32 #ifndef _QORE_QOREHASHNODE_H 34 #define _QORE_QOREHASHNODE_H 36 #include <qore/AbstractQoreNode.h> 56 friend class hash_assignment_priv;
57 friend class qore_object_private;
58 friend class qore_hash_private;
65 DLLLOCAL QoreHashNode& operator=(
const QoreHashNode&);
69 class qore_hash_private *
priv;
122 DLLEXPORT
QoreHashNode(
const QoreTypeInfo* valueTypeInfo);
351 DLLEXPORT
bool getKeyAsBool(
const char* key,
bool &found)
const;
356 DLLEXPORT QoreHashNode*
copy()
const;
552 DLLEXPORT
bool empty()
const;
559 DLLEXPORT
bool existsKey(
const char* key)
const;
614 DLLLOCAL
void clear(
ExceptionSink* xsink,
bool reverse =
false);
628 #include <qore/ReferenceHolder.h> 650 friend class qhi_priv;
660 DLLLOCAL HashIterator& operator=(
const HashIterator&);
663 DLLLOCAL
void*
operator new(size_t);
673 DLLEXPORT ~HashIterator();
679 DLLEXPORT
bool next();
685 DLLEXPORT
bool prev();
688 DLLEXPORT
const char* getKey()
const;
719 DLLEXPORT
bool first()
const;
722 DLLEXPORT
bool last()
const;
725 DLLEXPORT
bool empty()
const;
728 DLLEXPORT
bool valid()
const;
750 DLLEXPORT ~ReverseHashIterator();
756 DLLEXPORT
bool next();
762 DLLEXPORT
bool prev();
765 DLLEXPORT
bool first()
const;
768 DLLEXPORT
bool last()
const;
797 DLLLOCAL ConstHashIterator(
const ConstHashIterator&);
800 DLLEXPORT ~ConstHashIterator();
806 DLLEXPORT
bool next();
812 DLLEXPORT
bool prev();
815 DLLEXPORT
const char* getKey()
const;
830 DLLEXPORT
bool first()
const;
833 DLLEXPORT
bool last()
const;
836 DLLEXPORT
bool empty()
const;
839 DLLEXPORT
bool valid()
const;
842 DLLEXPORT
void reset();
861 DLLEXPORT ReverseConstHashIterator(
const QoreHashNode& h);
864 DLLEXPORT ~ReverseConstHashIterator();
870 DLLEXPORT
bool next();
876 DLLEXPORT
bool prev();
879 DLLEXPORT
bool first()
const;
882 DLLEXPORT
bool last()
const;
887 friend class hash_assignment_priv;
901 DLLEXPORT HashAssignmentHelper(
QoreHashNode& n_h,
const std::string& key,
bool must_already_exist =
false);
929 DLLEXPORT ~HashAssignmentHelper();
937 DLLEXPORT
void reassign(
const char* key,
bool must_already_exist =
false);
945 DLLEXPORT
void reassign(
const std::string& key,
bool must_already_exist =
false);
950 DLLEXPORT
operator bool()
const;
972 class hash_assignment_priv *
priv;
975 DLLLOCAL HashAssignmentHelper(
const HashAssignmentHelper&) =
delete;
976 DLLLOCAL HashAssignmentHelper& operator=(
const HashAssignmentHelper&) =
delete;
977 DLLLOCAL
void*
operator new(size_t) =
delete;
980 #endif // _QORE_HASH_H 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...
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
dereferences all elements of the hash
DLLEXPORT int64 getKeyAsBigInt(const char *key, bool &found) const
returns the value of the key as an int64
DLLEXPORT QoreValue getValueKeyValueExistence(const char *key, bool &exists, ExceptionSink *xsink) const
returns the value of the given key
virtual DLLLOCAL int64 bigIntEvalImpl(ExceptionSink *xsink) const
always returns 0
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
use this class to make assignments to hash keys from a pointer to the key value
Definition: QoreHashNode.h:886
DLLEXPORT QoreListNode * getValues() const
returns a QoreListNode of AbstractQoreNode pointers representing all values in the hash; caller owns ...
DLLEXPORT bool getKeyAsBool(const char *key, bool &found) const
returns the value of the key as a bool
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 void setKeyValue(const QoreString *key, AbstractQoreNode *value, ExceptionSink *xsink)
sets the value of "key" to "value"
reverse iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:741
virtual DLLEXPORT ~QoreHashNode()
deletes the object, cannot be called directly (use deref(ExceptionSink*) instead) ...
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...
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 ...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
DLLEXPORT void merge(const QoreHashNode *h, ExceptionSink *xsink)
appends all key-value pairs of "h" to this hash
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreHashNode.h:604
DLLEXPORT const char * getFirstKey() const
returns the cstring value of the first key in the hash
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...
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:74
DLLEXPORT QoreHashNode * hashRefSelf() const
returns "this" with an incremented reference count
virtual DLLEXPORT AbstractQoreNode * evalImpl(ExceptionSink *xsink) const
evaluates the object and returns a value (or 0)
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...
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...
class qore_hash_private * priv
private implementation of the class
Definition: QoreHashNode.h:69
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
DLLEXPORT const QoreTypeInfo * getValueTypeInfo() const
returns the value type declaration (only possible if there is no hashdecl set)
DLLEXPORT const TypedHashDecl * getHashDecl() const
returns the hash's type declaration, if any
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns the type info structure for the current value; also works for hashes derived from a TypedHash...
virtual DLLEXPORT AbstractQoreNode * realCopy() const
performs a copy of the hash and returns the new hash
const qore_type_t NT_HASH
type value for QoreHashNode
Definition: node_types.h:51
virtual DLLLOCAL double floatEvalImpl(ExceptionSink *xsink) const
always returns 0.0
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) ...
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
virtual DLLLOCAL int integerEvalImpl(ExceptionSink *xsink) const
always returns 0
DLLLOCAL void clearNeedsEval()
sets "needs_eval" to false and "value" to true
DLLEXPORT bool empty() const
returns true if the hash has no members, false if not
DLLEXPORT AbstractQoreNode * getKeyValue(const QoreString *key, ExceptionSink *xsink)
returns the value of the key if it exists
DLLEXPORT int setValueKeyValue(const char *key, QoreValue value, ExceptionSink *xsink)
sets the value of "key" to "value"
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
DLLEXPORT void removeKey(const QoreString *key, ExceptionSink *xsink)
removes the given key from the hash and derefences its value, if any
reverse constant iterator class for QoreHashNode, to be only created on the stack ...
Definition: QoreHashNode.h:855
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreHashNode.h:599
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:241
DLLEXPORT void deleteKey(const QoreString *key, ExceptionSink *xsink)
performs a delete operation on the value of the given key
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
typed hash declaration
Definition: TypedHashDecl.h:42
DLLEXPORT QoreListNode * getKeys() const
returns a QoreListNode of QoreStringNode pointers representing all keys in the hash, caller owns the reference count returned
DLLLOCAL void setNeedsEval()
sets "needs_eval" to true and "value" to false
DLLEXPORT QoreHashNode * copy() const
performs a copy of the hash and returns the new hash
DLLEXPORT qore_size_t size() const
returns the number of members in the hash, executes in constant time
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:71
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:159
constant iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:781
class hash_assignment_priv * priv
private implementation
Definition: QoreHashNode.h:972
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)...
virtual DLLLOCAL bool boolEvalImpl(ExceptionSink *xsink) const
always returns false
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
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 bool existsKey(const char *key) const
returns true if the hash contains the given key
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
initializes during parsing
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:51
DLLEXPORT QoreValue getValueKeyValue(const char *key, ExceptionSink *xsink) const
returns the value of the given key
iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:648