Qore Programming Language Reference Manual 1.14.0
Loading...
Searching...
No Matches
<hash> Class Reference

Methods in this pseudo-class can be executed on hash values. More...

#include <Pseudo_QC_Hash.dox.h>

Inheritance diagram for Qore::<hash>:
[legend]

Public Member Methods

bool compareKeys (hash< auto > oh)
 Returns True if the hash argument passed has the same keys in the same order as the current hash, False if not. More...
 
bool complexType ()
 returns True if the hash has a complex type (Hashdecl: Type-Safe Hash Declarations or Hash With Declared Value Type), False if not More...
 
HashListIterator contextIterator ()
 Returns a HashListIterator object for the hash. More...
 
bool empty ()
 Returns True if the hash has no keys, False if it does. More...
 
*string firstKey ()
 Returns the first key name in the hash or NOTHING if the hash has no keys. More...
 
auto firstValue ()
 Returns the value assigned to the first key in the hash if any or NOTHING if the hash has no keys. More...
 
bool hasKey (softstring key)
 Returns True if the key exists in the hash (may or may not be assigned a value), False if not. More...
 
bool hasKeyValue (softstring key)
 Returns True if the key exists and is assigned to a value, False if not. More...
 
AbstractIterator iterator ()
 Returns a HashIterator object for the hash. More...
 
HashKeyIterator keyIterator ()
 Returns a HashKeyIterator object for the hash. More...
 
list< stringkeys ()
 Returns a list of key names of the hash. More...
 
*string lastKey ()
 Returns the last key name in the hash or NOTHING if the hash has no keys. More...
 
auto lastValue ()
 Returns the value assigned to the last key in the hash if any or NOTHING if the hash has no keys. More...
 
HashPairIterator pairIterator ()
 Returns a HashPairIterator object for the hash. More...
 
int size ()
 Returns the number of keys in the hash. More...
 
bool sizep ()
 Returns True since hashes can return a non-zero size. More...
 
int typeCode ()
 Returns Qore::NT_HASH. More...
 
bool val ()
 Returns False if the hash has no keys, True if it does. More...
 
list< auto > values ()
 Returns a list of values of the hash. More...
 
- Public Member Methods inherited from <value>
bool callp ()
 Returns False; this method is reimplemented in other types and will return True if the given expression is a callable value (ie closures or call references) More...
 
bool complexType ()
 returns True if the value has a complex type, False if not More...
 
bool empty ()
 Returns True; this method will be reimplemented in container types where it may return False. More...
 
string fullType (*bool with_namespaces)
 returns the full type name which differs from the simple type name in case of complex types and objects More...
 
bool intp ()
 Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to an integer. More...
 
AbstractIterator iterator ()
 Returns an iterator object for the value; the default iterator object returned is SingleValueIterator. More...
 
int lsize ()
 Returns 1; the return value of this method should give the list size of the value, which is normally 1 for non-lists (except for NOTHING where the size will be 0) and the number of the elements in the list for lists; this method will be reimplemented in other types where it may return other values. More...
 
int size ()
 Returns zero; this method will be reimplemented in container types where it may return a non-zero value. More...
 
bool sizep ()
 Returns True if the type can return a non-zero size (True for containers including binary objects and strings, False for everything else) More...
 
bool strp ()
 Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to a string. More...
 
bool toBool ()
 Returns the boolean representation of the value; the default is False. More...
 
float toFloat ()
 Returns the floating-point representation of the value; the default is 0.0. More...
 
int toInt ()
 Returns the integer representation of the value; the default is 0. More...
 
number toNumber ()
 Returns the arbitrary-precision numeric representation of the value; the default is 0. More...
 
string toString ()
 Returns the string representation of the value; the default is an empty string. More...
 
string type ()
 Returns the string type for the value. More...
 
int typeCode ()
 Returns the type code for the value. More...
 
bool val ()
 Returns False; this method is reimplemented in other types and will return True if the given expression has a non-empty value. More...
 

Detailed Description

Methods in this pseudo-class can be executed on hash values.

Member Function Documentation

◆ compareKeys()

bool <hash>::compareKeys ( hash< auto >  oh)

Returns True if the hash argument passed has the same keys in the same order as the current hash, False if not.

Code Flags:
CONSTANT
Example:
bool b = h.compareKeys(oh);

Values are not compraed, only the key names and order

Parameters
oha hash to compare the keys against
Returns
True if the hash argument passed has the same keys in the same order as the current hash, False if not
Since
Qore 0.8.8

◆ complexType()

bool <hash>::complexType ( )

returns True if the hash has a complex type (Hashdecl: Type-Safe Hash Declarations or Hash With Declared Value Type), False if not

Code Flags:
CONSTANT
Example:
bool b = n.complexType();
Returns
True if the hash has a complex type (Hashdecl: Type-Safe Hash Declarations or Hash With Declared Value Type), False if not
See also
Since
Qore 0.8.13

◆ contextIterator()

HashListIterator <hash>::contextIterator ( )

Returns a HashListIterator object for the hash.

Returns
a HashListIterator object for the hash
Code Flags:
CONSTANT
Example:
*hash<auto> q = db.select("select * from table_name");
map printf("+ %s\n", $1), h.contextIterator();
Note
Since
Qore 0.8.6.2

◆ empty()

bool <hash>::empty ( )

Returns True if the hash has no keys, False if it does.

Returns
True if the hash has no keys, False if it does
Code Flags:
CONSTANT
Example:
bool b = h.empty();
Note
this pseudo-method is also implemented in <value>, so it's safe to use on all data types

◆ firstKey()

*string <hash>::firstKey ( )

Returns the first key name in the hash or NOTHING if the hash has no keys.

Returns
the first key name in the hash or NOTHING if the hash has no keys
Code Flags:
CONSTANT
Example:
*string n = h.firstKey();
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
See also
<hash>::lastKey()

◆ firstValue()

auto <hash>::firstValue ( )

Returns the value assigned to the first key in the hash if any or NOTHING if the hash has no keys.

Returns
the value assigned to the first key in the hash if any or NOTHING if the hash has no keys
Code Flags:
CONSTANT
Example:
auto v = h.firstValue();
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
See also
<hash>::lastValue()

◆ hasKey()

bool <hash>::hasKey ( softstring  key)

Returns True if the key exists in the hash (may or may not be assigned a value), False if not.

Code Flags:
RET_VALUE_ONLY
Parameters
keythe key name to check
Returns
True if the key exists in the hash (may or may not be assigned a value), False if not
Example:
bool b = h.hasKey(key);
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
See also
<hash>::hasKeyValue(softstring)

◆ hasKeyValue()

bool <hash>::hasKeyValue ( softstring  key)

Returns True if the key exists and is assigned to a value, False if not.

Code Flags:
RET_VALUE_ONLY
Parameters
keythe key name to check
Returns
True if the key exists and is assigned to a value, False if not
Example:
bool b = h.hasKeyValue(key);
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
See also
<hash>::hasKey(softstring)

◆ iterator()

AbstractIterator <hash>::iterator ( )

Returns a HashIterator object for the hash.

Returns
a HashIterator object for the hash
Code Flags:
CONSTANT
Example:
map printf("value: %y\n", $1), h.iterator();
Note
this pseudo-method is also implemented in <value>, so it's safe to use on all data types
Since
Qore 0.8.6

◆ keyIterator()

HashKeyIterator <hash>::keyIterator ( )

Returns a HashKeyIterator object for the hash.

Returns
a HashKeyIterator object for the hash
Code Flags:
CONSTANT
Example:
map printf("key: %s\n", $1), h.keyIterator();
Note
  • this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
  • this pseudo-method is very useful when using a hash as a simulation for a set of strings and quickly iterating the hash with the map operator, for example
Since
Qore 0.8.6.2

◆ keys()

list< string > <hash>::keys ( )

Returns a list of key names of the hash.

Returns
a list of key names of the hash
Code Flags:
CONSTANT
Example:
list<string> l = h.keys();
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
See also
<hash>::values()

◆ lastKey()

*string <hash>::lastKey ( )

Returns the last key name in the hash or NOTHING if the hash has no keys.

Returns
the last key name in the hash or NOTHING if the hash has no keys
Code Flags:
CONSTANT
Example:
*string n = h.lastKey();
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
See also
<hash>::firstKey()

◆ lastValue()

auto <hash>::lastValue ( )

Returns the value assigned to the last key in the hash if any or NOTHING if the hash has no keys.

Returns
the value assigned to the last key in the hash if any or NOTHING if the hash has no keys
Code Flags:
CONSTANT
Example:
auto v = h.lastValue();
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
See also
<hash>::firstValue()

◆ pairIterator()

HashPairIterator <hash>::pairIterator ( )

Returns a HashPairIterator object for the hash.

Returns
a HashPairIterator object for the hash
Code Flags:
CONSTANT
Example:
map printf("%s: %y\n", $1.key, $1.value), h.pairIterator());
Note
this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
Since
Qore 0.8.6.2

◆ size()

int <hash>::size ( )

Returns the number of keys in the hash.

The opposite of <hash>::val()

Returns
the number of keys in the hash
Code Flags:
CONSTANT
Example:
int num = h.size();
Note
this pseudo-method is also implemented in <value>, so it's safe to use on all data types
See also
<hash>::sizep()

◆ sizep()

bool <hash>::sizep ( )

Returns True since hashes can return a non-zero size.

Code Flags:
CONSTANT
Returns
True since hashes can return a non-zero size
See also
<hash>::size()
Since
Qore 0.8.9

◆ typeCode()

int <hash>::typeCode ( )

Returns Qore::NT_HASH.

Returns
Qore::NT_HASH
Code Flags:
CONSTANT
Example:
switch (h.typeCode()) {
case NT_HASH:
printf("%y: is a hash\n", h);
break;
}
Note
this pseudo-method is also implemented in <value>, so it's safe to use on all data types

◆ val()

bool <hash>::val ( )

Returns False if the hash has no keys, True if it does.

The opposite of <hash>::empty()

Returns
False if the hash has no keys, True if it does
Code Flags:
CONSTANT
Example:
bool b = h.val();
Note
this pseudo-method is also implemented in <value>, so it's safe to use on all data types
See also

◆ values()

list< auto > <hash>::values ( )

Returns a list of values of the hash.

Returns
a list of values of the hash
Code Flags:
CONSTANT
Example:
list<auto> l = h.values();
Note
  • equivalent to hash_values()
  • this pseudo-method is also implemented in <nothing>, so it's safe to use where the value could be a hash or NOTHING (ex: *hash)
  • a hash with a declared value type will have a plain untyped list returned; this will be fixed in a future version of Qore
See also
<hash>::keys()