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
00231 DLLEXPORT QoreHashNode *copy() const;
00232
00234
00241 DLLEXPORT AbstractQoreNode **getKeyValuePtr(const QoreString *key, ExceptionSink *xsink);
00242
00244
00248 DLLEXPORT AbstractQoreNode **getKeyValuePtr(const char *key);
00249
00251
00257 DLLEXPORT AbstractQoreNode **getExistingValuePtr(const QoreString *key, ExceptionSink *xsink);
00258
00260
00263 DLLEXPORT AbstractQoreNode **getExistingValuePtr(const char *key);
00264
00266
00271 DLLEXPORT void merge(const QoreHashNode *h, ExceptionSink *xsink);
00272
00274
00280 DLLEXPORT void setKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink);
00281
00283
00289 DLLEXPORT void setKeyValue(const char *key, AbstractQoreNode *value, ExceptionSink *xsink);
00290
00292
00298 DLLEXPORT AbstractQoreNode *swapKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink);
00299
00301
00305 DLLEXPORT AbstractQoreNode *swapKeyValue(const char *key, AbstractQoreNode *value);
00306
00308
00313 DLLEXPORT void deleteKey(const QoreString *key, ExceptionSink *xsink);
00314
00316
00320 DLLEXPORT void deleteKey(const char *key, ExceptionSink *xsink);
00321
00323
00327 DLLEXPORT AbstractQoreNode *takeKeyValue(const QoreString *key, ExceptionSink *xsink);
00328
00330
00333 DLLEXPORT AbstractQoreNode *takeKeyValue(const char *key);
00334
00336
00339 DLLEXPORT QoreListNode *getKeys() const;
00340
00342
00345 DLLEXPORT bool compareSoft(const QoreHashNode *h, ExceptionSink *xsink) const;
00346
00348
00351 DLLEXPORT bool compareHard(const QoreHashNode *h, ExceptionSink *xsink) const;
00352
00354
00356 DLLEXPORT qore_size_t size() const;
00357
00359
00361 DLLEXPORT bool empty() const;
00362
00363 DLLLOCAL QoreHashNode(bool ne);
00364 DLLLOCAL void clear(ExceptionSink *xsink);
00365
00367 DLLLOCAL void clearNeedsEval();
00368
00370 DLLLOCAL void setNeedsEval();
00371
00372 DLLLOCAL AbstractQoreNode *evalKeyValue(const QoreString *key, ExceptionSink *xsink) const;
00373
00374
00375 DLLLOCAL QoreHashNode *getSlice(const QoreListNode *value_list, ExceptionSink *xsink) const;
00376
00377
00378 DLLLOCAL AbstractQoreNode *getReferencedKeyValue(const char *key) const;
00379
00380
00381 DLLLOCAL AbstractQoreNode *getReferencedKeyValue(const char *key, bool &exists) const;
00382
00383 DLLLOCAL AbstractQoreNode *getFirstKeyValue() const;
00384
00386
00390 DLLEXPORT void removeKey(const QoreString *key, ExceptionSink *xsink);
00391
00393
00397 DLLEXPORT void removeKey(const char *key, ExceptionSink *xsink);
00398 };
00399
00400 #include <qore/ReferenceHolder.h>
00401
00403
00406 typedef ReferenceHolder<QoreHashNode> QoreHashNodeHolder;
00407
00409
00418 class HashIterator {
00419 private:
00420 class QoreHashNode *h;
00421 HashMember *ptr;
00422
00424 DLLLOCAL HashIterator(const HashIterator&);
00425
00427 DLLLOCAL HashIterator& operator=(const HashIterator&);
00428
00430 DLLLOCAL void* operator new(size_t);
00431
00432 public:
00434 DLLEXPORT HashIterator(QoreHashNode *h);
00435
00437 DLLEXPORT HashIterator(QoreHashNode &h);
00438
00440
00443 DLLEXPORT bool next();
00444
00446 DLLEXPORT const char *getKey() const;
00447
00449 DLLEXPORT QoreString *getKeyString() const;
00450
00452 DLLEXPORT AbstractQoreNode *getValue() const;
00453
00455 DLLEXPORT AbstractQoreNode *takeValueAndDelete();
00456
00458
00462 DLLEXPORT void deleteKey(ExceptionSink *xsink);
00463
00465 DLLEXPORT AbstractQoreNode **getValuePtr() const;
00466
00468 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00469
00471 DLLEXPORT bool first() const;
00472
00474 DLLEXPORT bool last() const;
00475
00476
00477 };
00478
00480
00489 class ConstHashIterator {
00490 private:
00491 const QoreHashNode *h;
00492 HashMember *ptr;
00493
00495 DLLLOCAL ConstHashIterator(const HashIterator&);
00496
00498 DLLLOCAL ConstHashIterator& operator=(const HashIterator&);
00499
00501 DLLLOCAL void* operator new(size_t);
00502
00503 public:
00505 DLLEXPORT ConstHashIterator(const QoreHashNode *h);
00506
00508 DLLEXPORT ConstHashIterator(const QoreHashNode &h);
00509
00511
00514 DLLEXPORT bool next();
00515
00517 DLLEXPORT const char *getKey() const;
00518
00520 DLLEXPORT QoreString *getKeyString() const;
00521
00523 DLLEXPORT const AbstractQoreNode *getValue() const;
00524
00526 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00527
00529 DLLEXPORT bool first() const;
00530
00532 DLLEXPORT bool last() const;
00533 };
00534
00535 #endif // _QORE_HASH_H