BRandomIterator Class Reference
[Data Model]

#include <support/Iterator.h>

Inheritance diagram for BRandomIterator:

BnRandomIterator BObserver IRandomIterator BBinder BBinder IIterator IBinder IBinder IInterface SAtom SAtom SAtom List of all members.

Public Member Functions

 BRandomIterator (const sptr< IIterator > &iter)
virtual size_t Count () const
 The total number of items available in the iterator.
virtual void InitAtom ()
 Called the first time a strong reference is acquired. All significant object initialization should go here.
virtual status_t Next (IIterator::ValueList *keys, IIterator::ValueList *values, uint32_t flags, size_t count=0)
 Return a batch of keys and values from the iteration.
virtual void Observed (const SValue &key, const SValue &value)
 Override this to receive observed events.
virtual SValue Options () const
 The iterable options that are in force for this iterator.
virtual size_t Position () const
 The current position in the iterator.
virtual status_t Remove ()
 Removes the current element.
virtual void SetPosition (size_t value)
 The current position in the iterator.

Protected Member Functions

virtual ~BRandomIterator ()

Constructor & Destructor Documentation

BRandomIterator const sptr< IIterator > &  iter  ) 
 

~BRandomIterator  )  [protected, virtual]
 


Member Function Documentation

size_t Count  )  const [virtual]
 

The total number of items available in the iterator.

Implements IRandomIterator.

void InitAtom  )  [virtual]
 

Called the first time a strong reference is acquired. All significant object initialization should go here.

You can override it and do any setup you need. Note that you do not need to call the SAtom implementation. (So you can derive from two different SAtom implementations and safely call down to both of their IncStrong() methods.)

See also:
IncStrong()

Reimplemented from SAtom.

status_t Next IIterator::ValueList keys,
IIterator::ValueList values,
uint32_t  flags,
size_t  count = 0
[virtual]
 

Return a batch of keys and values from the iteration.

Parameters:
[out] keys The mapping keys. If your iterator is returning simple values (not mappings), the keys can be B_WILD_VALUE, or you can just make this sequence empty.
[out] values The value of each item. Must be returned.
[in] flags Any of REQUEST_DATA, COLLAPSE_NODE, IGNORE_PROJECTION.
[in] count A "hint" about how many results you want. (You may get more, or fewer.) Use 0 for "don't care".
Returns:
B_OK if results were returned, B_END_OF_DATA if there is no more data in the iterator, or some other error code if an error occurred.
This API is designed, for performance reasons, to return iteration results as batches. You will usually use SIterator::Next() to hide that batching mechanism and retrieve the entries one at a time. In either case, the function will return B_END_OF_DATA once you have reached the end of the iterator's data.

The iterator may return key/value pairs, or single values. If returning single values, by the SValue mapping rules the key should always be B_WILD_VALUE.

The Next() method can be given a flags parameter. Like INode::Walk(), you can supply REQUEST_DATA and COLLAPSE_NODE in the function's flags, with the corresponding semantics for the values the iterator returns. Also like INode::Walk(), the iterator is free to ignore these flags.

Implements IIterator.

void Observed const SValue key,
const SValue value
[virtual]
 

Override this to receive observed events.

Implements BObserver.

SValue Options  )  const [virtual]
 

The iterable options that are in force for this iterator.

You can use this determine which of the arguments given to IIterable::NewIterator() are in force for this iterator, and in what way. These are the same form as the arguments supplied to IIterable::NewIterator().

Implements IIterator.

size_t Position  )  const [virtual]
 

The current position in the iterator.

This is the index of the item that will be returned the next time IIterator::Next() is called. That is, semantically the Next() operation returns the data at the current location, and then increments the iterator to the next location.

To retrieve an item at a specific location, first set position to the index of the desired item (range from 0 to count-1) and then call IIterator with count=1 to retrieve only that item.

Setting position to 0 will make the iterator restart back at the beginning of its data.

Implements IRandomIterator.

status_t Remove  )  [virtual]
 

Removes the current element.

Iterators are not required to implement this, and can return B_UNSUPPORTED in that case. Note that this removes the item at the current position, thus if you call Next() and then Remove(), you will be removing the next item after the ones you had just retrieved.

Implements IRandomIterator.

void SetPosition size_t  value  )  [virtual]
 

The current position in the iterator.

This is the index of the item that will be returned the next time IIterator::Next() is called. That is, semantically the Next() operation returns the data at the current location, and then increments the iterator to the next location.

To retrieve an item at a specific location, first set position to the index of the desired item (range from 0 to count-1) and then call IIterator with count=1 to retrieve only that item.

Setting position to 0 will make the iterator restart back at the beginning of its data.

Implements IRandomIterator.


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