FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
OMEassoc.h
Go to the documentation of this file.
1 #ifndef _OME_ASSOC_H
2 #define _OME_ASSOC_H "$Id: OMEassoc.h 312 2020-03-21 21:25:35Z geoff $"
4 
10 #include <map>
11 
12 #include <OMErefCount.h>
13 #include <OMEstring.h>
14 
23 {
24  friend class OMEassocStorage;
25 
26 private:
27  class OMEstring *key;
28  class OMEbaseType *value;
29 
30  OMEassocKeyPair(OMEstring *k, OMEbaseType *v)
31  {
32  key = k;
33  value = v;
34  }
35 
36  // delete implementation in OMEassoc.cpp since OMEbaseType not known
38 
39  bool operator==(const OMEassocKeyPair &arg) const;
40 
41  bool operator!=(const OMEassocKeyPair &arg) const;
42 
43  template <typename STREAMTYPE>
44  STREAMTYPE &outputOnStream(STREAMTYPE &outputOnStream, int_fast16_t indent = 0,
45  uint8_t includeTypePrefix = OME_DEFAULT_COMPLEX_OUTPUT_MODE) const;
46 }; // end class OMEassocKeyPair
47 
49 
50 // OMEassocStorage is used internally by OMEassoc, thus all of its
51 // members are private and OMEassoc is listed as a friend.
52 
53 class OMEassocStorage final : public OMEreferenceCount
54 {
55  friend class OMEassoc;
57 
58 public:
59  typedef uint32_t ASSOC_HASH_KEY_t;
60 
61 private:
62  typedef _STD map<ASSOC_HASH_KEY_t, OME_KEY_PAIR> AssocArrayType_t;
64 
65  // default initializer
67 
68  // destructor
70 
71  virtual OMEreferenceCount *deepCopy() const override;
72 
73  bool operator==(const OMEassocStorage &arg) const;
74 
75  bool operator!=(const OMEassocStorage &arg) const;
76 
77  OMEbaseType &operator[](const ASSOC_HASH_KEY_t);
78 
79  const OMEbaseType &operator[](const ASSOC_HASH_KEY_t) const;
80 
81  bool deleteIndex(const ASSOC_HASH_KEY_t);
82 
83  const OMEstring &getKeyForIndex(const ASSOC_HASH_KEY_t i) const;
84 
85  bool indexExists(const ASSOC_HASH_KEY_t i) const;
86 
87  ASSOC_HASH_KEY_t nextIndex(const ASSOC_HASH_KEY_t currentSubscript) const;
88 
89  OMEbaseType &operator[](const OMEstring &);
90 
91  const OMEbaseType &operator[](const OMEstring &) const;
92 
93  bool deleteIndex(const OMEstring &);
94 
95  bool indexExists(const OMEstring &) const;
96 
97  uint_fast32_t elementCount() const OME_ALWAYS_INLINE
98  {
99  return (assocArray.size());
100  }
101 
103  {
104  return (assocArray.empty());
105  }
106 
107  template <typename STREAMTYPE>
108  STREAMTYPE &outputOnStream(STREAMTYPE &outputOnStream, int_fast16_t indent = 0,
109  uint8_t includeTypePrefix = OME_DEFAULT_COMPLEX_OUTPUT_MODE) const;
110 }; // end class OMEassocStorage
111 
112 class OME_DLL_EXPORT OMEassoc final : public OMEreferenceToData<OMEassocStorage>
113 {
114 private:
116  {
117  // only used by deepCopy()
118  data = s;
119  // TODO: may add unwanted reference since storage objects have
120  // initial reference count of 1
121  // addReadOnlyReference();
122  }
123 
124 public:
126  // default initializer
128  {
129  data = new OMEassocStorage();
130  }
131 
132  // copy initializer
133  explicit OMEassoc(const OMEassoc &org) : OMEreferenceToData<OMEassocStorage>(org.data)
134  {
135 // data = org.data;
136 // addReadOnlyReference();
137  }
138 
139  // assignment
141  {
142  if (this->data == arg.data) {
143  //std::cout << "OMEassoc assignment to self, ref=" << totalReferences() << "\n";
144  return (*this); // asignment to self...
145  }
146  arg.data->addReadOnlyReference();
147  dropReference(arg.data);
148  return (*this);
149  }
150 
152 
153  // COMPARISON
154  bool operator==(const OMEassoc &arg) const
155  {
156  if (data == arg.data) { // points at same object
157  return (true); // fast path
158  }
159  // evaluate by comparing content
160  return (*data == *arg.data);
161  }
162 
163  bool operator!=(const OMEassoc &arg) const
164  {
165  if (data == arg.data) { // points at same object
166  return (false); // fast path
167  }
168  // evaluate by comparing content
169  return (*data != *arg.data);
170  }
171 
172  OMEbaseType &operator[](const ASSOC_HASH_KEY_t i)
173  {
175  return ((*data)[i]);
176  }
177 
178  const OMEbaseType &operator[](const ASSOC_HASH_KEY_t i) const
179  {
180  // read-only
181  const OMEassocStorage &a = *data;
182  return (a[i]);
183  }
184 
185  OMEbaseType &operator[](const OMEstring &key)
186  {
188  return ((*data)[key]);
189  }
190 
191  const OMEbaseType &operator[](const OMEstring &key) const
192  {
193  // read-only
194  const OMEassocStorage &a = *data;
195  return (a[key]);
196  }
197 
199  {
200  return (data->getKeyForIndex(i));
201  }
202 
204  {
206  return (data->deleteIndex(i));
207  }
208 
210  {
211  return (data->deleteIndex(i));
212  }
213 
214  bool deleteIndex(const OMEstring &key)
215  {
217  return (data->deleteIndex(key));
218  }
219 
220  bool forceDeleteIndex(const OMEstring &key)
221  {
222  // don't do getUniqueReference()
223  return (data->deleteIndex(key));
224  }
225 
226  bool indexExists(const ASSOC_HASH_KEY_t i) const
227  {
228  return (data->indexExists(i));
229  }
230 
231  bool indexExists(const OMEstring &key) const
232  {
233  return (data->indexExists(key));
234  }
235 
236  ASSOC_HASH_KEY_t nextIndex(const ASSOC_HASH_KEY_t currentSubscript) const
237  {
238  return (data->nextIndex(currentSubscript));
239  }
240 
241  uint_fast32_t elementCount() const OME_ALWAYS_INLINE
242  {
243  return (data->elementCount());
244  }
245 
247  {
248  return (data->isEmpty());
249  }
250 
252  {
253 
254  OMEassocStorage *storageCopy = static_cast<OMEassocStorage *>(data->deepCopy());
255  OMEassoc *copy = new OMEassoc(storageCopy);
256  return (copy);
257  }
258 
269  template <typename STREAMTYPE>
270  STREAMTYPE &outputOnStream(STREAMTYPE &outputStream, int_fast16_t indent = 0,
271  uint8_t includeTypePrefix = OME_DEFAULT_COMPLEX_OUTPUT_MODE) const
272  {
273  data->outputOnStream(outputStream, indent, includeTypePrefix);
274  return (outputStream);
275  }
276 }; // end class OMEassoc
277 
278 #define OME_ASSOC_SUB(v) static_cast<OMEassoc::ASSOC_HASH_KEY_t>(v)
279 
282 template <typename STREAMTYPE>
283 inline STREAMTYPE &operator<<(STREAMTYPE &outputStream, const OMEassoc &data)
284 {
285  data.outputOnStream(outputStream, 0);
286  return (outputStream);
287 }
288 
292 #endif
293 /* vim: set expandtab shiftwidth=4 tabstop=4: */
OMEassoc::forceDeleteIndex
bool forceDeleteIndex(const ASSOC_HASH_KEY_t i)
Similar to deleteIndex(), but does not ensure a single reference to the array is held.
Definition: OMEassoc.h:209
OMErefCount.h
OME reference count implementation.
OMEassoc::indexExists
bool indexExists(const OMEstring &key) const
Definition: OMEassoc.h:231
OMEassocStorage::nextIndex
ASSOC_HASH_KEY_t nextIndex(const ASSOC_HASH_KEY_t currentSubscript) const
Definition: OMEassoc.cpp:200
OMEtype::initializeAsType
void initializeAsType(const enum OMEtypes_t t)
The fundamental tagged data type used through the FARGOS/VISTA infrastructure.
Definition: OMEtype.cpp:95
OMEassocKeyPair
Holds the string / data tuple for an element of an OMEassoc sparse array.
Definition: OMEassoc.h:22
OMEprofileCounter< uint32_t >
s
const char s[]
Definition: t.cpp:4
OMEfunctions.h
OME utility functions.
OMEassoc::operator=
OMEassoc & operator=(const OMEassoc &arg)
Definition: OMEassoc.h:140
OMEassocKeyPair::OMEassocKeyPair
OMEassocKeyPair(OMEstring *k, OMEtype *v)
Definition: OMEassoc.h:30
OMEstring.h
OME string implementation.
OMEassocStorage::outputOnStream
STREAMTYPE & outputOnStream(STREAMTYPE &outputOnStream, int_fast16_t indent=0, uint8_t includeTypePrefix=OME_DEFAULT_COMPLEX_OUTPUT_MODE) const
Definition: OMEoutputOnStream.h:63
OMEassocStorage::indexExists
bool indexExists(const ASSOC_HASH_KEY_t i) const
Definition: OMEassoc.cpp:182
OMEassoc::OMEassoc
OMEassoc(OMEassocStorage *s)
Definition: OMEassoc.h:115
OMEassoc::isEmpty
bool isEmpty() const OME_ALWAYS_INLINE
Definition: OMEassoc.h:246
OMEassoc
Implements associative array of OMEtype elements.
Definition: OMEassoc.h:112
OMEassoc::nextIndex
ASSOC_HASH_KEY_t nextIndex(const ASSOC_HASH_KEY_t currentSubscript) const
Definition: OMEassoc.h:236
OMEstring
Implements text and binary string storage.
Definition: OMEstring.h:305
OMEassocStorage::getKeyForIndex
const OMEstring & getKeyForIndex(const ASSOC_HASH_KEY_t i) const
Definition: OMEassoc.cpp:158
stderr
#define stderr
Definition: tmp.o.cpp:3115
OMEassoc::OMEassoc
OMEassoc()
Definition: OMEassoc.h:127
OMEreferenceToData::data
C * data
Definition: OMErefCount.h:82
OMEassoc::~OMEassoc
~OMEassoc()
Definition: OMEassoc.h:151
OMEtype::value
union OMEtype::@26 value
OMEhash
OME_DLL_EXPORT uint32_t OMEhash(const unsigned char *data, const uint32_t len) NONNULL_PARAMETERS(1)
Fast 32-bit hash over a buffer.
Definition: OMEhash.cpp:13
OMEassoc::indexExists
bool indexExists(const ASSOC_HASH_KEY_t i) const
Definition: OMEassoc.h:226
OMEassocKeyPair::operator!=
bool operator!=(const OMEassocKeyPair &arg) const
Definition: OMEassoc.cpp:40
OMEassocStorage::operator[]
OMEtype & operator[](const ASSOC_HASH_KEY_t)
Definition: OMEassoc.cpp:119
OMEassoc::operator==
bool operator==(const OMEassoc &arg) const
Definition: OMEassoc.h:154
OMEassocStorage
Reference-counted maintainer of an associative array. Used internally by OMEassoc.
Definition: OMEassoc.h:53
OMEassocStorage::deepCopy
virtual OMEreferenceCount * deepCopy() const override
Definition: OMEassoc.cpp:79
OMEassocKeyPair::~OMEassocKeyPair
~OMEassocKeyPair()
Definition: OMEassoc.cpp:23
OMEreferenceToData
Templated type-specific reference to a reference-counted object.
Definition: OMErefCount.h:79
OMEreferenceCount
Base class for reference-counted data.
Definition: OMErefCount.h:31
OMEassocStorage::operator!=
bool operator!=(const OMEassocStorage &arg) const
Definition: OMEassoc.cpp:407
OMEassocKeyPair::key
class OMEstring * key
Definition: OMEassoc.h:27
OMEassocKeyPair::outputOnStream
STREAMTYPE & outputOnStream(STREAMTYPE &outputOnStream, int_fast16_t indent=0, uint8_t includeTypePrefix=OME_DEFAULT_COMPLEX_OUTPUT_MODE) const
Definition: OMEoutputOnStream.h:55
srcID
const char srcID[]
Definition: catSym.c:17
OMEassoc::getKeyForIndex
const OMEstring & getKeyForIndex(const ASSOC_HASH_KEY_t i) const
Definition: OMEassoc.h:198
operator<<
STREAMTYPE & operator<<(STREAMTYPE &outputStream, const OMEassoc &data)
Output an OMEassoc object to an output stream.
Definition: OMEassoc.h:283
aCount
int aCount
Definition: OMEassoc.cpp:73
OMEassocStorage::AssocArrayType_t
_STD map< ASSOC_HASH_KEY_t, OME_KEY_PAIR > AssocArrayType_t
Definition: OMEassoc.h:62
OMEassoc::outputOnStream
STREAMTYPE & outputOnStream(STREAMTYPE &outputStream, int_fast16_t indent=0, uint8_t includeTypePrefix=OME_DEFAULT_COMPLEX_OUTPUT_MODE) const
Output an OMEassoc object to an output stream.
Definition: OMEassoc.h:270
deleteIndex
int deleteIndex(OMEthread *thread, OMEtype &result, const OMEtype &array, const OMEtype &subscript)
Definition: OILtypeFuncs.cpp:452
OME_NIL
@ OME_NIL
Definition: OMEmanifests.h:78
OMEassocKeyPair::operator==
bool operator==(const OMEassocKeyPair &arg) const
Definition: OMEassoc.cpp:29
_OME_ASSOC_H
#define _OME_ASSOC_H
Definition: tmp.o.cpp:965
OMEassocStorage::ASSOC_HASH_KEY_t
uint32_t ASSOC_HASH_KEY_t
Definition: OMEassoc.h:59
OMEassoc.h
OME associative array implementation.
OMEassocStorage::deleteIndex
bool deleteIndex(const ASSOC_HASH_KEY_t)
Definition: OMEassoc.cpp:172
OMEassoc::ASSOC_HASH_KEY_t
OMEassocStorage::ASSOC_HASH_KEY_t ASSOC_HASH_KEY_t
Definition: OMEassoc.h:125
OMEtype.h
OME fundamental type implementation.
OMEassocKeyPair::value
class OMEtype * value
Definition: OMEassoc.h:28
getKeyForIndex
int getKeyForIndex(OMEthread *thread, OMEtype &result, const OMEtype &array, const OMEtype &subscript)
Definition: OILtypeFuncs.cpp:437
OMEassoc::forceDeleteIndex
bool forceDeleteIndex(const OMEstring &key)
Similar to deleteIndex(), but does not ensure a single reference to the array is held.
Definition: OMEassoc.h:220
OMEassoc::operator[]
OMEtype & operator[](const ASSOC_HASH_KEY_t i)
Subscript reference !
Definition: OMEassoc.h:172
OMEassocStorage::~OMEassocStorage
~OMEassocStorage()
Definition: OMEassoc.cpp:60
OME_USED
const char srcID[] OME_USED
Definition: tick_time.cpp:24
OMEassoc::operator[]
const OMEtype & operator[](const OMEstring &key) const
read-only subscript reference using a string key. !
Definition: OMEassoc.h:191
OMEassocStorage::OMEassocStorage
OMEassocStorage()
Definition: OMEassoc.cpp:56
OMEreferenceCount::addReadOnlyReference
void addReadOnlyReference()
Definition: OMErefCount.cpp:139
OMEassocStorage::assocArray
AssocArrayType_t assocArray
Definition: OMEassoc.h:63
OME_SET
@ OME_SET
Definition: OMEmanifests.h:89
OMEassoc::OMEassoc
OMEassoc(const OMEassoc &org)
Definition: OMEassoc.h:133
OME_ALWAYS_INLINE
#define OME_ALWAYS_INLINE
Tell the compiler to alway inline a function, regardless of optimization level.
Definition: compiler_hints.h:364
OMEassoc::operator[]
const OMEtype & operator[](const ASSOC_HASH_KEY_t i) const
read-only subscript reference !
Definition: OMEassoc.h:178
OME_KEY_PAIR
class OMEassocKeyPair * OME_KEY_PAIR
Definition: OMEassoc.h:48
OMEreferenceToData::dropReference
void dropReference(C *newData=nullptr) OME_ALWAYS_INLINE
Definition: OMErefCount.h:91
noteDeepCopy
void noteDeepCopy()
Definition: OMEassoc.cpp:74
OMEassocStorage::elementCount
uint_fast32_t elementCount() const OME_ALWAYS_INLINE
Definition: OMEassoc.h:97
_STD
#define _STD
Definition: OMEmanifests.h:146
OMEdebugInfo.h
OME debug and profiling interfaces.
OMEassoc::deepCopy
OMEassoc * deepCopy() const
Definition: OMEassoc.h:251
OMEreferenceToData::getUniqueReference
void getUniqueReference()
Force unique reference to the data, which will trigger duplication if necessary (copy-on-write).
Definition: OMErefCount.h:127
OME_DLL_EXPORT
#define OME_DLL_EXPORT
Definition: compiler_hints.h:464
OMEassoc::operator[]
OMEtype & operator[](const OMEstring &key)
subscript reference using a string key. !
Definition: OMEassoc.h:185
OMEassocStorage::isEmpty
bool isEmpty() const OME_ALWAYS_INLINE
Definition: OMEassoc.h:102
OME_DEFAULT_COMPLEX_OUTPUT_MODE
@ OME_DEFAULT_COMPLEX_OUTPUT_MODE
Definition: OMEmanifests.h:116
OMEassoc::elementCount
uint_fast32_t elementCount() const OME_ALWAYS_INLINE
Definition: OMEassoc.h:241
OMEassoc::deleteIndex
bool deleteIndex(const OMEstring &key)
Definition: OMEassoc.h:214
OMEassoc::operator!=
bool operator!=(const OMEassoc &arg) const
Definition: OMEassoc.h:163
OME_ARRAY
@ OME_ARRAY
Definition: OMEmanifests.h:86
OMEtype
#define OMEtype
Definition: tmp.o.cpp:396
OMEassoc::deleteIndex
bool deleteIndex(const ASSOC_HASH_KEY_t i)
Definition: OMEassoc.h:203
OME_ASSOC
@ OME_ASSOC
Definition: OMEmanifests.h:87
OMEassocStorage::operator==
bool operator==(const OMEassocStorage &arg) const
Definition: OMEassoc.cpp:354
Generated: Fri Jul 31 2020 18:19:14
Support Information