Itasca C++ Interface
Loading...
Searching...
No Matches
ithing.h
Go to the documentation of this file.
1#pragma once
5
6#include "igroup.h"
7#include "base/src/farray.h"
8#include "base/src/spinlock.h"
9
10namespace fish {
11 class IParameter;
12}
13
14namespace itasca {
15#ifndef DOXYGEN
16 class Archive2;
17 class IContainer;
18 class IGroup;
19#endif
20
21//#define ITHINGMUTEX
22
30 class IThing {
31 public:
32#ifdef ITHINGMUTEX
33 using LockType = std::mutex;
34#else
35 using LockType = SpinLock;
36#endif
37
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 ConditionalLock<LockType> {
44 public:
45 inline LockIf(const IThing *t, bool b) : ConditionalLock<LockType>(t ? &t->thingLock_ : nullptr,b) { }
46 };
47
48 class BreakLock : public ReverseLock<LockType> {
49 public:
50 inline BreakLock(const IThing *t) : ReverseLock<LockType>(t->thingLock_) {}
51 };
52
53 struct Handle { // Used in the Handle system, so we have some opacity and flexibility in the future
54 Handle() {}
55 explicit Handle(uint64 h) : val_(h) { }
56 bool operator<(const Handle &h) const { return val_<h.val_; }
57 bool operator==(const Handle &h) const { return val_==h.val_; }
58 bool valid() const { return val_ ? true : false; }
59 uint64 val_ = 0;
60 };
61
63 inline static const TType type_ = 0x4c815a59;
65 inline static const uint maxGroupSlot_ = 128;
67 inline static const uint maxExtraIndex_ = 128;
68
69 inline IThing() { }
70 virtual ~IThing() { }
71 //inline ~IThing() { sendDeleteNotice(); }
72
74 virtual const IThing *getIThing() const=0;
75 virtual IThing * getIThing()=0;
76
81 virtual TType getType() const=0;
82
84 virtual IString getTypeName() const=0;
85
92 virtual TType getGeneralType() const=0;
93
99 virtual const void *convertToType(const TType &id) const=0;
100 virtual void * convertToTypeNC(const TType &id)=0;
101
104 template <class T> const T *convert() const { return (const T *)convertToType(T::type_); }
105 template <class T> T * convert() { return (T *)convertToType(T::type_); }
106
108 virtual uint64 getID() const=0;
109
114 virtual uint64 getCollectionID() const=0;
115
118 virtual bool getIsSet() const=0;
119
122 virtual const IThing * getSet() const=0;
123
125 virtual void getAssociatedThings(const TType &type,FArray<const IThing*> *ret) const=0;
126
129
131 virtual IString getName() const=0;
132
135 virtual DVect3 getLocation() const=0;
136
139 virtual DExtent3 getExtent() const=0;
140
144 virtual DVect3 getClosest(const DVect3 &pos) const=0;
145
147 virtual DVect3 getNormal() const=0;
148
150 virtual DVect3 getDisplacementThing() const=0;
151
153 virtual DVect3 getVelocityThing() const=0;
154
156 virtual double getVolume() const=0;
157
161 virtual bool isWithinOrientation(const Orientation3 &orientation,const DVect2 &tol) const=0;
162
164 virtual bool isOnSurface(bool mech=true,bool therm=false,bool fluid=false,bool _or=false) const=0;
165
168 virtual const IContainer *getContainer() const=0;
172 virtual uint64 getContainerOrder() const=0;
173
176 //virtual bool addGroup(IGroupID *id)=0;
177 virtual bool addGroup(const IGroupID &id) = 0;
181 virtual bool removeGroup(const IGroupID &id)=0;
188 virtual uint isInGroup(const FArray<IGroupID> &ids,TType type=0,bool only=false) const=0;
191 virtual const IGroup *getGroup(const ISlotID &slot) const=0;
195 virtual IString getGroupName(const ISlotID &slot=ISlotID()) const=0;
197 virtual void getGroupInfo(std::vector<std::pair<int,IString>> *) const = 0;
199 virtual uint getGroupList(FArray<IGroupID> *list) const=0;
201 virtual void copyGroups(const IThing *t)=0;
202 virtual void clearGroup()=0;
203
205 virtual uint getExtraSize() const=0;
208 virtual const fish::IParameter *getExtra(uint index) const=0;
209 virtual void setExtra(uint index,const fish::IParameter &p)=0;
210 virtual void clearExtra()=0;
211
213 virtual bool getHidden() const=0;
215 virtual bool setHidden(bool b)=0;
216
218 virtual bool getSelected() const=0;
220 virtual bool setSelected(bool b)=0;
221
223 virtual void save(Archive2 &) const=0;
224 virtual bool restore(Archive2 &,uint64)=0;
225 virtual void remap(Archive2 &)=0;
226 virtual Handle getRemapHandle(bool allowCreate,uint32 thread) const=0;
227 //virtual void clearRemapHandle()=0;
228
231 virtual void destroy()=0;
232
233 private:
234 mutable LockType thingLock_; // Generic spin lock for access to this IThing
235 };
236
238 template <class Dest> inline const Dest *convert_cast(const IThing *src) { return src ? src->convert<Dest>() : 0; }
240 template <class Dest> inline Dest * convert_cast(IThing *src) { return src ? src->convert<Dest>() : 0; }
241
243 template <class Dest, class Src> inline const Dest* convert_getcast(const Src* src) { return src ? src->getIThing()->template convert<Dest>() : 0; }
245 template <class Dest, class Src> inline Dest* convert_getcast(Src* src) { return src ? src->getIThing()->template convert<Dest>() : 0; }
246
247 inline int64 pointCompare(const IThing *p1,const IThing *p2) {
248 int64 i1 = p1 ? p1->getType() : 0;
249 int64 i2 = p2 ? p2->getType() : 0;
250 if (i1 == i2) {
251 i1 = p1 ? p1->getID() : 0;
252 i2 = p2 ? p2->getID() : 0;
253 }
254 return i1 - i2;
255 }
256} // namespace itasca
257namespace std {
258 template <>
259 struct hash<itasca::IThing::Handle> {
260 std::size_t operator()(const itasca::IThing::Handle &h) const { return hash<uint64>()(h.val_); }
261 };
262} // namespace std
263namespace utility {
264 using itasca::IThing;
267}
268
269// EoF
An array class that attempts to minimize unnecessary heap access.
Definition farray.h:25
Definition istring.h:14
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition orientation.h:99
Definition spinlock.h:27
Definition iparameter.h:13
Interface for containers of IThings.
Definition icontainer.h:21
Interface to a group object.
Definition igroup.h:9
Definition igroup.h:82
Definition igroup.h:41
Base class for items that will be stored in containers.
Definition ithing.h:30
virtual DVect3 getLocation() const =0
virtual bool getIsSet() const =0
virtual DVect3 getClosest(const DVect3 &pos) const =0
virtual DVect3 getVelocityThing() const =0
Returns the instantaneous velocity for things supporting velocity.
virtual bool setSelected(bool b)=0
Sets the selected flag at index.
virtual DVect3 getDisplacementThing() const =0
Returns the accumulated displacement for things supporting displacement.
virtual void getAssociatedThings(const TType &type, FArray< const IThing * > *ret) const =0
Returns a list of things associated with this thing with TType type.
virtual bool addGroup(const IGroupID &id)=0
static const TType type_
The base type of an IThing.
Definition ithing.h:63
virtual DVect3 getNormal() const =0
Returns a normal vector representing the orientation of the object, if this is appropriate....
virtual IString getTypeName() const =0
Returns a description of the type of the class.
static const uint maxGroupSlot_
Maximum number of group slots per object.
Definition ithing.h:65
virtual void destroy()=0
virtual void resetAssociatedThings(FArray< const IThing * > *ret)=0
Resets any data used with the associated things.
virtual bool getHidden() const =0
Returns the Hide flag at index.
virtual void getGroupInfo(std::vector< std::pair< int, IString > > *) const =0
Returns the group name/slot for all groups.
virtual uint isInGroup(const FArray< IGroupID > &ids, TType type=0, bool only=false) const =0
virtual IString getName() const =0
Returns a name string - the exact meaning of which is defined by the container and the implementing c...
virtual IThing * getIThing()=0
Return the IThing interface.
virtual const fish::IParameter * getExtra(uint index) const =0
virtual DExtent3 getExtent() const =0
virtual TType getGeneralType() const =0
virtual const IThing * getIThing() const =0
Return the IThing interface.
virtual uint getGroupList(FArray< IGroupID > *list) const =0
Return all groups and all slots assigned to the object in a list.
virtual bool isWithinOrientation(const Orientation3 &orientation, const DVect2 &tol) const =0
virtual uint64 getID() const =0
Returns a value - the exact meaning of which is defined by the container and the implementing class.
T * convert()
Definition ithing.h:105
static const uint maxExtraIndex_
Maximum number of extra FISH variables per object.
Definition ithing.h:67
const T * convert() const
Definition ithing.h:104
virtual IContainer * getContainer()=0
virtual const IGroup * getGroup(const ISlotID &slot) const =0
virtual void * convertToTypeNC(const TType &id)=0
virtual bool getSelected() const =0
Returns the selected flag at index.
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.
virtual const IContainer * getContainer() const =0
virtual bool removeGroup(const IGroupID &id)=0
virtual TType getType() const =0
virtual const IThing * getSet() const =0
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.
virtual void setExtra(uint index, const fish::IParameter &p)=0
virtual const void * convertToType(const TType &id) const =0
virtual void save(Archive2 &) const =0
Archives the Thing to a file (if appropriate).
virtual uint64 getCollectionID() const =0
virtual bool setHidden(bool b)=0
Sets the hidden flag at index.
virtual void copyGroups(const IThing *t)=0
Copies group data from one IThing to this, all original group data is lost.
virtual IString getGroupName(const ISlotID &slot=ISlotID()) const =0
An array class that attempts to minimize unnecessary heap access.
uint32 TType
class type indicator
Definition basedef.h:46
namespace Itasca
Definition basememory.cpp:10
const Dest * convert_cast(const IThing *src)
A cast operator (use similar to dynamic_cast) for types derived from IThing (const).
Definition ithing.h:238
const Dest * convert_getcast(const Src *src)
A cast operator for Interface types that define getThing() (const).
Definition ithing.h:243
Definition ithing.h:53