Itasca C++ Interface
Loading...
Searching...
No Matches
icontainer.h
Go to the documentation of this file.
1#pragma once
4
5#include "base/src/basei.h"
6#include "shared/interface/signal.h"
7#include "ithing.h"
8
9namespace itasca {
21 class IContainer {
22 public:
24 inline static const TType type_ = 0x51cdf4ed;
25
27 using signal_type = shared::Signal<const IThing *,const IContainer *>;
28 signal_type thingAdded;
29 signal_type thingRemoved;
30 signal_type aboutToDestroy;
31
33 class IOpaqueIterator { };
34
36 virtual IThing * getIThing()=0;
38 virtual const IThing *getIThing() const=0;
42 virtual const IContainer *getIContainer() const=0;
44 virtual bool getValueBased() const=0;
46 virtual bool isPartitioned() const=0;
48 virtual uint64 getSize() const=0;
50 virtual uint64 getNumberHidden() const=0;
52 virtual uint64 getNumberSelected() const=0;
55 virtual uint64 getNextID() const=0;
57 virtual void setNextID(uint64)=0;
62 virtual IThing * remove(IThing *t)=0;
67 virtual void erase(IThing *t)=0;
72 virtual IThing * add(IThing *t,uint64 id=0)=0;
75 virtual void clear()=0;
79 virtual IThing * findWithID(uint64 id)=0;
83 virtual const IThing *findWithID(uint64 id) const=0;
85 virtual uint64 getInstance(uint64 id) const=0;
90 virtual IThing * findWithName(const IString &s)=0;
95 virtual const IThing *findWithName(const IString &s) const=0;
101 virtual const signal_type *getAddedSignal() const=0;
106 virtual const signal_type *getRemovedSignal() const=0;
111 virtual const signal_type *getDestroySignal() const=0;
112
114 virtual IOpaqueIterator *acquire() const=0;
117 virtual void release(IOpaqueIterator *i) const=0;
120 virtual bool atEnd(IOpaqueIterator *i) const=0;
123 virtual IThing * get(IOpaqueIterator *i)=0;
126 virtual const IThing * get(IOpaqueIterator *i) const=0;
130 virtual bool increment(IOpaqueIterator *i) const=0;
134 virtual bool copy(IOpaqueIterator *iSrc,IOpaqueIterator *iDst) const=0;
137 virtual IThing * doSilentRemove(IThing *t)=0;
138 };
139
148 template <class T> class ICIterator {
149 public:
152 ICIterator(const IContainer *c) : c_(c), i_(nullptr) { if (c_) i_ = c_->acquire(); }
154 ~ICIterator() { if (c_&&i_) c_->release(i_); }
156 void setContainer(const IContainer *c) { if (c_&&i_) c_->release(i_); i_ = 0; c_ = c; if (c_) i_ = c_->acquire(); }
158 const IContainer *getContainer() const { return c_; }
160 bool atEnd() const { if (!c_ || !i_) return true; return c_->atEnd(i_); }
162 const ICIterator<T> &operator++() { if (c_&&i_) c_->increment(i_); return *this; }
163
166 //const ICIterator<T> &operator+=(int i) { assert(i>=0); if (c_&&i_) c_->incrementBy(i_, i); return *this; }
170 //uint64 operator-(const ICIterator& earlier) { if (c_&&i_) return c_->subtract(this, &earlier); return 0; }
171
173 const T *get() const { if (!c_ || !i_) return 0; return convert_cast<T>(c_->get(i_)); }
175 const T *operator->() const { return get(); }
177 const T &operator*() const { return *get(); }
179 operator const T *() const { return get(); }
181 void copy(const ICIterator<T> &c) { if (c_&&i_) c_->release(i_); i_ = 0; c_ = c.c_; if (c_) i_ = c_->acquire(); if (c_&&c.i_) c_->copy(c.i_,i_); }
182 private:
183 ICIterator(const ICIterator &); // DISALLOWED
184 void operator=(const ICIterator &); // DISALLOWED
185 const IContainer * c_;
187 };
188
197 template <class T> class IIterator : public ICIterator<T> {
198 public:
207 T *get() const { return const_cast<T *>(ICIterator<T>::get()); }
209 T *operator->() const { return get(); }
211 T &operator*() const { return *get(); }
213 operator T *() const { return get(); }
214 private:
215 IIterator(const IIterator &); // DISALLOWED
216 void operator=(const IIterator &); // DISALLOWED
217 };
218
219}
220namespace utility {
221 using itasca::IContainer;
222 using itasca::ICIterator;
223 using itasca::IIterator;
224}
225// EoF
Definition istring.h:14
Const iterator for an IContainer.
Definition icontainer.h:148
const T * get() const
Return a const pointer to T.
Definition icontainer.h:173
bool atEnd() const
Returns true if at the end of the IContainer.
Definition icontainer.h:160
void copy(const ICIterator< T > &c)
Copy another iterator.
Definition icontainer.h:181
const T * operator->() const
Return a const pointer to T.
Definition icontainer.h:175
const ICIterator< T > & operator++()
Increment the const iterator to the next entry in the IContainer.
Definition icontainer.h:162
~ICIterator()
Destructor for the const iterator.
Definition icontainer.h:154
void setContainer(const IContainer *c)
Associate this with a different container.
Definition icontainer.h:156
const IContainer * getContainer() const
Get the IContainer pointer that this iterator is associated with.
Definition icontainer.h:158
const T & operator*() const
Return a const reference to T.
Definition icontainer.h:177
ICIterator(const IContainer *c)
Definition icontainer.h:152
Interface class for iterating through the container that has a null implementation.
Definition icontainer.h:33
Interface for containers of IThings.
Definition icontainer.h:21
virtual IThing * remove(IThing *t)=0
virtual uint64 getSize() const =0
Returns the IThing count or number of IThings held in the container.
virtual bool copy(IOpaqueIterator *iSrc, IOpaqueIterator *iDst) const =0
virtual const signal_type * getAddedSignal() const =0
virtual const IContainer * getIContainer() const =0
Returns the const IThing pointer of the container.
virtual IOpaqueIterator * acquire() const =0
Acquire a new IOpaqueIterator for use iterating through the container.
virtual bool atEnd(IOpaqueIterator *i) const =0
virtual bool isPartitioned() const =0
Returns TRUE if the container is partitioned in cluster mode (zones, balls, etc).
virtual void release(IOpaqueIterator *i) const =0
virtual const IThing * getIThing() const =0
Returns the const IThing pointer of the container.
virtual const IThing * findWithID(uint64 id) const =0
virtual IThing * doSilentRemove(IThing *t)=0
virtual IThing * get(IOpaqueIterator *i)=0
virtual const IThing * get(IOpaqueIterator *i) const =0
virtual void clear()=0
virtual void setNextID(uint64)=0
Set the maximum ID. This should only be used on a restore if manipulating the container under the hoo...
virtual IThing * findWithID(uint64 id)=0
virtual IThing * getIThing()=0
Returns the IThing pointer of the container.
shared::Signal< const IThing *, const IContainer * > signal_type
Defines the Signal2<> type used for removed, added, and destroy signals sent from the container.
Definition icontainer.h:27
virtual const IThing * findWithName(const IString &s) const =0
virtual const signal_type * getDestroySignal() const =0
virtual bool getValueBased() const =0
Returns TRUE if the container is value based, or pointer based.
static const TType type_
The type identification number for this class, for use in convert_cast() and convert_getcast().
Definition icontainer.h:24
virtual uint64 getInstance(uint64 id) const =0
Return instance count associated with id, this is always 0 if not a value based container.
virtual void erase(IThing *t)=0
virtual bool increment(IOpaqueIterator *i) const =0
virtual IThing * add(IThing *t, uint64 id=0)=0
virtual const signal_type * getRemovedSignal() const =0
virtual uint64 getNumberHidden() const =0
Returns the number of IThings that have getHidden()==true.
virtual IContainer * getIContainer()=0
Returns the IThing pointer of the container.
virtual uint64 getNextID() const =0
virtual IThing * findWithName(const IString &s)=0
virtual uint64 getNumberSelected() const =0
Returns the number of IThings that have getSelected()==true.
Iterator for an IContainer.
Definition icontainer.h:197
IIterator(IContainer *c)
Definition icontainer.h:201
T & operator*() const
Return a referenc to T.
Definition icontainer.h:211
const IIterator< T > & operator++()
Increment the iterator to the next entry in the IContainer.
Definition icontainer.h:203
T * get() const
Return a pointer to T.
Definition icontainer.h:207
void setContainer(IContainer *c)
Associate this with a different container.
Definition icontainer.h:205
T * operator->() const
Return a pointer to T.
Definition icontainer.h:209
Base class for items that will be stored in containers.
Definition ithing.h:30
uint32 TType
class type indicator
Definition basedef.h:46
Base class for items that will be stored in containers.
namespace Itasca
Definition basememory.cpp:14
namespace itasca
Definition igenerictet.h:11