All Classes Namespaces Functions Variables Groups Pages
<hash> Class Reference

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

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

## Public Member Functions

bool | compareKeys (hash oh)
| Returns True if the hash argument passed has the same keys in the same order as the current hash, 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...
any | 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 | keys ()
| 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...
any | 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 | values ()
| Returns a list of values of the hash. More...
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) More...
bool | empty ()
| Returns True; this method will be reimplemented in container types where it may return False. 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 value that would be converted to True according to the rules described in %perl-bool-eval. More...

## Detailed Description

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

## Member Function Documentation

bool <hash>::compareKeys | ( | hash | 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

HashListIterator <hash>::contextIterator | ( |  | ) |

Returns a HashListIterator object for the hash.

Returns
  a HashListIterator object for the hash

Code Flags:
  CONSTANT

Example:
  *hash 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

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

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

any <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:
  any 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()

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)

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)

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

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

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

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

any <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:
  any 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()

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

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

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

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

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

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

Returns a list of values of the hash.

Returns
  a list of values of the hash

Code Flags:
  CONSTANT

Example:
  list 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)

See Also
  <hash>::keys()