Skip to content
Snippets Groups Projects
Commit 97f83fb1 authored by Sylvester Joosten's avatar Sylvester Joosten
Browse files

WIP

parent 2e42d833
No related tags found
1 merge request!502Feat context service overhaul
......@@ -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; }
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment