diff --git a/external/algorithms/core/include/algorithms/algorithm.h b/external/algorithms/core/include/algorithms/algorithm.h index 864c7e9de5287138339370a50f6992d11396550f..9ab724a4f6b18de2c173b52bf64c1f4c19311a48 100644 --- a/external/algorithms/core/include/algorithms/algorithm.h +++ b/external/algorithms/core/include/algorithms/algorithm.h @@ -92,10 +92,11 @@ public: void initialize() { init(); } void execute(const Input& i, const Output& o) const { process(i, o); } void executeInContext(const Input& i, const Output& o, const Context& c) const { - Algorithm clone = *this; - clone.context(c, &clone); - clone.execute(i, o); + auto copy = clone(); + copy->context(c, copy.get()); + copy->execute(i, o); } + auto clone() const { return std::make_unique<Algorithm>(*this); } const InputNames& inputNames() const { return m_input_names; } const OutputNames& outputNames() const { return m_output_names; } diff --git a/external/algorithms/core/include/algorithms/resource.h b/external/algorithms/core/include/algorithms/resource.h index c0fb8064d8f68ce969c140bef509dc49a7111652..303e7a3bbade82b4ce4c1667227296a1d05638f8 100644 --- a/external/algorithms/core/include/algorithms/resource.h +++ b/external/algorithms/core/include/algorithms/resource.h @@ -48,21 +48,16 @@ public: ResourceMixin() = default; - // Copy constructor for the ResourceMixin needs to update the addresses of the contained - // resources to refer to the new copies. - ResourceMixin(const ResourceMixin& rhs) : m_resources(rhs.m_resources.size(), nullptr) { - for (size_t i = 0; i < m_resources.size(); ++i) { - m_resources[i] = rhs.m_resources[i]->relocate(this); - // std::cout << m_resources[i] << " " << rhs.m_resources[i] << std::endl; - // m_resources[i]->context(&m_context); - } - } + // Copy constructor for the ResourceMixin assumes new auto-registration (as + // pointers need to be relocated to the new instance) + ResourceMixin(const ResourceMixin&) : m_resources() {} + ResourceMixin& operator=(const ResourceMixin& rhs) = delete; - void context(const Context& c, const NameMixin* s = nullptr) { - m_context = c; - if (s) { - m_context.scope(s); + void context(const Context& ctx, const NameMixin* scope = nullptr) { + m_context = ctx; + if (scope) { + m_context.scope(scope); } } const Context& context() const { return m_context; } @@ -79,27 +74,15 @@ public: // management. Implementation is similar to Property class ResourceHandle { public: - ResourceHandle(const ResourceMixin* owner) - : m_offset{reinterpret_cast<const char*>(this) - reinterpret_cast<const char*>(owner)} { - std::cout << "resources handle offset: " << m_offset << std::endl; - } + ResourceHandle() = default; virtual void context(const Context*) = 0; virtual const Context* context() const = 0; - // return the relocated address for the copied object in the new instance - ResourceHandle* relocate(ResourceMixin* clone) const { - return reinterpret_cast<ResourceHandle*>(reinterpret_cast<char*>(clone) + m_offset); - } - - private: - // offset versus the ResourceMixin `this` pointer to allow relocating views - const ptrdiff_t m_offset; }; template <class ResourceType> class Resource : public ResourceHandle { public: template <class... Args> - Resource(ResourceMixin* owner, Args&&... args) - : ResourceHandle{owner}, m_impl{std::forward<Args>(args)...} { - std::cout << "Hi, I'm the original and I'm here: " << this << std::endl; + Resource(ResourceMixin* owner, Args&&... args) : m_impl{std::forward<Args>(args)...} { + std::cout << "DEBUGDEBUG Hi, I'm a resource and I'm here: " << this << std::endl; if (owner) { owner->registerResource(this); m_impl.context(&(owner->context())); @@ -108,10 +91,7 @@ public: fmt::format("Attempting to create Resource '{}' without valid owner", m_impl.name())); } } - Resource(const Resource& rhs) : m_impl{rhs.m_impl} { - std::cout << "Hi I'm the copy and I'm here: " << this << " compared to previous: " << &rhs - << " offset: " << (&rhs - this) << std::endl; - } + Resource(const Resource& rhs) = delete; void context(const Context* c) final { m_impl.context(c); } const Context* context() const final { return m_impl.context(); } @@ -124,7 +104,7 @@ public: private: ResourceType m_impl; }; -}; +}; // namespace algorithms } // namespace algorithms