Qore Programming Language  0.8.7
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreHashNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreHashNode.h
4 
5  Qore Programming Language
6 
7  Copyright 2003 - 2013 David Nichols
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
24 #ifndef _QORE_QOREHASHNODE_H
25 
26 #define _QORE_QOREHASHNODE_H
27 
28 #include <qore/AbstractQoreNode.h>
29 #include <qore/common.h>
30 
31 class HashMember;
32 class LocalVar;
33 
35 
42  friend class HashIterator;
43  friend class ReverseHashIterator;
44  friend class ConstHashIterator;
45  friend class ReverseConstHashIterator;
46  friend class HashAssignmentHelper;
47  friend class hash_assignment_priv;
48  friend class qore_object_private;
49  friend class qore_hash_private;
50 
51 private:
53  DLLLOCAL QoreHashNode(const QoreHashNode&);
54 
56  DLLLOCAL QoreHashNode& operator=(const QoreHashNode&);
57 
58 protected:
60  class qore_hash_private *priv;
61 
63 
69  DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
70 
72 
75  DLLEXPORT virtual AbstractQoreNode* evalImpl(ExceptionSink* xsink) const;
76 
78 
81  DLLLOCAL virtual AbstractQoreNode* evalImpl(bool &needs_deref, ExceptionSink* xsink) const;
82 
84  DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink* xsink) const;
85 
87  DLLLOCAL virtual int integerEvalImpl(ExceptionSink* xsink) const;
88 
90  DLLLOCAL virtual bool boolEvalImpl(ExceptionSink* xsink) const;
91 
93  DLLLOCAL virtual double floatEvalImpl(ExceptionSink* xsink) const;
94 
96 
99  DLLEXPORT virtual ~QoreHashNode();
100 
101 public:
103  DLLEXPORT QoreHashNode();
104 
106 
108  DLLEXPORT virtual bool getAsBoolImpl() const;
109 
111 
117  DLLEXPORT virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
118 
120 
127  DLLEXPORT virtual QoreString* getAsString(bool &del, int foff, ExceptionSink* xsink) const;
128 
130 
132  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
133 
135 
139  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
140 
142 
146  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
147 
149 
151  DLLEXPORT virtual const char* getTypeName() const;
152 
154 
156  DLLEXPORT QoreHashNode* hashRefSelf() const;
157 
159 
161  DLLEXPORT const char* getFirstKey() const;
162 
164 
166  DLLEXPORT const char* getLastKey() const;
167 
169 
173  DLLEXPORT AbstractQoreNode* getKeyValueExistence(const char* key, bool &exists);
174 
176 
180  DLLEXPORT const AbstractQoreNode* getKeyValueExistence(const char* key, bool &exists) const;
181 
183 
190  DLLEXPORT AbstractQoreNode* getKeyValueExistence(const QoreString* key, bool &exists, ExceptionSink* xsink);
191 
193 
200  DLLEXPORT const AbstractQoreNode* getKeyValueExistence(const QoreString* key, bool &exists, ExceptionSink* xsink) const;
201 
203 
209  DLLEXPORT AbstractQoreNode* getKeyValue(const QoreString* key, ExceptionSink* xsink);
210 
212 
218  DLLEXPORT AbstractQoreNode* getKeyValue(const QoreString& key, ExceptionSink* xsink);
219 
221 
227  DLLEXPORT const AbstractQoreNode* getKeyValue(const QoreString* key, ExceptionSink* xsink) const;
228 
230 
233  DLLEXPORT AbstractQoreNode* getKeyValue(const char* key);
234 
236 
239  DLLEXPORT const AbstractQoreNode* getKeyValue(const char* key) const;
240 
242 
246  DLLEXPORT int64 getKeyAsBigInt(const char* key, bool &found) const;
247 
249 
253  DLLEXPORT bool getKeyAsBool(const char* key, bool &found) const;
254 
256 
258  DLLEXPORT QoreHashNode* copy() const;
259 
261 
269  DLLEXPORT AbstractQoreNode** getKeyValuePtr(const QoreString* key, ExceptionSink* xsink);
270 
272 
277  DLLEXPORT AbstractQoreNode** getKeyValuePtr(const char* key);
278 
280 
287  DLLEXPORT AbstractQoreNode** getExistingValuePtr(const QoreString* key, ExceptionSink* xsink);
288 
290 
294  DLLEXPORT AbstractQoreNode** getExistingValuePtr(const char* key);
295 
297 
302  DLLEXPORT void merge(const QoreHashNode* h, ExceptionSink* xsink);
303 
305 
311  DLLEXPORT void setKeyValue(const QoreString* key, AbstractQoreNode* value, ExceptionSink* xsink);
312 
314 
320  DLLEXPORT void setKeyValue(const QoreString& key, AbstractQoreNode* value, ExceptionSink* xsink);
321 
323 
329  DLLEXPORT void setKeyValue(const char* key, AbstractQoreNode* value, ExceptionSink* xsink);
330 
332 
339 
341 
346  DLLEXPORT AbstractQoreNode* swapKeyValue(const char* key, AbstractQoreNode* value);
347 
349 
355  DLLEXPORT AbstractQoreNode* swapKeyValue(const char* key, AbstractQoreNode* value, ExceptionSink* xsink);
356 
358 
363  DLLEXPORT void deleteKey(const QoreString* key, ExceptionSink* xsink);
364 
366 
370  DLLEXPORT void deleteKey(const char* key, ExceptionSink* xsink);
371 
373 
377  DLLEXPORT AbstractQoreNode* takeKeyValue(const QoreString* key, ExceptionSink* xsink);
378 
380 
383  DLLEXPORT AbstractQoreNode* takeKeyValue(const char* key);
384 
386 
389  DLLEXPORT QoreListNode* getKeys() const;
390 
392 
395  DLLEXPORT bool compareSoft(const QoreHashNode* h, ExceptionSink* xsink) const;
396 
398 
401  DLLEXPORT bool compareHard(const QoreHashNode* h, ExceptionSink* xsink) const;
402 
404 
406  DLLEXPORT qore_size_t size() const;
407 
409 
411  DLLEXPORT bool empty() const;
412 
414 
418  DLLEXPORT bool existsKey(const char* key) const;
419 
421 
424  DLLEXPORT bool existsKeyValue(const char* key) const;
425 
427 
431  DLLEXPORT void removeKey(const QoreString* key, ExceptionSink* xsink);
432 
434 
438  DLLEXPORT void removeKey(const char* key, ExceptionSink* xsink);
439 
441 
443  DLLLOCAL static const char* getStaticTypeName() {
444  return "hash";
445  }
446 
448  DLLLOCAL static qore_type_t getStaticTypeCode() {
449  return NT_HASH;
450  }
451 
453  DLLLOCAL virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
454 
455  DLLLOCAL QoreHashNode(bool ne);
456  DLLLOCAL void clear(ExceptionSink* xsink);
457 
459  DLLLOCAL void clearNeedsEval();
460 
462  DLLLOCAL void setNeedsEval();
463 
464  DLLLOCAL AbstractQoreNode* evalKeyValue(const QoreString* key, ExceptionSink* xsink) const;
465 
466  // returns a new hash consisting of just the members of value_list
467  DLLLOCAL QoreHashNode* getSlice(const QoreListNode* value_list, ExceptionSink* xsink) const;
468 
469  // "key" is always passed in the default character encoding
470  DLLLOCAL AbstractQoreNode* getReferencedKeyValue(const char* key) const;
471 
472  // "key" is always passed in the default character encoding
473  DLLLOCAL AbstractQoreNode* getReferencedKeyValue(const char* key, bool& exists) const;
474 
475  DLLLOCAL static void doDuplicateKeyWarning(const char* key);
476 };
477 
478 #include <qore/ReferenceHolder.h>
479 
481 
485 
487 
497  friend class HashAssignmentHelper;
498 
499 protected:
500  QoreHashNode* h;
501  HashMember *ptr;
502 
504  DLLLOCAL HashIterator(const HashIterator&);
505 
507  DLLLOCAL HashIterator& operator=(const HashIterator&);
508 
510  DLLLOCAL void* operator new(size_t);
511 
512 public:
514  DLLEXPORT HashIterator(QoreHashNode* h);
515 
517  DLLEXPORT HashIterator(QoreHashNode& h);
518 
520 
523  DLLEXPORT bool next();
524 
526 
529  DLLEXPORT bool prev();
530 
532  DLLEXPORT const char* getKey() const;
533 
535  DLLEXPORT QoreString* getKeyString() const;
536 
538  DLLEXPORT AbstractQoreNode* getValue() const;
539 
542 
544 
548  DLLEXPORT void deleteKey(ExceptionSink* xsink);
549 
551 
554  DLLEXPORT AbstractQoreNode** getValuePtr() const;
555 
557  DLLEXPORT AbstractQoreNode* getReferencedValue() const;
558 
560  DLLEXPORT bool first() const;
561 
563  DLLEXPORT bool last() const;
564 
566  DLLEXPORT bool empty() const;
567 
569  DLLEXPORT bool valid() const;
570 };
571 
573 
583 public:
585  DLLEXPORT ReverseHashIterator(QoreHashNode* h);
586 
588  DLLEXPORT ReverseHashIterator(QoreHashNode& h);
589 
591 
594  DLLEXPORT bool next();
595 
597 
600  DLLEXPORT bool prev();
601 
603  DLLEXPORT bool first() const;
604 
606  DLLEXPORT bool last() const;
607 };
608 
610 
620 protected:
621  const QoreHashNode* h;
622  HashMember *ptr;
623 
625  DLLLOCAL ConstHashIterator(const HashIterator&);
626 
628  DLLLOCAL ConstHashIterator& operator=(const HashIterator&);
629 
631  DLLLOCAL ConstHashIterator(const QoreHashNode* n_h, HashMember* n_ptr);
632 
633 public:
635  DLLEXPORT ConstHashIterator(const QoreHashNode* h);
636 
638  DLLEXPORT ConstHashIterator(const QoreHashNode& h);
639 
641 
644  DLLEXPORT bool next();
645 
647 
650  DLLEXPORT bool prev();
651 
653  DLLEXPORT const char* getKey() const;
654 
656  DLLEXPORT QoreString* getKeyString() const;
657 
659  DLLEXPORT const AbstractQoreNode* getValue() const;
660 
662  DLLEXPORT AbstractQoreNode* getReferencedValue() const;
663 
665  DLLEXPORT bool first() const;
666 
668  DLLEXPORT bool last() const;
669 
671  DLLEXPORT bool empty() const;
672 
674  DLLEXPORT bool valid() const;
675 
677  DLLEXPORT void reset();
678 };
679 
681 
691 public:
693  DLLEXPORT ReverseConstHashIterator(const QoreHashNode* h);
694 
696  DLLEXPORT ReverseConstHashIterator(const QoreHashNode& h);
697 
699 
702  DLLEXPORT bool next();
703 
705 
708  DLLEXPORT bool prev();
709 
711  DLLEXPORT bool first() const;
712 
714  DLLEXPORT bool last() const;
715 };
716 
719 private:
722 
724  DLLLOCAL HashAssignmentHelper& operator=(const HashAssignmentHelper&);
725 
727  DLLLOCAL void* operator new(size_t);
728 
729 protected:
731  class hash_assignment_priv *priv;
732 
733 public:
735 
739  DLLLOCAL HashAssignmentHelper(QoreHashNode& n_h, const char* key, bool must_already_exist = false);
740 
742 
746  DLLLOCAL HashAssignmentHelper(QoreHashNode& n_h, const std::string& key, bool must_already_exist = false);
747 
749 
756  DLLLOCAL HashAssignmentHelper(ExceptionSink* xsink, QoreHashNode& n_h, const QoreString& key, bool must_already_exist = false);
757 
759 
766  DLLLOCAL HashAssignmentHelper(ExceptionSink* xsink, QoreHashNode& n_h, const QoreString* key, bool must_already_exist = false);
767 
769 
771  DLLLOCAL HashAssignmentHelper(HashIterator &hi);
772 
774  DLLLOCAL ~HashAssignmentHelper();
775 
777 
779  DLLLOCAL operator bool() const;
780 
782 
786  DLLLOCAL void assign(AbstractQoreNode* v, ExceptionSink* xsink);
787 
789 
792  DLLLOCAL AbstractQoreNode* swap(AbstractQoreNode* v, ExceptionSink* xsink);
793 
795 
797  DLLLOCAL AbstractQoreNode* operator*() const;
798 };
799 
800 #endif // _QORE_HASH_H