Qore Programming Language 1.19.5
Loading...
Searching...
No Matches
HashIterator Class Reference

iterator class for QoreHashNode, to be only created on the stack More...

#include <QoreHashNode.h>

Inheritance diagram for HashIterator:
[legend]
Collaboration diagram for HashIterator:
[legend]

Public Member Methods

DLLEXPORT HashIterator (QoreHashNode &h)
 initializes the iterator with the passed hash
 
DLLEXPORT HashIterator (QoreHashNode *h)
 initializes the iterator with the passed hash
 
DLLEXPORT ~HashIterator ()
 Destroys the iterator.
 
DLLEXPORT int assign (QoreValue val, ExceptionSink *xsink)
 Assigns the given value to the key and dereferences any current value. More...
 
DLLEXPORT void deleteKey (ExceptionSink *xsink)
 deletes the key from the hash and dereferences the value More...
 
DLLEXPORT bool empty () const
 returns true if the hash is empty
 
DLLEXPORT bool first () const
 returns true if on the first key of the hash
 
DLLEXPORT QoreValue get () const
 returns the value of the current key
 
DLLEXPORT QoreHashNodegetHash () const
 returns the hash
 
DLLEXPORT const char * getKey () const
 returns the current key
 
DLLEXPORT QoreStringgetKeyString () const
 returns a QoreString for the current key, the caller owns QoreString returned
 
DLLEXPORT QoreValue getReferenced () const
 returns the value of the current key with an incremented reference count
 
DLLEXPORT const QoreTypeInfo * getTypeInfo () const
 returns the type info for the current value
 
DLLEXPORT bool last () const
 returns true if on the last key of the hash
 
DLLEXPORT bool next ()
 moves to the next element, returns false when there are no more elements to iterate More...
 
DLLEXPORT bool prev ()
 moves to the previous element, returns false when there are no more elements to iterate More...
 
DLLEXPORT QoreValue removeKeyValue ()
 removes the key value and returns the value returned
 
DLLEXPORT bool valid () const
 returns true if the iterator is currently pointing at a valid element
 

Private Member Methods

DLLLOCAL HashIterator (const HashIterator &)
 this function is not implemented; it is here as a private function in order to prohibit it from being used
 
DLLLOCAL void * operator new (size_t)
 this function is not implemented; it is here as a private function in order to prohibit it from being used
 
DLLLOCAL HashIteratoroperator= (const HashIterator &)
 this function is not implemented; it is here as a private function in order to prohibit it from being used
 

Friends

class HashAssignmentHelper
 

Detailed Description

iterator class for QoreHashNode, to be only created on the stack

while (hi.next()) {
QoreStringValueHelper str(hi.get());
printf("key: '%s', value: '%s'\n", hi.getKey(), str->getBuffer());
}
iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:444
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:320

Member Function Documentation

◆ assign()

DLLEXPORT int HashIterator::assign ( QoreValue  val,
ExceptionSink xsink 
)

Assigns the given value to the key and dereferences any current value.

Parameters
valthe value to assign; the value must already be referenced for the assignment
xsinktype exceptions with the value to be assigned and any exception dereferencing the current value will be stored here
Returns
-1 = the iterator is invalid or an exception was thrown dereferencing the current value, or the current key cannot accept the value due to type restrictions; 0 = OK

If the value cannoe be assigned because the iterator is invalid or there is a conflict with the type, the value will be dereferenced in the call.

Since
Qore 1.14

◆ deleteKey()

DLLEXPORT void HashIterator::deleteKey ( ExceptionSink xsink)

deletes the key from the hash and dereferences the value

the pointer is moved to the previous element (or before the beginning) so that the next call to next() will put the pointer on the element after the one being deleted

◆ next()

DLLEXPORT bool HashIterator::next ( )

moves to the next element, returns false when there are no more elements to iterate

also moves to the first element if the object has just been initialized after a complete iteration (assuming there is at least one element in the hash)

◆ prev()

DLLEXPORT bool HashIterator::prev ( )

moves to the previous element, returns false when there are no more elements to iterate

also moves to the last element if the object has just been initialized after a complete iteration (assuming there is at least one element in the hash)


The documentation for this class was generated from the following file: