FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
Ownable.hpp
1#ifndef __FIBER_OWNED_HPP
2#define __FIBER_OWNED_HPP
3
4#include "FieldAPI.h"
5#include <memcore/RefPtr.hpp>
6#include <memcore/Interface.hpp>
7#include <memcore/Verbose.hpp>
8#include <memcore/Ageable.hpp>
9
10#include <unordered_set>
11
12namespace Fiber
13{
14
20{
21public:
23 OwnerBase();
24
26 ~OwnerBase();
27
39 const MemCore::Intercube&Input) const = 0;
40
46 {
47 return processOwnership(OutputAndInput, OutputAndInput);
48 }
49
54 template <class ItemType>
56
57
66 virtual void x_updateOwnershipAge(const MemCore::Ageable&) = 0;
67};
68
70{
72 youngestChildAge = MemCore::Ageable::InfinitelyOld();
73};
74
75
79template <class Domain, class ContainerBase = ChildrenProperties>
80class Ownable : public virtual OwnerBase
81{
82public:
83
88 class Container : public MemCore::ReferenceBase<Container>
89 , public virtual OwnerBase
90 , public ContainerBase
91 {
92 public:
94 Container()
96 {}
97
98 class PassThrough : public MemCore::Interface<PassThrough>
99 {
100 public:
101 MemCore::WeakPtr<Container> myContainer;
102
104 : myContainer( theContainer )
105 {}
106 };
107
108 void recognizeOwnership(MemCore::Intercube&Output)
109 {
110 Output.addInterface(new PassThrough( this->self() ) );
111 }
112
113inline static MemCore::WeakPtr<Container> getOwnershipPassThroughItem(const MemCore::Intercube&Ic)
114 {
116 {
117 return PT->myContainer;
118 }
119 return nullptr;
120 }
121 };
122
128
129
134 {
135 for(auto oIt : Owners)
136 {
137 if (const MemCore::WeakPtr<Container> myContainer = oIt)
138 {
139 myContainer->x_updateOwnershipAge(theNewAge);
140 }
141 }
142 }
143
146 {
147 Owners.insert( theOwner.self() );
148 }
149
150
153 {
154 if (theOwner)
155 {
157 return true;
158 }
159 return false;
160 }
161
168
175
178 {}
179
184 {}
185
191 {
192 return *this;
193 }
194
203
211
214 {
215 for(auto oIt : Owners)
216 {
217 if (oIt)
218 return oIt;
219 }
220
221 return ::MemCore::NullPtr();
222 }
223
226 {
227 size_t NumberOfValidOwners = 0;
228 for(auto oIt : Owners)
229 {
230 if (oIt)
232 }
233
234 return NumberOfValidOwners;
235 }
236
241 {
242 Verbose(200) << " -- Checking " << this->Owners.size() << " owners for " << typeid(*this);
243
244 for(auto oIt : Owners)
245 {
246 if (const MemCore::WeakPtr<Container> myContainer = oIt)
247 {
248 Verbose(200) << " -- processing owner " << myContainer;
249
250 myContainer->recognizeOwnership(Output);
251 if (!myContainer->processOwnership(Output, Input ) )
252 return false;
253 }
254 }
255 return true;
256 }
257};
258
259
260
264template <class OwnedObjectType, class ContainerBase = ChildrenProperties>
266
267
268
269} /* namespace Fiber */
270
271#endif /* __FIBER_OWNED_HPP */
size_type size() const noexcept
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Base class for objects that may own domain-specific objects.
Definition Ownable.hpp:91
Domain-specific class of objects that can be owned.
Definition Ownable.hpp:81
Ownable & operator=(const Ownable &)
Assignment, does NOT copy any ownership information, the assigned Ownable will retain all its ownersh...
Definition Ownable.hpp:190
void insertOwner(const Container &theOwner)
Add some owner.
Definition Ownable.hpp:145
Ownable()
Default constructor, empty Ownership list.
Definition Ownable.hpp:177
void x_updateOwnershipAge(const MemCore::Ageable &theNewAge) override
Forward some age to all Owners.
Definition Ownable.hpp:133
void addOwner(const MemCore::WeakPtr< Container > &theOwner, const MemCore::Ageable &theNewAge)
Add some owner and broadcast a new age to all Ownerrs.
Definition Ownable.hpp:170
MemCore::WeakPtr< Container > getPrimaryOwner() const
Get the first valid owner.
Definition Ownable.hpp:213
Ownable(const Ownable &)
Copy constructor, does NOT copy any ownership information, the new Ownable will be unowned.
Definition Ownable.hpp:183
bool processOwnership(MemCore::Intercube &Output, const MemCore::Intercube &Input) const override
Process some ownership action.
Definition Ownable.hpp:240
std::unordered_set< MemCore::WeakPtr< Container > > Owners
The (internal) list of owners.
Definition Ownable.hpp:127
bool insertOwner(const MemCore::WeakPtr< Container > &theOwner)
Add some owner.
Definition Ownable.hpp:152
void addOwner(const Container &theOwner, const MemCore::Ageable &theNewAge)
Add some owner and broadcast a new age to all Ownerrs.
Definition Ownable.hpp:163
size_t getNumberOfValidOwners() const
Get the first valid owner.
Definition Ownable.hpp:225
Ownable(const Container &theOwner, const MemCore::Ageable &theNewAge)
Construct an Ownable with an initial owner.
Definition Ownable.hpp:207
Ownable(const MemCore::WeakPtr< Container > &theOwner, const MemCore::Ageable &theNewAge)
Construct an Ownable with an initial owner.
Definition Ownable.hpp:198
Base class for objects that are owned by others and owning others.
Definition Ownable.hpp:20
virtual void x_updateOwnershipAge(const MemCore::Ageable &)=0
Update all owners with the given age (Ageable::update() ).
virtual bool processOwnership(MemCore::Intercube &Output, const MemCore::Intercube &Input) const =0
Hierarchically broadcast some activity to all Owners.
bool processOwnership(MemCore::Intercube &OutputAndInput) const
Process ownership where the input information is shared with the output information in the same Inter...
Definition Ownable.hpp:45
static constexpr const Ageable & InfinitelyOld() noexcept
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
typename Ownable< OwnedObjectType, ContainerBase >::Container OwnerOf
Shortcut to find the owning type.
Definition Ownable.hpp:265
Definition Ownable.hpp:70