Itasca C++ Interface
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
ithing.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "ideletenotice.h"
7 #include "igroup.h"
8 #include "base/src/farray.h"
9 #include "base/src/spinlock.h"
10 
11 namespace fish {
12  class IParameter;
13 }
14 
15 namespace itasca {
16 #ifndef DOXYGEN
17  class Archive2;
18  class IContainer;
19  class IGroup;
20 #endif
21 
22 //#define ITHINGMUTEX
23 
31  class IThing {
32 #ifdef ITHINGMUTEX
33  using LockType = std::mutex;
34 #else
35  using LockType = spinlock;
36 #endif
37  public:
38  class Lock : public std::lock_guard<LockType> {
39  public:
40  inline Lock(const IThing *t) : std::lock_guard<LockType>(t->thingLock_) { }
41  };
42 
43  class LockIf : public conditional_lock<LockType> {
44  public:
45  inline LockIf(const IThing *t, bool b) : conditional_lock<LockType>(t ? &t->thingLock_ : nullptr,b) { }
46  };
47 
48  class BreakLock : public reverse_lock<LockType> {
49  public:
50  inline BreakLock(const IThing *t) : reverse_lock<LockType>(t->thingLock_) {}
51  };
52 
54  inline static const TType type_ = 0x4c815a59;
56  inline static const uint maxGroupSlot_ = 128;
58  inline static const uint maxExtraIndex_ = 128;
59 
60  inline IThing() { }
61  //inline ~IThing() { sendDeleteNotice(); }
62 
64  virtual const IThing *getIThing() const=0;
65  virtual IThing * getIThing()=0;
66 
71  virtual TType getType() const=0;
72 
74  virtual QString getTypeName() const=0;
75 
82  virtual TType getGeneralType() const=0;
83 
89  virtual const void *convertToType(const TType &id) const=0;
90  virtual void * convertToType(const TType &id)=0;
91 
94  template <class T> const T *convert() const { return (const T *)convertToType(T::type_); }
95  template <class T> T * convert() { return (T *)convertToType(T::type_); }
96 
98  virtual quint64 getID() const=0;
99 
104  virtual quint64 getCollectionID() const=0;
105 
108  virtual bool getIsSet() const=0;
109 
112  virtual const IThing * getSet() const=0;
113 
115  virtual void getAssociatedThings(const TType &type,FArray<const IThing*> *ret) const=0;
116 
118  virtual void resetAssociatedThings(FArray<const IThing*> *ret) = 0;
119 
121  virtual QString getName() const=0;
122 
125  virtual DVect3 getLocation() const=0;
126 
129  virtual DExtent3 getExtent() const=0;
130 
134  virtual DVect3 getClosest(const DVect3 &pos) const=0;
135 
137  virtual DVect3 getNormal() const=0;
138 
140  virtual DVect3 getDisplacementThing() const=0;
141 
143  virtual DVect3 getVelocityThing() const=0;
144 
146  virtual double getVolume() const=0;
147 
151  virtual bool isWithinOrientation(const Orientation3 &orientation,const DVect2 &tol) const=0;
152 
154  virtual bool isOnSurface(bool mech=true,bool therm=false,bool fluid=false,bool _or=false) const=0;
155 
158  virtual const IContainer *getContainer() const=0;
161  virtual IContainer * getContainer()=0;
162 
165  //virtual bool addGroup(IGroupID *id)=0;
166  virtual bool addGroup(const IGroupID &id) = 0;
170  virtual bool removeGroup(const IGroupID &id)=0;
177  virtual uint isInGroup(const FArray<IGroupID> &ids,TType type=0,bool only=false) const=0;
180  virtual const IGroup *getGroup(const ISlotID &slot) const=0;
184  virtual QString getGroupName(const ISlotID &slot=ISlotID()) const=0;
186  virtual uint getGroupList(FArray<IGroupID> *list) const=0;
188  virtual void copyGroups(const IThing *t)=0;
189  virtual void clearGroup()=0;
190 
192  virtual uint getExtraSize() const=0;
195  virtual const fish::IParameter *getExtra(uint index) const=0;
196  virtual void setExtra(uint index,const fish::IParameter &p)=0;
197  virtual void clearExtra()=0;
198 
200  virtual bool getHidden() const=0;
202  virtual bool setHidden(bool b)=0;
203 
205  virtual bool getSelected() const=0;
207  virtual bool setSelected(bool b)=0;
208 
209  // MPI Support functions
211  virtual bool getGhost() const=0;
212  virtual void setGhost(bool b)=0;
215  virtual quint64 getContainerOrder() const = 0;
216  virtual void setContainerOrder(quint64 i) = 0;
217 
219  virtual void save(Archive2 &) const=0;
220  virtual bool restore(Archive2 &,quint64)=0;
221  virtual void remap(Archive2 &)=0;
222  virtual quint64 getRemapHandle(Archive2 &) const=0;
223  //virtual void clearRemapHandle()=0;
224 
227  virtual void destroy()=0;
228 
230  inline void addDeleteNotice(IDeleteNotice *delnot) const;
231  inline void removeDeleteNotice(IDeleteNotice *delnot) const;
232  inline void sendDeleteNotice();
233  inline void changeToNewPointer(IThing *newPnt);
234  private:
235  mutable IDeleteNotice *head_ = nullptr;
236  mutable LockType thingLock_; // Generic spin lock for access to this IThing
237  mutable LockType deleteNoticeLock_; // Specific to delete notice - using the same one was causing race conditions in intrinsics
238  };
239 
240  inline void IThing::addDeleteNotice(IDeleteNotice *delnot) const {
241  std::lock_guard<LockType> l(deleteNoticeLock_);
242  delnot->insert(&head_);
243  }
244 
245  inline void IThing::removeDeleteNotice(IDeleteNotice *delnot) const {
246  std::lock_guard<LockType> l(deleteNoticeLock_);
247  delnot->remove(&head_);
248  }
249 
250  inline void IThing::sendDeleteNotice() {
251  std::lock_guard<LockType> l(deleteNoticeLock_);
252  while (head_) {
253  auto dn = head_;
254  dn->remove(&head_);
255  reverse_lock<LockType> r(deleteNoticeLock_);
256  dn->onDelete(this);
257  }
258  }
259 
260  inline void IThing::changeToNewPointer(IThing *newPnt) {
261  std::vector<IDeleteNotice *> all;
262  {
263  std::lock_guard<LockType> l(deleteNoticeLock_);
264  for (auto *dn = head_; dn; dn = dn->nextDeleteNotice())
265  all.push_back(dn);
266  }
267  for (auto *dn : all)
268  dn->changeToNewPointer(this,newPnt);
269  }
270 
272  template <class Dest> inline const Dest *convert_cast(const IThing *src) { return src ? src->convert<Dest>() : 0; }
274  template <class Dest> inline Dest * convert_cast(IThing *src) { return src ? src->convert<Dest>() : 0; }
275 
277  template <class Dest, class Src> inline const Dest* convert_getcast(const Src* src) { return src ? src->getIThing()->template convert<Dest>() : 0; }
279  template <class Dest, class Src> inline Dest* convert_getcast(Src* src) { return src ? src->getIThing()->template convert<Dest>() : 0; }
280 } // namespace itasca
281 
282 // EoF
virtual const IContainer * getContainer() const =0
virtual const void * convertToType(const TType &id) const =0
virtual bool setHidden(bool b)=0
Sets the hidden flag at index.
virtual bool removeGroup(const IGroupID &id)=0
Interface to a group object.
Definition: igroup.h:9
Definition: iparameter.h:16
virtual DExtent3 getExtent() const =0
virtual bool addGroup(const IGroupID &id)=0
virtual const fish::IParameter * getExtra(uint index) const =0
const Dest * convert_getcast(const Src *src)
A cast operator for Interface types that define getThing() (const).
Definition: ithing.h:277
virtual bool getGhost() const =0
Indicates if the thing is a "ghost", that is actually ownned by a different node.
virtual uint isInGroup(const FArray< IGroupID > &ids, TType type=0, bool only=false) const =0
namespace Itasca
Definition: basememory.cpp:9
virtual void setExtra(uint index, const fish::IParameter &p)=0
Base class for items that will be stored in containers.
Definition: ithing.h:31
static const uint maxGroupSlot_
Maximum number of group slots per object.
Definition: ithing.h:56
virtual bool getIsSet() const =0
virtual bool isWithinOrientation(const Orientation3 &orientation, const DVect2 &tol) const =0
Definition: ithing.h:43
virtual QString getName() const =0
Returns a name string - the exact meaning of which is defined by the container and the implementing c...
virtual bool getHidden() const =0
Returns the Hide flag at index.
virtual TType getGeneralType() const =0
An array class that attempts to minimize unnecessary heap access.
virtual const IThing * getSet() const =0
virtual bool getSelected() const =0
Returns the selected flag at index.
Definition: spinlock.h:67
const Dest * convert_cast(const IThing *src)
A cast operator (use similar to dynamic_cast) for types derived from IThing (const).
Definition: ithing.h:272
virtual quint64 getContainerOrder() const =0
virtual DVect3 getDisplacementThing() const =0
Returns the accumulated displacement for things supporting displacement.
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition: orientation.h:94
Definition: igroup.h:91
virtual void save(Archive2 &) const =0
Archives the Thing to a file (if appropriate).
virtual bool isOnSurface(bool mech=true, bool therm=false, bool fluid=false, bool _or=false) const =0
Returns TRUE if this is a "Surface", based on the three process criteria.
static const TType type_
The base type of an IThing.
Definition: ithing.h:54
virtual TType getType() const =0
unsigned int TType
class type indicator
Definition: basedef.h:41
Definition: spinlock.h:29
virtual const IThing * getIThing() const =0
Return the IThing interface.
virtual void resetAssociatedThings(FArray< const IThing * > *ret)=0
Resets any data used with the associated things.
virtual DVect3 getVelocityThing() const =0
Returns the instantaneous velocity for things supporting velocity.
virtual const IGroup * getGroup(const ISlotID &slot) const =0
Definition: ideletenotice.h:9
T * convert()
Definition: ithing.h:95
virtual uint getGroupList(FArray< IGroupID > *list) const =0
Return all groups and all slots assigned to the object in a list.
Definition: spinlock.h:57
virtual quint64 getCollectionID() const =0
virtual uint getExtraSize() const =0
Returns the number of extra FISH extra variables for this object.
virtual double getVolume() const =0
Returns the volume if this is appropraite. 0 is returned otherwise.
An array class that attempts to minimize unnecessary heap access.
Definition: farray.h:27
Interface for containers of IThings.
Definition: icontainer.h:23
virtual QString getTypeName() const =0
Returns a description of the type of the class.
Definition: ithing.h:38
Definition: igroup.h:51
virtual bool setSelected(bool b)=0
Sets the selected flag at index.
virtual void destroy()=0
Definition: ithing.h:48
virtual DVect3 getNormal() const =0
Returns a normal vector representing the orientation of the object, if this is appropriate....
virtual quint64 getID() const =0
Returns a value - the exact meaning of which is defined by the container and the implementing class.
virtual DVect3 getClosest(const DVect3 &pos) const =0
virtual DVect3 getLocation() const =0
virtual QString getGroupName(const ISlotID &slot=ISlotID()) const =0
virtual void getAssociatedThings(const TType &type, FArray< const IThing * > *ret) const =0
Returns a list of things associated with this thing with TType type.
static const uint maxExtraIndex_
Maximum number of extra FISH variables per object.
Definition: ithing.h:58
virtual void copyGroups(const IThing *t)=0
Copies group data from one IThing to this, all original group data is lost.
const T * convert() const
Definition: ithing.h:94