vrcore  0.45
visuReal Messkern
 All Classes Files Functions Variables
StatusGroup.h
1 #pragma once
2 
3 inline bool checkStatus (StatusValue vectorValue, StatusValue value, bool bStrict) { return bStrict ? ((vectorValue & value) == value) : ((vectorValue & value) != 0); }
4 inline bool uncheckStatus (StatusValue vectorValue, StatusValue value, bool bStrict) { return bStrict ? ((vectorValue & value) == 0) : ((vectorValue & value) != value); }
5 
7  {
8  private:
9  static const StatusValue shiftValue = 1;
10  public:
11  static const StatusValue St_None = 0;
12  static const StatusValue St_Ready = shiftValue << 0;
13  static const StatusValue St_Error = shiftValue << 1;
14  protected:
15  static const StatusValue NONE = St_None;
16  int currentGroup;
17  std::vector <StatusValue> statusVector;
18  StatusValue bitToStatus (unsigned int nBit) const { return (nBit < sizeof (StatusValue) * 8) ? (shiftValue << nBit) : St_None; }
19  bool inRange (size_t idxGroup) { return idxGroup < statusVector.size (); }
20  void resize (size_t nGroups) { if (statusVector.size () < nGroups) statusVector.resize (nGroups, 0); }
21  void clear (int idxGroup, StatusValue value) { if (value) { statusVector [idxGroup] |= value; statusVector [idxGroup] ^= value; }}
22  public:
23  StatusGroup (size_t nGroups = 1) { resize (nGroups); currentGroup = -1; }
24 // statusFunktionen false im Sinne von nicht gesetzt (auch bei nicht besetzter Group!)
25  bool isStatus (int idxGroup, StatusValue value) { return inRange (idxGroup) && checkStatus (statusVector [idxGroup], value, false); }
26  bool isStrictStatus (int idxGroup, StatusValue value) { return inRange (idxGroup) && checkStatus (statusVector [idxGroup], value, true); }
27  void clearStatus (int idxGroup, StatusValue value) { if (inRange (idxGroup)) clear (idxGroup, value); }
28  StatusValue getStatus (int idxGroup) { return inRange (idxGroup) ? statusVector [idxGroup] : NONE; }
29  void setStatus (int idxGroup, StatusValue value, StatusValue clearValue = 0) { resize (idxGroup + 1); clear (idxGroup, clearValue); statusVector [idxGroup] |= value; }
30  bool isNone (int idxGroup) { return inRange (idxGroup) && statusVector [idxGroup] == NONE; }
31  void setNone (int idxGroup) { resize (idxGroup + 1); statusVector [idxGroup] = NONE; }
32  bool isOneOrOther (int theOne, int theOther, StatusValue value) { return isStatus (theOne, value) || isStatus (theOther, value); }
33  bool isOneAndOther (int theOne, int theOther, StatusValue value) { return isStatus (theOne, value) && isStatus (theOther, value); }
34 // currentFunktionen
35  bool isCurrent () { return currentGroup != -1; }
36  bool isCurrent (int nGroup) const { return currentGroup == nGroup; }
37  bool setCurrent (int nGroup) { resize (nGroup + 1); currentGroup = nGroup; return isCurrent (); }
38  int getCurrent () const { return currentGroup; }
39  void nonCurrent () { currentGroup = -1; }
40  bool switchCurrent (int theOne, int theOther) { return isCurrent (theOne) ? setCurrent (theOther) : isCurrent (theOther) ? setCurrent (theOne) : false; }
41 // currentStatus
42  bool isCurrentStatus (StatusValue value) { return isStatus (currentGroup, value); }
43  bool isOtherStatus (int theOne, int theOther, StatusValue value) { return isCurrent (theOne) ? isStatus (theOther, value) : isCurrent (theOther) ? isStatus (theOne, value) : false; }
44  bool isCurrentStrictStatus (StatusValue value) { return isStrictStatus (currentGroup, value); }
45  bool isOtherStrictStatus (int theOne, int theOther, StatusValue value) { return isCurrent (theOne) ? isStrictStatus (theOther, value) : isCurrent (theOther) ? isStrictStatus (theOne, value) : false; }
46  void clearCurrentStatus (StatusValue value) { if (isCurrent ()) clearStatus (currentGroup, value); }
47  void setCurrentStatus (StatusValue value, StatusValue clearValue = St_None) { if (isCurrent ()) setStatus (currentGroup, value, clearValue); }
48  bool isCurrentNone () { return isNone (currentGroup); }
49  void setCurrentNone () { setNone (currentGroup); }
50 // administrativer
51  void reset () { fillStatus (0); }
52  void resizeStatus (size_t newSize, StatusValue fillValue = St_None) { resize (newSize); fillStatus (fillValue); }
53  void fillStatus (StatusValue fillValue) { for (size_t i = 0, n = statusVector.size (); i < n; i++) statusVector [i] = fillValue; }
54  int getStatusDeepness () const { return sizeof (StatusValue) * 8; }
55  int getSize () { return (int) statusVector.size (); }
56  bool groupExist (int idxGroup) { return -1 < idxGroup && idxGroup < getSize (); }
57 // groupCheck
58  bool containsStatus (StatusValue value, bool bStrict = true) { return countOccurence (value, bStrict) > 0; }
59  bool completeStatus (StatusValue value, bool bStrict = true) { return countOmittance (value, bStrict) == 0; }
60  int countOccurence (StatusValue value, bool bStrict = true)
61  { int cnt = 0; for (size_t i = 0, n = statusVector.size (); i < n; i++) if (checkStatus (statusVector [i], value, bStrict)) cnt++; return cnt; }
62  int countOmittance (StatusValue value, bool bStrict = true)
63  { int cnt = 0; for (size_t i = 0, n = statusVector.size (); i < n; i++) if (uncheckStatus (statusVector [i], value, bStrict)) cnt++; return cnt; }
64 // bitFunktionen
65  void setBit (int idxGroup, unsigned int nBit) { setStatus (idxGroup, bitToStatus (nBit)); }
66  void clearBit (int idxGroup, unsigned int nBit) { clearStatus (idxGroup, bitToStatus (nBit)); }
67  bool isBit (int idxGroup, unsigned int nBit) { return isStatus (idxGroup, bitToStatus (nBit)); }
68 // current - bitFunktionen
69  void setCurrentBit (unsigned int nBit) { setCurrentStatus (bitToStatus (nBit)); }
70  void cleaCurrentrBit (unsigned int nBit) { clearCurrentStatus (bitToStatus (nBit)); }
71  bool isCurrentBit (unsigned int nBit) { return isCurrentStatus (bitToStatus (nBit)); }
72  };
73 
75  {
76  protected:
77  int pos, nextPos;
78  StatusGroup *lpStGr;
79 
80  virtual int nextPosition () { return pos + 1; }
81  public:
82  StatusIterator (StatusGroup *statusGroup) { lpStGr = statusGroup; reset (); }
83  bool hasNext () { nextPos = nextPosition (); return -1 < nextPos && nextPos < lpStGr->getSize (); }
84  int next (bool bSetCurrent = false) { pos = nextPos; if (bSetCurrent) lpStGr->setCurrent (pos); return pos; }
85  void reset () { pos = nextPos = -1; }
86  bool isStatus (StatusValue value) { return lpStGr->isStatus (pos, value); }
87  bool isStrictStatus (StatusValue value) { return lpStGr->isStrictStatus (pos, value); }
88  void clearStatus (StatusValue value) { lpStGr->clearStatus (pos, value); }
89  void setStatus (StatusValue value, StatusValue clearValue = 0) { lpStGr->setStatus (pos, value, clearValue); }
90  };
91 
92 // iteriert über vorhandene
94  {
95  protected:
96  bool bStrict;
97  StatusValue occurenceValue;
98  int nextPosition () { for (int i = pos, n = (int) lpStGr->getSize (); ++i < n; ) if (checkStatus (lpStGr->getStatus (i), occurenceValue, bStrict)) return i; return -1; }
99  public:
100  OccurenceStatusIterator (StatusGroup *statusGroup, StatusValue occurenceValue, bool bStrict = true) : StatusIterator (statusGroup)
101  { this->occurenceValue = occurenceValue; this->bStrict = bStrict; }
102  };
103 
104 // iteriert über fehlende
106  {
107  protected:
108  bool bStrict;
109  StatusValue omittanceValue;
110  int nextPosition () { for (int i = pos, n = (int) lpStGr->getSize (); ++i < n; ) if (uncheckStatus (lpStGr->getStatus (i), omittanceValue, bStrict)) return i; return -1; }
111  public:
112  OmittanceStatusIterator (StatusGroup *statusGroup, StatusValue omittanceValue, bool bStrict = true) : StatusIterator (statusGroup)
113  { this->omittanceValue = omittanceValue; this->bStrict = bStrict; }
114  };
115 
117  {
118  private:
119  std::vector<std::string> groupKeys;
120  public:
121  KeyedStatusGroup () : StatusGroup () {}
122  int getGroupIndex (std::string key) { if (!key.empty ()) for (int i = 0, n = (int) groupKeys.size (); i < n; i++) if (key == groupKeys [i]) return i; return -1; }
123  bool isStatus (std::string key, StatusValue value) { return StatusGroup::isStatus (getGroupIndex (key), value); }
124  bool isStrictStatus (std::string key, StatusValue value) { return StatusGroup::isStrictStatus (getGroupIndex (key), value); }
125  void clearStatus (std::string key, StatusValue value) { return StatusGroup::clearStatus (getGroupIndex (key), value); }
126  StatusValue getStatus (std::string key) { return StatusGroup::getStatus (getGroupIndex (key)); }
127  void setStatus (std::string key, StatusValue value, StatusValue clearValue = 0)
128  { if (key.empty ()) return; int idx = getGroupIndex (key);
129  if (idx == -1) { idx = (int) groupKeys.size (); groupKeys.push_back (key); } StatusGroup::setStatus (idx, value, clearValue); }
130  bool isNone (std::string key) { return StatusGroup::isNone (getGroupIndex (key)); }
131  void setNone (std::string key) { StatusGroup::setNone (getGroupIndex (key)); }
132  };
Definition: StatusGroup.h:116
Definition: StatusGroup.h:105
Definition: StatusGroup.h:74
Definition: StatusGroup.h:93
Definition: StatusGroup.h:6