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 Functions

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.
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
HashListIterator | contextIterator ()
| Returns a HashListIterator object for the hash.
bool | empty ()
| Returns True if the hash has no keys, False if it does.
*string | firstKey ()
| Returns the first key name in the hash or NOTHING if the hash has no keys.
auto | firstValue ()
| Returns the value assigned to the first key in the hash if any or NOTHING if the hash has no keys.
bool | hasKey (softstring key)
| Returns True if the key exists in the hash (may or may not be assigned a value), False if not.
bool | hasKeyValue (softstring key)
| Returns True if the key exists and is assigned to a value, False if not.
AbstractIterator | iterator ()
| Returns a HashIterator object for the hash.
HashKeyIterator | keyIterator ()
| Returns a HashKeyIterator object for the hash.
list< string > | keys ()
| Returns a list of key names of the hash.
*string | lastKey ()
| Returns the last key name in the hash or NOTHING if the hash has no keys.
auto | lastValue ()
| Returns the value assigned to the last key in the hash if any or NOTHING if the hash has no keys.
HashPairIterator | pairIterator ()
| Returns a HashPairIterator object for the hash.
int | size ()
| Returns the number of keys in the hash.
bool | sizep ()
| Returns True since hashes can return a non-zero size.
int | typeCode ()
| Returns Qore::NT_HASH.
bool | val ()
| Returns False if the hash has no keys, True if it does.
list< auto > | values ()
| Returns a list of values of the hash.
Public Member Functions 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)
bool | complexType ()
| returns True if the value has a complex type, False if not
bool | empty ()
| Returns True; this method will be reimplemented in container types where it may return False.
string | fullType (*bool with_namespaces)
| returns the full type name which differs from the simple type name in case of complex types and objects
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.
AbstractIterator | iterator ()
| Returns an iterator object for the value; the default iterator object returned is SingleValueIterator.
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.
int | size ()
| Returns zero; this method will be reimplemented in container types where it may return a non-zero value.
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)
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.
bool | toBool ()
| Returns the boolean representation of the value; the default is False.
float | toFloat ()
| Returns the floating-point representation of the value; the default is 0.0.
int | toInt ()
| Returns the integer representation of the value; the default is 0.
number | toNumber ()
| Returns the arbitrary-precision numeric representation of the value; the default is 0.
string | toString (*string encoding)
| Returns the string representation of the value; the default is an empty string.
string | type ()
| Returns the string type for the value.
int | typeCode ()
| Returns the type code for the value.
bool | val ()
| Returns False; this method is reimplemented in other types and will return True if the given expression has a non-empty value.

## 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

  oh | a 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
  - <value>::fullType()

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
  - a hash with non-list values will be iterated as if each key value were a single element list
  - 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 iterating query results from Datasource::select() or DatasourcePool::select() with the map operator, for example

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

  key | the 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

  key | the 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
  - %perl-bool-eval
  - %strict-bool-eval

## 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()