00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _QORE_QOREHASHNODE_H
00024
00025 #define _QORE_QOREHASHNODE_H
00026
00027 #include <qore/AbstractQoreNode.h>
00028 #include <qore/common.h>
00029 #include <qore/hash_map.h>
00030
00031 class HashMember;
00032 class LocalVar;
00033
00035
00041 class QoreHashNode : public AbstractQoreNode {
00042 friend class HashIterator;
00043 friend class ConstHashIterator;
00044
00045 private:
00047 DLLLOCAL QoreHashNode(const QoreHashNode&);
00048
00050 DLLLOCAL QoreHashNode& operator=(const QoreHashNode&);
00051
00052 protected:
00054 struct qore_hash_private *priv;
00055
00057
00063 DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
00064
00066
00069 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
00070
00072
00075 DLLLOCAL virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
00076
00078 DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00079
00081 DLLLOCAL virtual int integerEvalImpl(ExceptionSink *xsink) const;
00082
00084 DLLLOCAL virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00085
00087 DLLLOCAL virtual double floatEvalImpl(ExceptionSink *xsink) const;
00088
00090
00093 DLLEXPORT virtual ~QoreHashNode();
00094
00095 public:
00097 DLLEXPORT QoreHashNode();
00098
00100
00106 DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const;
00107
00109
00116 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const;
00117
00119
00121 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
00122
00124
00128 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00129
00131
00135 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00136
00138
00140 DLLEXPORT virtual const char *getTypeName() const;
00141
00143
00145 DLLLOCAL static const char *getStaticTypeName() {
00146 return "hash";
00147 }
00148
00150
00152 DLLEXPORT QoreHashNode *hashRefSelf() const;
00153
00155
00157 DLLEXPORT const char *getFirstKey() const;
00158
00160
00162 DLLEXPORT const char *getLastKey() const;
00163
00165
00169 DLLEXPORT AbstractQoreNode *getKeyValueExistence(const char *key, bool &exists);
00170
00172
00176 DLLEXPORT const AbstractQoreNode *getKeyValueExistence(const char *key, bool &exists) const;
00177
00179
00186 DLLEXPORT AbstractQoreNode *getKeyValueExistence(const QoreString *key, bool &exists, ExceptionSink *xsink);
00187
00189
00196 DLLEXPORT const AbstractQoreNode *getKeyValueExistence(const QoreString *key, bool &exists, ExceptionSink *xsink) const;
00197
00199
00205 DLLEXPORT AbstractQoreNode *getKeyValue(const QoreString *key, ExceptionSink *xsink);
00206
00208
00214 DLLEXPORT const AbstractQoreNode *getKeyValue(const QoreString *key, ExceptionSink *xsink) const;
00215
00217
00220 DLLEXPORT AbstractQoreNode *getKeyValue(const char *key);
00221
00223
00226 DLLEXPORT const AbstractQoreNode *getKeyValue(const char *key) const;
00227
00229
00233 DLLEXPORT int64 getKeyAsBigInt(const char *key, bool &found) const;
00234
00236
00238 DLLEXPORT QoreHashNode *copy() const;
00239
00241
00248 DLLEXPORT AbstractQoreNode **getKeyValuePtr(const QoreString *key, ExceptionSink *xsink);
00249
00251
00255 DLLEXPORT AbstractQoreNode **getKeyValuePtr(const char *key);
00256
00258
00264 DLLEXPORT AbstractQoreNode **getExistingValuePtr(const QoreString *key, ExceptionSink *xsink);
00265
00267
00270 DLLEXPORT AbstractQoreNode **getExistingValuePtr(const char *key);
00271
00273
00278 DLLEXPORT void merge(const QoreHashNode *h, ExceptionSink *xsink);
00279
00281
00287 DLLEXPORT void setKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink);
00288
00290
00296 DLLEXPORT void setKeyValue(const char *key, AbstractQoreNode *value, ExceptionSink *xsink);
00297
00299
00305 DLLEXPORT AbstractQoreNode *swapKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink);
00306
00308
00312 DLLEXPORT AbstractQoreNode *swapKeyValue(const char *key, AbstractQoreNode *value);
00313
00315
00320 DLLEXPORT void deleteKey(const QoreString *key, ExceptionSink *xsink);
00321
00323
00327 DLLEXPORT void deleteKey(const char *key, ExceptionSink *xsink);
00328
00330
00334 DLLEXPORT AbstractQoreNode *takeKeyValue(const QoreString *key, ExceptionSink *xsink);
00335
00337
00340 DLLEXPORT AbstractQoreNode *takeKeyValue(const char *key);
00341
00343
00346 DLLEXPORT QoreListNode *getKeys() const;
00347
00349
00352 DLLEXPORT bool compareSoft(const QoreHashNode *h, ExceptionSink *xsink) const;
00353
00355
00358 DLLEXPORT bool compareHard(const QoreHashNode *h, ExceptionSink *xsink) const;
00359
00361
00363 DLLEXPORT qore_size_t size() const;
00364
00366
00368 DLLEXPORT bool empty() const;
00369
00370 DLLLOCAL QoreHashNode(bool ne);
00371 DLLLOCAL void clear(ExceptionSink *xsink);
00372
00374 DLLLOCAL void clearNeedsEval();
00375
00377 DLLLOCAL void setNeedsEval();
00378
00379 DLLLOCAL AbstractQoreNode *evalKeyValue(const QoreString *key, ExceptionSink *xsink) const;
00380
00381
00382 DLLLOCAL QoreHashNode *getSlice(const QoreListNode *value_list, ExceptionSink *xsink) const;
00383
00384
00385 DLLLOCAL AbstractQoreNode *getReferencedKeyValue(const char *key) const;
00386
00387
00388 DLLLOCAL AbstractQoreNode *getReferencedKeyValue(const char *key, bool &exists) const;
00389
00390 DLLLOCAL AbstractQoreNode *getFirstKeyValue() const;
00391
00393
00397 DLLEXPORT void removeKey(const QoreString *key, ExceptionSink *xsink);
00398
00400
00404 DLLEXPORT void removeKey(const char *key, ExceptionSink *xsink);
00405 };
00406
00407 #include <qore/ReferenceHolder.h>
00408
00410
00413 typedef ReferenceHolder<QoreHashNode> QoreHashNodeHolder;
00414
00416
00425 class HashIterator {
00426 private:
00427 class QoreHashNode *h;
00428 HashMember *ptr;
00429
00431 DLLLOCAL HashIterator(const HashIterator&);
00432
00434 DLLLOCAL HashIterator& operator=(const HashIterator&);
00435
00437 DLLLOCAL void* operator new(size_t);
00438
00439 public:
00441 DLLEXPORT HashIterator(QoreHashNode *h);
00442
00444 DLLEXPORT HashIterator(QoreHashNode &h);
00445
00447
00450 DLLEXPORT bool next();
00451
00453 DLLEXPORT const char *getKey() const;
00454
00456 DLLEXPORT QoreString *getKeyString() const;
00457
00459 DLLEXPORT AbstractQoreNode *getValue() const;
00460
00462 DLLEXPORT AbstractQoreNode *takeValueAndDelete();
00463
00465
00469 DLLEXPORT void deleteKey(ExceptionSink *xsink);
00470
00472 DLLEXPORT AbstractQoreNode **getValuePtr() const;
00473
00475 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00476
00478 DLLEXPORT bool first() const;
00479
00481 DLLEXPORT bool last() const;
00482
00483
00484 };
00485
00487
00496 class ConstHashIterator {
00497 private:
00498 const QoreHashNode *h;
00499 HashMember *ptr;
00500
00502 DLLLOCAL ConstHashIterator(const HashIterator&);
00503
00505 DLLLOCAL ConstHashIterator& operator=(const HashIterator&);
00506
00508 DLLLOCAL void* operator new(size_t);
00509
00510 public:
00512 DLLEXPORT ConstHashIterator(const QoreHashNode *h);
00513
00515 DLLEXPORT ConstHashIterator(const QoreHashNode &h);
00516
00518
00521 DLLEXPORT bool next();
00522
00524 DLLEXPORT const char *getKey() const;
00525
00527 DLLEXPORT QoreString *getKeyString() const;
00528
00530 DLLEXPORT const AbstractQoreNode *getValue() const;
00531
00533 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00534
00536 DLLEXPORT bool first() const;
00537
00539 DLLEXPORT bool last() const;
00540 };
00541
00542 #endif // _QORE_HASH_H