Itasca C++ Interface
Loading...
Searching...
No Matches
igroup.h
1#pragma once
2
3#include "base/src/istring.h"
4
5namespace itasca {
6 class IThing;
7
9 class IGroup {
10 public:
12 static constexpr TType type_ = 0x4ecd4d65;
13 inline static IString nullName() { return "None"; }
14 static constexpr uint32 null_ = 0xFFFFFFFF;
16 virtual IThing * getIThing()=0;
17 virtual const IThing *getIThing() const=0;
19 virtual IString getName() const=0;
20 };
21
23 class ISlot {
24 public:
26 static constexpr TType type_ = 0x4ecd4d66;
27 static constexpr uint32 any_ = 0xFFFFFFFF;
28 static constexpr uint32 invalid_ = 0xFFFFFFFE;
29 static constexpr uint32 unresolved_ = 0xFFFFFFFD;
30 inline static IString anyName() { return "Any"; }
31 inline static IString defaultName() { return "Default"; }
32 inline static IString invalidName() { return "Invalid"; }
34 virtual IThing * getIThing()=0;
35 virtual const IThing *getIThing() const=0;
37 virtual IString getName() const=0;
38 virtual uint32 getIndex() const = 0;
39 };
40
41 class ISlotID {
42 public:
43 static constexpr uint32 any_ = ISlot::any_;
44 static constexpr uint32 unresolved_ = ISlot::unresolved_;
45 static constexpr uint32 invalid_ = ISlot::invalid_;
46 inline static IString anyName() { return ISlot::anyName(); }
47 inline static IString defaultName() { return ISlot::defaultName(); }
48 inline static IString invalidName() { return ISlot::invalidName(); }
49
50 inline ISlotID(const ISlot *slot) : slot_(slot), slotIndex_(slot ? ISlot::unresolved_ : ISlot::invalid_) { }
51 inline ISlotID(uint32 slot=any_) : slotIndex_(slot) { } // Any slot for read, default slot for write.
52 inline ISlotID(const IString &name) : slotIndex_(name.length() ? ISlot::unresolved_ : ISlot::any_), slotName_(name) { }
53 inline ISlotID(const ISlotID &id) : slot_(id.slot_), slotIndex_(id.slotIndex_), slotName_(id.slotName_), thread_(id.thread_) {}
54 inline ISlotID(ISlotID &&id) noexcept : slot_(id.slot_), slotIndex_(id.slotIndex_), slotName_(std::move(id.slotName_)), thread_(id.thread_) {}
55
56 inline const ISlotID &operator=(const ISlotID &id) { slot_ = id.slot_; slotIndex_ = id.slotIndex_; slotName_ = id.slotName_; thread_ = id.thread_; return *this; }
57 inline const ISlotID &operator=(ISlotID &&id) noexcept { slot_ = id.slot_; slotIndex_ = id.slotIndex_; slotName_ = std::move(id.slotName_); thread_ = id.thread_; return *this; }
58 inline bool anySlot() const { return slot_ ? slot_->getIndex()==any_ : (slotIndex_!=unresolved_ ? slotIndex_==ISlot::any_ : slotName_.compare(anyName(), IString::Case::Insensitive)==0 ); }
59 inline bool unresolvedSlot() const { return slot_==nullptr && (slotIndex_!=unresolved_ || slotName_.length()); }
60 inline bool invalidSlot() const { return slotIndex_ == invalid_; }
61 inline bool hasSlot() const { return slot_ || slotIndex_!=unresolved_ || slotName_.length(); }
62 inline void setSlot(uint32 slot) { slot_ = nullptr; slotIndex_ = slot; slotName_ = IString(); }
63 inline void setSlot(const IString &name) { slot_ = nullptr; slotName_ = name; slotIndex_ = name.length() ? unresolved_ : any_; }
64 inline void setSlot(const ISlot *slot) { slot_ = slot; slotName_ = IString(); slotIndex_ = slot ? unresolved_ : invalid_; }
65 inline void setSlot(const ISlotID &id) { operator=(id); }
66 inline void setAny() { slot_ = nullptr; slotIndex_ = any_; slotName_ = IString(); }
67 inline const ISlot * slot() const { return slot_; }
68 inline uint32 slotIndex() const { return slot_ ? slot_->getIndex() : slotIndex_; }
69 inline IString slotName() const { return slot_ ? slot_->getName() : slotName_; }
70 inline const IString &givenSlotName() const { return slotName_; }
71 inline bool operator <(const ISlotID &slot) const { return slotIndex()<slot.slotIndex(); }
72 inline uint32 thread() const { return thread_; }
73 inline void thread(uint32 t) { thread_ = t; }
74 private:
75 // Used to determine slot in this order of priority
76 const ISlot *slot_ = nullptr; // If non-null
77 uint32 slotIndex_ = ISlot::unresolved_; // if not unresolved
78 IString slotName_; // Last resort
79 uint32 thread_ = 0;
80 };
81
82 class IGroupID : public ISlotID {
83 public:
84 inline static IString nullName() { return IGroup::nullName(); }
85
86 inline IGroupID() { }
87 inline IGroupID(const IGroup *group) : group_(group) { }
88 inline IGroupID(const IGroup *group,const ISlot *slot) : ISlotID(slot), group_(group) { }
89 inline IGroupID(const IString &groupName) : groupName_(groupName) {}
90 inline IGroupID (const IGroup *group,const ISlotID &slot) : ISlotID(slot), group_(group) { }
91 inline IGroupID(const IString &groupName,const IString &slotName) : ISlotID(slotName), group_(nullptr), groupName_(groupName) { }
92 inline IGroupID(const IString &groupName,uint32 slot) : ISlotID(slot), groupName_(groupName) { }
93 inline IGroupID(const IGroupID &id) : ISlotID(id), group_(id.group_), groupName_(id.groupName_) {}
94 inline IGroupID(IGroupID &&id) noexcept : ISlotID(std::move(id)), group_(id.group_), groupName_(std::move(id.groupName_)) {}
95 inline IGroupID(const ISlotID &s) : ISlotID(s) {}
96 inline IGroupID(ISlotID &&s) noexcept : ISlotID(std::move(s)) {}
97 inline const IGroupID &operator=(const IGroupID &id) { ISlotID::operator=(id); group_ = id.group_; groupName_ = id.groupName_; return *this; }
98 inline const IGroupID &operator=(IGroupID &&id) noexcept { ISlotID::operator=(std::move(id)); group_ = id.group_; groupName_ = std::move(id.groupName_); return *this; }
99 inline bool hasGroup() const { if (group_ || groupName_.length()) return true; return false; }
100 inline bool unresolvedGroup() const { return !group_ && groupName_.length(); }
101 inline bool unresolved() const { return unresolvedGroup() || unresolvedSlot(); }
102 inline void setGroup(const IGroup *group) { group_ = group; groupName_ = IString(); }
103 inline void setGroup(const IString &name) { groupName_ = name; group_ = nullptr; }
104 inline const IGroup * group() const { return group_; }
105 inline IString groupName() const { return group_ ? group_->getName() : groupName_; }
106 inline const IString &givenGroupName() const { return groupName_; }
107 inline bool operator <(const IGroupID &group) const { if (slotIndex()!=group.slotIndex()) return slotIndex()<group.slotIndex(); return groupName().compare(group.groupName(),IString::Case::Insensitive)<0; }
108 private:
109 const IGroup *group_ = nullptr; // If non-null groupName_ is ignored.
110 IString groupName_; // Used to find group_, must be non-null if group_ is null.
111 };
112} // namespace itasca
113namespace utility {
114 using itasca::IGroup;
115 using itasca::ISlot;
116 using itasca::IGroupID;
117 using itasca::ISlotID;
118}
119// EoF
Definition istring.h:14
Interface to a group object.
Definition igroup.h:9
virtual IThing * getIThing()=0
Return IThing interface associated with this group.
virtual const IThing * getIThing() const =0
Return IThing interface associated with this group.
static constexpr TType type_
The type identification number for this class, for use in convert_cast() and convert_getcast().
Definition igroup.h:12
virtual IString getName() const =0
Return the group name.
Definition igroup.h:82
Interface to a slot object.
Definition igroup.h:23
virtual const IThing * getIThing() const =0
Return IThing interface associated with this group.
virtual IThing * getIThing()=0
Return IThing interface associated with this group.
static constexpr TType type_
The type identification number for this class, for use in convert_cast() and convert_getcast().
Definition igroup.h:26
Definition igroup.h:41
Base class for items that will be stored in containers.
Definition ithing.h:30
uint32 TType
class type indicator
Definition basedef.h:46
namespace Itasca
Definition basememory.cpp:14
namespace itasca
Definition igenerictet.h:11