libqmlbind
A C library for creating QML bindings for other languages easily through exporting objects to QML
Files | Classes | Functions
qmlbind_iterator

provides a Java-style iterator for the properties of qmlbind_values. More...

Files

file  iterator.h
 Contains all methods defined on qmlbind_iterator.
 

Classes

struct  qmlbind_iterator
 an opaque struct mainly used as self argument in the methods defined in qmlbind_iterator. More...
 

Functions

QMLBIND_API qmlbind_iteratorqmlbind_iterator_new (const qmlbind_value *object)
 Constructs an iterator for traversing object. More...
 
QMLBIND_API void qmlbind_iterator_release (qmlbind_iterator *self)
 Destroys this qmlbind_iterator.
 
QMLBIND_API qmlbind_stringqmlbind_iterator_get_key (const qmlbind_iterator *self)
 Returns the name of the last property that was jumped over using qmlbind_iterator_next(). More...
 
QMLBIND_API qmlbind_valueqmlbind_iterator_get_value (const qmlbind_iterator *self)
 Returns the value of the last property that was jumped over using qmlbind_iterator_next(). More...
 
QMLBIND_API void qmlbind_iterator_next (qmlbind_iterator *self)
 Advances the iterator by one position. More...
 
QMLBIND_API int qmlbind_iterator_has_next (const qmlbind_iterator *self)
 Returns 1 if there is at least one item ahead of the iterator (i.e. the iterator is not at the back of the property sequence); otherwise returns 0. More...
 

Detailed Description

provides a Java-style iterator for the properties of qmlbind_values.

The qmlbind_iterator_new() constructor takes a qmlbind_value as argument. After construction, the iterator is located at the very beginning of the sequence of properties. Here's how to iterate over all the properties of a qmlbind_value:

qmlbind_value *object;
...
qmlbind_iterator it = qmlbind_iterator_new(object);
qmlbind_string *value_str = qmlbind_iterator_get_string(it);
printf("%s: %s", qmlbind_string_get_chars(key), qmlbind_string_get_chars(value_str));
}

The qmlbind_iterator_next() advances the iterator. The qmlbind_iterator_get_key() and qmlbind_iterator_get_value() functions return the name and value of the last item that was jumped over.

Note that qmlbind_iterator only iterates over the qmlbind_value's own properties; i.e. it does not follow the prototype chain. You can use a loop like this to follow the prototype chain:

qmlbind_value *obj = ...; // the object to iterate over
printf("%s", qmlbind_iterator_get_chars(key));
}
obj = prototype;
}

libqmlbind's equivalent of QJSValueIterator.

Function Documentation

QMLBIND_API qmlbind_iterator* qmlbind_iterator_new ( const qmlbind_value object)

Constructs an iterator for traversing object.

The iterator is set to be at the front of the sequence of properties (before the first property).

libqmlbind's equivalent of QJSValueIterator::QJSValueIterator.

QMLBIND_API qmlbind_string* qmlbind_iterator_get_key ( const qmlbind_iterator self)

Returns the name of the last property that was jumped over using qmlbind_iterator_next().

Ownership of the returned string is transfered to the caller.

libqmlbind's equivalent of QJSValueIterator::name().

QMLBIND_API qmlbind_value* qmlbind_iterator_get_value ( const qmlbind_iterator self)

Returns the value of the last property that was jumped over using qmlbind_iterator_next().

Ownership of the returned value is transfered to the caller.

libqmlbind's equivalent of QJSValueIterator::value().

QMLBIND_API void qmlbind_iterator_next ( qmlbind_iterator self)

Advances the iterator by one position.

Returns 1 if there was at least one item ahead of the iterator (i.e. the iterator was not already at the back of the property sequence); otherwise returns 0.

libqmlbind's equivalent of QJSValueIterator::next().

QMLBIND_API int qmlbind_iterator_has_next ( const qmlbind_iterator self)

Returns 1 if there is at least one item ahead of the iterator (i.e. the iterator is not at the back of the property sequence); otherwise returns 0.

libqmlbind's equivalent of QJSValueIterator::hasNext().