00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _QORE_QOREHASHNODE_H
00025
00026 #define _QORE_QOREHASHNODE_H
00027
00028 #include <qore/AbstractQoreNode.h>
00029 #include <qore/common.h>
00030 #include <qore/hash_map.h>
00031
00032 class HashMember;
00033 class LocalVar;
00034
00036
00042 class QoreHashNode : public AbstractQoreNode {
00043 friend class HashIterator;
00044 friend class ConstHashIterator;
00045
00046 private:
00048 DLLLOCAL QoreHashNode(const QoreHashNode&);
00049
00051 DLLLOCAL QoreHashNode& operator=(const QoreHashNode&);
00052
00053 protected:
00055 struct qore_hash_private *priv;
00056
00058
00064 DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
00065
00067
00070 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
00071
00073
00076 DLLLOCAL virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
00077
00079 DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00080
00082 DLLLOCAL virtual int integerEvalImpl(ExceptionSink *xsink) const;
00083
00085 DLLLOCAL virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00086
00088 DLLLOCAL virtual double floatEvalImpl(ExceptionSink *xsink) const;
00089
00091
00094 DLLEXPORT virtual ~QoreHashNode();
00095
00096 public:
00098 DLLEXPORT QoreHashNode();
00099
00101
00107 DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const;
00108
00110
00117 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const;
00118
00120
00122 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
00123
00125
00129 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00130
00132
00136 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00137
00139
00141 DLLEXPORT virtual const char *getTypeName() const;
00142
00144
00146 DLLLOCAL static const char *getStaticTypeName() {
00147 return "hash";
00148 }
00149
00151
00153 DLLEXPORT QoreHashNode *hashRefSelf() const;
00154
00156
00158 DLLEXPORT const char *getFirstKey() const;
00159
00161
00163 DLLEXPORT const char *getLastKey() const;
00164
00166
00170 DLLEXPORT AbstractQoreNode *getKeyValueExistence(const char *key, bool &exists);
00171
00173
00177 DLLEXPORT const AbstractQoreNode *getKeyValueExistence(const char *key, bool &exists) const;
00178
00180
00187 DLLEXPORT AbstractQoreNode *getKeyValueExistence(const QoreString *key, bool &exists, ExceptionSink *xsink);
00188
00190
00197 DLLEXPORT const AbstractQoreNode *getKeyValueExistence(const QoreString *key, bool &exists, ExceptionSink *xsink) const;
00198
00200
00206 DLLEXPORT AbstractQoreNode *getKeyValue(const QoreString *key, ExceptionSink *xsink);
00207
00209
00215 DLLEXPORT const AbstractQoreNode *getKeyValue(const QoreString *key, ExceptionSink *xsink) const;
00216
00218
00221 DLLEXPORT AbstractQoreNode *getKeyValue(const char *key);
00222
00224
00227 DLLEXPORT const AbstractQoreNode *getKeyValue(const char *key) const;
00228
00230
00234 DLLEXPORT int64 getKeyAsBigInt(const char *key, bool &found) const;
00235
00237
00239 DLLEXPORT QoreHashNode *copy() const;
00240
00242
00249 DLLEXPORT AbstractQoreNode **getKeyValuePtr(const QoreString *key, ExceptionSink *xsink);
00250
00252
00256 DLLEXPORT AbstractQoreNode **getKeyValuePtr(const char *key);
00257
00259
00265 DLLEXPORT AbstractQoreNode **getExistingValuePtr(const QoreString *key, ExceptionSink *xsink);
00266
00268
00271 DLLEXPORT AbstractQoreNode **getExistingValuePtr(const char *key);
00272
00274
00279 DLLEXPORT void merge(const QoreHashNode *h, ExceptionSink *xsink);
00280
00282
00288 DLLEXPORT void setKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink);
00289
00291
00297 DLLEXPORT void setKeyValue(const char *key, AbstractQoreNode *value, ExceptionSink *xsink);
00298
00300
00306 DLLEXPORT AbstractQoreNode *swapKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink);
00307
00309
00313 DLLEXPORT AbstractQoreNode *swapKeyValue(const char *key, AbstractQoreNode *value);
00314
00316
00321 DLLEXPORT void deleteKey(const QoreString *key, ExceptionSink *xsink);
00322
00324
00328 DLLEXPORT void deleteKey(const char *key, ExceptionSink *xsink);
00329
00331
00335 DLLEXPORT AbstractQoreNode *takeKeyValue(const QoreString *key, ExceptionSink *xsink);
00336
00338
00341 DLLEXPORT AbstractQoreNode *takeKeyValue(const char *key);
00342
00344
00347 DLLEXPORT QoreListNode *getKeys() const;
00348
00350
00353 DLLEXPORT bool compareSoft(const QoreHashNode *h, ExceptionSink *xsink) const;
00354
00356
00359 DLLEXPORT bool compareHard(const QoreHashNode *h, ExceptionSink *xsink) const;
00360
00362
00364 DLLEXPORT qore_size_t size() const;
00365
00367
00369 DLLEXPORT bool empty() const;
00370
00372
00376 DLLEXPORT bool existsKey(const char *key) const;
00377
00379
00382 DLLEXPORT bool existsKeyValue(const char *key) const;
00383
00385
00389 DLLEXPORT void removeKey(const QoreString *key, ExceptionSink *xsink);
00390
00392
00396 DLLEXPORT void removeKey(const char *key, ExceptionSink *xsink);
00397
00399 DLLLOCAL virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
00400
00401 DLLLOCAL QoreHashNode(bool ne);
00402 DLLLOCAL void clear(ExceptionSink *xsink);
00403
00405 DLLLOCAL void clearNeedsEval();
00406
00408 DLLLOCAL void setNeedsEval();
00409
00410 DLLLOCAL AbstractQoreNode *evalKeyValue(const QoreString *key, ExceptionSink *xsink) const;
00411
00412
00413 DLLLOCAL QoreHashNode *getSlice(const QoreListNode *value_list, ExceptionSink *xsink) const;
00414
00415
00416 DLLLOCAL AbstractQoreNode *getReferencedKeyValue(const char *key) const;
00417
00418
00419 DLLLOCAL AbstractQoreNode *getReferencedKeyValue(const char *key, bool &exists) const;
00420
00421 DLLLOCAL AbstractQoreNode *getFirstKeyValue() const;
00422
00423 DLLLOCAL static void doDuplicateKeyWarning(const char *key);
00424 };
00425
00426 #include <qore/ReferenceHolder.h>
00427
00429
00432 typedef ReferenceHolder<QoreHashNode> QoreHashNodeHolder;
00433
00435
00444 class HashIterator {
00445 private:
00446 QoreHashNode *h;
00447 HashMember *ptr;
00448
00450 DLLLOCAL HashIterator(const HashIterator&);
00451
00453 DLLLOCAL HashIterator& operator=(const HashIterator&);
00454
00456 DLLLOCAL void* operator new(size_t);
00457
00458 public:
00460 DLLEXPORT HashIterator(QoreHashNode *h);
00461
00463 DLLEXPORT HashIterator(QoreHashNode &h);
00464
00466
00469 DLLEXPORT bool next();
00470
00472 DLLEXPORT const char *getKey() const;
00473
00475 DLLEXPORT QoreString *getKeyString() const;
00476
00478 DLLEXPORT AbstractQoreNode *getValue() const;
00479
00481 DLLEXPORT AbstractQoreNode *takeValueAndDelete();
00482
00484
00488 DLLEXPORT void deleteKey(ExceptionSink *xsink);
00489
00491 DLLEXPORT AbstractQoreNode **getValuePtr() const;
00492
00494 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00495
00497 DLLEXPORT bool first() const;
00498
00500 DLLEXPORT bool last() const;
00501
00502
00503 };
00504
00506
00515 class ConstHashIterator {
00516 private:
00517 const QoreHashNode *h;
00518 HashMember *ptr;
00519
00521 DLLLOCAL ConstHashIterator(const HashIterator&);
00522
00524 DLLLOCAL ConstHashIterator& operator=(const HashIterator&);
00525
00527 DLLLOCAL void* operator new(size_t);
00528
00529 public:
00531 DLLEXPORT ConstHashIterator(const QoreHashNode *h);
00532
00534 DLLEXPORT ConstHashIterator(const QoreHashNode &h);
00535
00537
00540 DLLEXPORT bool next();
00541
00543 DLLEXPORT const char *getKey() const;
00544
00546 DLLEXPORT QoreString *getKeyString() const;
00547
00549 DLLEXPORT const AbstractQoreNode *getValue() const;
00550
00552 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00553
00555 DLLEXPORT bool first() const;
00556
00558 DLLEXPORT bool last() const;
00559 };
00560
00561 #endif // _QORE_HASH_H