24 #ifndef _QORE_QOREHASHNODE_H
26 #define _QORE_QOREHASHNODE_H
28 #include <qore/AbstractQoreNode.h>
47 friend class hash_assignment_priv;
48 friend class qore_object_private;
49 friend class qore_hash_private;
56 DLLLOCAL QoreHashNode& operator=(
const QoreHashNode&);
60 class qore_hash_private *
priv;
246 DLLEXPORT int64
getKeyAsBigInt(
const char* key,
bool &found)
const;
253 DLLEXPORT
bool getKeyAsBool(
const char* key,
bool &found)
const;
258 DLLEXPORT QoreHashNode*
copy()
const;
411 DLLEXPORT
bool empty()
const;
418 DLLEXPORT
bool existsKey(
const char* key)
const;
473 DLLLOCAL
AbstractQoreNode* getReferencedKeyValue(
const char* key,
bool& exists)
const;
475 DLLLOCAL
static void doDuplicateKeyWarning(
const char* key);
478 #include <qore/ReferenceHolder.h>
509 DLLLOCAL HashIterator&
operator=(
const HashIterator&);
512 DLLLOCAL
void*
operator new(size_t);
528 DLLEXPORT
bool next();
534 DLLEXPORT
bool prev();
537 DLLEXPORT
const char*
getKey()
const;
565 DLLEXPORT
bool first()
const;
568 DLLEXPORT
bool last()
const;
571 DLLEXPORT
bool empty()
const;
574 DLLEXPORT
bool valid()
const;
602 DLLEXPORT
bool next();
608 DLLEXPORT
bool prev();
611 DLLEXPORT
bool first()
const;
614 DLLEXPORT
bool last()
const;
652 DLLEXPORT
bool next();
658 DLLEXPORT
bool prev();
661 DLLEXPORT
const char*
getKey()
const;
673 DLLEXPORT
bool first()
const;
676 DLLEXPORT
bool last()
const;
679 DLLEXPORT
bool empty()
const;
682 DLLEXPORT
bool valid()
const;
685 DLLEXPORT
void reset();
713 DLLEXPORT
bool next();
719 DLLEXPORT
bool prev();
722 DLLEXPORT
bool first()
const;
725 DLLEXPORT
bool last()
const;
735 DLLLOCAL HashAssignmentHelper& operator=(
const HashAssignmentHelper&);
738 DLLLOCAL
void*
operator new(size_t);
742 class hash_assignment_priv *
priv;
750 DLLLOCAL HashAssignmentHelper(
QoreHashNode& n_h,
const char* key,
bool must_already_exist =
false);
757 DLLLOCAL HashAssignmentHelper(
QoreHashNode& n_h,
const std::string& key,
bool must_already_exist =
false);
790 DLLLOCAL
operator bool()
const;
811 #endif // _QORE_HASH_H
DLLEXPORT bool empty() const
returns true if the hash is empty
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
dereferences all elements of the hash
DLLEXPORT ~HashIterator()
Destroys the iterator.
DLLEXPORT bool compareHard(const QoreHashNode *h, ExceptionSink *xsink) const
does a deep "hard" compare of all hash elements (no type conversions are performed) and returns true ...
DLLEXPORT bool prev()
moves to the previous element, returns false when there are no more elements to iterate ...
DLLEXPORT QoreListNode * getKeys() const
returns a QoreListNode of QoreStringNodes representing all keys in the hash, caller owns the referenc...
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:41
use this class to make assignments to hash keys from a pointer to the key value
Definition: QoreHashNode.h:729
DLLEXPORT AbstractQoreNode * getValue() const
returns the value of the current key
DLLEXPORT ReverseConstHashIterator(const QoreHashNode *h)
initializes the iterator with the passed hash
DLLEXPORT bool compareSoft(const QoreHashNode *h, ExceptionSink *xsink) const
does a deep "soft" compare of all hash elements (types may be converted for the comparison) and retur...
DLLLOCAL void assign(AbstractQoreNode *v, ExceptionSink *xsink)
assigns a value to the hash key, dereferences any old value, assumes that the value is already refere...
DLLEXPORT AbstractQoreNode ** getKeyValuePtr(const QoreString *key, ExceptionSink *xsink)
returns a pointer to a pointer of the value of the key so the value may be set or changed externally ...
DLLEXPORT AbstractQoreNode * takeValueAndDelete()
deletes the key from the hash and returns the value, caller owns the reference
DLLEXPORT void setKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink)
sets the value of "key" to "value"
DLLEXPORT bool next()
moves to the next element in reverse order, returns false when there are no more elements to iterate ...
reverse iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:587
virtual DLLEXPORT ~QoreHashNode()
deletes the object, cannot be called directly (use deref(ExceptionSink*) instead) ...
DLLEXPORT bool next()
moves to the next element, returns false when there are no more elements to iterate ...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
DLLEXPORT void merge(const QoreHashNode *h, ExceptionSink *xsink)
appends all key-value pairs of "h" to this hash
DLLEXPORT void deleteKey(ExceptionSink *xsink)
deletes the key from the hash and dereferences the value
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreHashNode.h:448
DLLEXPORT bool valid() const
returns true if the iterator is currently pointing at a valid element
DLLEXPORT AbstractQoreNode * getKeyValueExistence(const char *key, bool &exists)
returns the value of the key (assumed to be in QCS_DEFAULT) if it exists and sets "exists" accordingl...
DLLEXPORT ConstHashIterator(const QoreHashNode *h)
initializes the iterator with the passed hash
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:62
DLLEXPORT int64 getKeyAsBigInt(const char *key, bool &found) const
returns the value of the key as an int64
virtual DLLEXPORT int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const
concatenate the verbose string representation of the list (including all contained values) to an exis...
DLLEXPORT bool first() const
returns true if on the first key of the hash
DLLEXPORT bool last() const
returns true if on the last key of the hash
DLLEXPORT bool first() const
returns true if on the last key of the hash
DLLEXPORT AbstractQoreNode * takeKeyValue(const QoreString *key, ExceptionSink *xsink)
"takes" the value of the key from the hash and removes the key from the hash and returns the value...
DLLEXPORT const AbstractQoreNode * getValue() const
returns the value of the current key
DLLEXPORT ~ConstHashIterator()
Destroys the iterator.
class qore_hash_private * priv
private implementation of the class
Definition: QoreHashNode.h:60
virtual DLLEXPORT AbstractQoreNode * evalImpl(ExceptionSink *xsink) const
evaluates the object and returns a value (or 0)
DLLEXPORT void reset()
resets the iterator to its initial state
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:59
DLLEXPORT bool next()
moves to the next element in reverse order, returns false when there are no more elements to iterate ...
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:42
DLLEXPORT const char * getLastKey() const
returns the cstring value of the last key in the hash
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
DLLEXPORT QoreHashNode * hashRefSelf() const
returns "this" with an incremented reference count
DLLEXPORT bool prev()
moves to the previous element in reverse order, returns false when there are no more elements to iter...
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:44
virtual DLLLOCAL int64 bigIntEvalImpl(ExceptionSink *xsink) const
always returns 0
DLLEXPORT bool empty() const
returns true if the hash is empty
DLLLOCAL AbstractQoreNode * swap(AbstractQoreNode *v, ExceptionSink *xsink)
swaps the current value with the new value of the hash key, assumes that the new value is already ref...
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
DLLEXPORT AbstractQoreNode ** getValuePtr() const
returns a pointer to a pointer to the current value so the value of the key may be manipulated extern...
DLLLOCAL AbstractQoreNode * operator*() const
returns the current value of the hash key; the pointer returned is still owned by the hash ...
DLLEXPORT bool prev()
moves to the previous element, returns false when there are no more elements to iterate ...
virtual DLLEXPORT AbstractQoreNode * realCopy() const
performs a copy of the hash and returns the new hash
DLLEXPORT const char * getFirstKey() const
returns the cstring value of the first key in the hash
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values) with possible type conversion (sof...
const qore_type_t NT_HASH
type value for QoreHashNode
Definition: node_types.h:43
DLLEXPORT AbstractQoreNode * getReferencedValue() const
returns the value of the current key with an incremented reference count
DLLEXPORT bool last() const
returns true if on the last key of the hash
DLLEXPORT bool last() const
returns true if on the first key of the hash
DLLLOCAL ~HashAssignmentHelper()
destroys the object and does post processing on the new value
DLLLOCAL HashIterator(const HashIterator &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
virtual DLLLOCAL bool boolEvalImpl(ExceptionSink *xsink) const
always returns false
DLLLOCAL void clearNeedsEval()
sets "needs_eval" to false and "value" to true
DLLEXPORT bool prev()
moves to the previous element in reverse order, returns false when there are no more elements to iter...
DLLEXPORT AbstractQoreNode * getKeyValue(const QoreString *key, ExceptionSink *xsink)
returns the value of the key if it exists
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
DLLEXPORT void removeKey(const QoreString *key, ExceptionSink *xsink)
removes the given key from the hash and derefences its value, if any
DLLLOCAL HashIterator & operator=(const HashIterator &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
DLLEXPORT bool last() const
returns true if on the first key of the hash
DLLEXPORT bool existsKeyValue(const char *key) const
returns true if the hash contains the given key and the key has a value (i.e. is not NOTHING) ...
reverse constant iterator class for QoreHashNode, to be only created on the stack ...
Definition: QoreHashNode.h:698
virtual DLLLOCAL int integerEvalImpl(ExceptionSink *xsink) const
always returns 0
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreHashNode.h:443
DLLEXPORT bool empty() const
returns true if the hash has no members, false if not
DLLEXPORT void deleteKey(const QoreString *key, ExceptionSink *xsink)
performs a delete operation on the value of the given key
DLLEXPORT bool valid() const
returns true if the iterator is currently pointing at a valid element
DLLEXPORT qore_size_t size() const
returns the number of members in the hash, executes in constant time
virtual DLLLOCAL double floatEvalImpl(ExceptionSink *xsink) const
always returns 0.0
DLLEXPORT const char * getKey() const
returns the current key
DLLLOCAL ConstHashIterator & operator=(const HashIterator &)
this function is not implemented; it is here as a protected function in order to prohibit it from bei...
DLLLOCAL void setNeedsEval()
sets "needs_eval" to true and "value" to false
DLLEXPORT bool getKeyAsBool(const char *key, bool &found) const
returns the value of the key as a bool
bool value
this is true for values, if false then either the type needs evaluation to produce a value or is a pa...
Definition: AbstractQoreNode.h:152
constant iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:627
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values) without type conversions (hard com...
DLLEXPORT ~ReverseConstHashIterator()
Destroys the iterator.
class hash_assignment_priv * priv
private implementation
Definition: QoreHashNode.h:742
DLLEXPORT QoreString * getKeyString() const
returns a QoreString for the current key, the caller owns QoreString returned
DLLEXPORT AbstractQoreNode * swapKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink)
sets the value of "key" to "value" and returns the old value (0 if not present or if already 0)...
DLLEXPORT AbstractQoreNode ** getExistingValuePtr(const QoreString *key, ExceptionSink *xsink)
returns a pointer to a pointer of the value of the key only if the key already exists ...
DLLEXPORT QoreHashNode()
creates an empty hash
DLLEXPORT QoreHashNode * copy() const
performs a copy of the hash and returns the new hash
DLLEXPORT QoreString * getKeyString() const
returns a QoreString for the current key, the caller owns QoreString returned
DLLEXPORT ReverseHashIterator(QoreHashNode *h)
initializes the iterator with the passed hash
DLLEXPORT bool first() const
returns true if on the last key of the hash
DLLEXPORT bool first() const
returns true if on the first key of the hash
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
initializes during parsing
DLLEXPORT ~ReverseHashIterator()
Destroys the iterator.
DLLEXPORT const char * getKey() const
returns the current key
DLLEXPORT bool next()
moves to the next element, returns false when there are no more elements to iterate ...
DLLEXPORT bool existsKey(const char *key) const
returns true if the hash contains the given key
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:43
DLLEXPORT AbstractQoreNode * getReferencedValue() const
returns the value of the current key with an incremented reference count
iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:498