Itasca C++ Interface
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
igroup.h
1 #pragma once
2 
3 #include "base/src/baseqt.h"
4 
5 namespace itasca {
6  class IThing;
7 
9  class IGroup {
10  public:
12  static constexpr TType type_ = 0x4ecd4d65;
13 #if defined __LINUX || __WINCMAKE
14  inline static QStringView nullName() { return u"None"; }
15 #else
16  inline static QStringView nullName() { return L"None"; }
17 #endif
18  static constexpr uint null_ = 0xFFFFFFFF;
20  virtual IThing * getIThing()=0;
21  virtual const IThing *getIThing() const=0;
22  virtual QString getName() const=0;
24  };
25 
27  class ISlot {
28  public:
30  static constexpr TType type_ = 0x4ecd4d66;
31  static constexpr uint any_ = 0xFFFFFFFF;
32  static constexpr uint invalid_ = 0xFFFFFFFE;
33  static constexpr uint unresolved_ = 0xFFFFFFFD;
34 #if defined __LINUX || __WINCMAKE
35  inline static QStringView anyName() { return u"Any"; }
36  inline static QStringView defaultName() { return u"Default"; }
37  inline static QStringView invalidName() { return u"Invalid"; }
38 #else
39  inline static QStringView anyName() { return L"Any"; }
40  inline static QStringView defaultName() { return L"Default"; }
41  inline static QStringView invalidName() { return L"Invalid"; }
42 #endif
43  virtual IThing * getIThing()=0;
45  virtual const IThing *getIThing() const=0;
46  virtual QString getName() const=0;
48  virtual quint32 getIndex() const = 0;
49  };
50 
51  class ISlotID {
52  public:
53  static constexpr uint any_ = ISlot::any_;
54  static constexpr uint unresolved_ = ISlot::unresolved_;
55  static constexpr uint invalid_ = ISlot::invalid_;
56  inline static QStringView anyName() { return ISlot::anyName(); }
57  inline static QStringView defaultName() { return ISlot::defaultName(); }
58  inline static QStringView invalidName() { return ISlot::invalidName(); }
59 
60  inline ISlotID(const ISlot *slot) : slot_(slot), slotIndex_(slot ? ISlot::unresolved_ : ISlot::invalid_) { }
61  inline ISlotID(uint slot=any_) : slotIndex_(slot) { } // Any slot for read, default slot for write.
62  inline ISlotID(const QString &name) : slotIndex_(name.length() ? ISlot::unresolved_ : ISlot::any_), slotName_(name) { }
63  inline ISlotID(const ISlotID &id) : slot_(id.slot_), slotIndex_(id.slotIndex_), slotName_(id.slotName_), thread_(id.thread_) {}
64  inline ISlotID(ISlotID &&id) noexcept : slot_(id.slot_), slotIndex_(id.slotIndex_), slotName_(std::move(id.slotName_)), thread_(id.thread_) {}
65  inline const ISlotID &operator=(const ISlotID &id) { slot_ = id.slot_; slotIndex_ = id.slotIndex_; slotName_ = id.slotName_; thread_ = id.thread_; return *this; }
66  inline const ISlotID &operator=(ISlotID &&id) noexcept { slot_ = id.slot_; slotIndex_ = id.slotIndex_; slotName_ = std::move(id.slotName_); thread_ = id.thread_; return *this; }
67  inline bool anySlot() const { return slot_ ? slot_->getIndex()==any_ : (slotIndex_!=unresolved_ ? slotIndex_==ISlot::any_ : slotName_.compare(anyName(), Qt::CaseInsensitive)==0 ); }
68  inline bool unresolvedSlot() const { return slot_==nullptr && (slotIndex_!=unresolved_ || slotName_.length()); }
69  inline bool invalidSlot() const { return slotIndex_ == invalid_; }
70  inline bool hasSlot() const { return slot_ || slotIndex_!=unresolved_ || slotName_.length(); }
71  inline void setSlot(uint slot) { slot_ = nullptr; slotIndex_ = slot; slotName_ = QString(); }
72  inline void setSlot(const QString &name) { slot_ = nullptr; slotName_ = name; slotIndex_ = name.length() ? unresolved_ : any_; }
73  inline void setSlot(const ISlot *slot) { slot_ = slot; slotName_ = QString(); slotIndex_ = slot ? unresolved_ : invalid_; }
74  inline void setSlot(const ISlotID &id) { operator=(id); }
75  inline void setAny() { slot_ = nullptr; slotIndex_ = any_; slotName_ = QString(); }
76  inline const ISlot * slot() const { return slot_; }
77  inline uint slotIndex() const { return slot_ ? slot_->getIndex() : slotIndex_; }
78  inline QString slotName() const { return slot_ ? slot_->getName() : slotName_; }
79  inline const QString &givenSlotName() const { return slotName_; }
80  inline bool operator <(const ISlotID &slot) const { return slotIndex()<slot.slotIndex(); }
81  inline quint32 thread() const { return thread_; }
82  inline void thread(quint32 t) { thread_ = t; }
83  private:
84  // Used to determine slot in this order of priority
85  const ISlot *slot_ = nullptr; // If non-null
86  quint32 slotIndex_ = ISlot::unresolved_; // if not unresolved
87  QString slotName_; // Last resort
88  quint32 thread_ = 0;
89  };
90 
91  class IGroupID : public ISlotID {
92  public:
93  inline static QStringView nullName() { return IGroup::nullName(); }
94 
95  inline IGroupID() { }
96  inline IGroupID(const IGroup *group) : group_(group) { }
97  inline IGroupID(const IGroup *group,const ISlot *slot) : ISlotID(slot), group_(group) { }
98  inline IGroupID(const QString &groupName) : groupName_(groupName) {}
99  inline IGroupID (const IGroup *group,const ISlotID &slot) : ISlotID(slot), group_(group) { }
100  inline IGroupID(const QString &groupName,const QString &slotName) : ISlotID(slotName), group_(nullptr), groupName_(groupName) { }
101  inline IGroupID(const QString &groupName,quint32 slot) : ISlotID(slot), groupName_(groupName) { }
102  inline IGroupID(const IGroupID &id) : ISlotID(id), group_(id.group_), groupName_(id.groupName_) {}
103  inline IGroupID(IGroupID &&id) noexcept : ISlotID(std::move(id)), group_(id.group_), groupName_(std::move(id.groupName_)) {}
104  inline IGroupID(const ISlotID &s) : ISlotID(s) {}
105  inline IGroupID(ISlotID &&s) noexcept : ISlotID(std::move(s)) {}
106  inline const IGroupID &operator=(const IGroupID &id) { ISlotID::operator=(id); group_ = id.group_; groupName_ = id.groupName_; return *this; }
107  inline const IGroupID &operator=(IGroupID &&id) noexcept { ISlotID::operator=(std::move(id)); group_ = id.group_; groupName_ = std::move(id.groupName_); return *this; }
108  inline bool hasGroup() const { if (group_ || groupName_.length()) return true; return false; }
109  inline bool unresolvedGroup() const { return !group_ && groupName_.length(); }
110  inline bool unresolved() const { return unresolvedGroup() || unresolvedSlot(); }
111  inline void setGroup(const IGroup *group) { group_ = group; groupName_ = QString(); }
112  inline void setGroup(const QString &name) { groupName_ = name; group_ = nullptr; }
113  inline const IGroup * group() const { return group_; }
114  inline QString groupName() const { return group_ ? group_->getName() : groupName_; }
115  inline const QString &givenGroupName() const { return groupName_; }
116  inline bool operator <(const IGroupID &group) const { if (slotIndex()!=group.slotIndex()) return slotIndex()<group.slotIndex(); return groupName().compare(group.groupName(),Qt::CaseInsensitive)<0; }
117  private:
118  const IGroup *group_ = nullptr; // If non-null groupName_ is ignored.
119  QString groupName_; // Used to find group_, must be non-null if group_ is null.
120  };
121 } // namespace itasca
122 // EoF
Interface to a group object.
Definition: igroup.h:9
namespace Itasca
Definition: basememory.cpp:9
static constexpr TType type_
The type identification number for this class, for use in convert_cast() and convert_getcast().
Definition: igroup.h:30
Interface to a slot object.
Definition: igroup.h:27
virtual IThing * getIThing()=0
Return IThing interface associated with this group.
Definition: igroup.h:91
virtual IThing * getIThing()=0
Return IThing interface associated with this group.
unsigned int TType
class type indicator
Definition: basedef.h:41
static constexpr TType type_
The type identification number for this class, for use in convert_cast() and convert_getcast().
Definition: igroup.h:12
virtual QString getName() const =0
Return the group name.
Definition: igroup.h:51
All default base headers if Qt is being used.