Wt
3.3.8
|
An STL container for iterating query results. More...
#include <Wt/Dbo/collection>
Classes | |
class | const_iterator |
Const Iterator. More... | |
class | iterator |
Iterator. More... | |
Public Types | |
typedef C | value_type |
Value type. | |
Public Member Functions | |
collection () | |
Default constructor. More... | |
collection (const collection< C > &other) | |
Copy constructor. | |
collection< C > & | operator= (const collection< C > &other) |
Assignment operator. | |
~collection () | |
Destructor. | |
iterator | begin () |
Returns an iterator to the begin of the collection. More... | |
iterator | end () |
Returns an iterator to the end of the collection. More... | |
const_iterator | begin () const |
Returns a const iterator to the begin of the collection. More... | |
const_iterator | end () const |
Returns a const iterator to the end of the collection. More... | |
C | front () const |
Returns a reference to the first object. More... | |
size_type | size () const |
Returns the size. More... | |
bool | empty () const |
Returns whether the collection is empty. More... | |
void | insert (C c) |
Inserts an object. More... | |
void | erase (C c) |
Removes an object. More... | |
void | clear () |
Clears the collection. More... | |
int | count (C c) const |
Returns the whether the collection contains an object. More... | |
Session * | session () const |
Returns the session to which this collection is bound. | |
Query< C, DynamicBinding > | find () const |
Returns the query that backs the collection. More... | |
An STL container for iterating query results.
This is an STL-compatible container that is backed by an SQL query for fetching data.
A collection has two uses in Wt::Dbo:
Its iterators implement the InputIterator requirements, meaning you have to traverse the results from begin() to end() solely by alternating between reading an element and incrementing the iterator. When the collection represents the results of a Query, you can only iterate the results just once: i.e. you can have only one begin() call.
If you cannot gaurantee that during its iteration the same query will be reused, you should copy the results in a standard container. Note that this is no big overhead since dbo pointers are lightweight.
Before iterating a collection, the session is flushed. In this way, the collection will reflect any pending dirty changes.
Wt::Dbo::collection< C >::collection | ( | ) |
Default constructor.
Constructs an empty collection that is not bound to a database session or query.
collection< C >::iterator Wt::Dbo::collection< C >::begin | ( | ) |
Returns an iterator to the begin of the collection.
collection< C >::const_iterator Wt::Dbo::collection< C >::begin | ( | ) | const |
Returns a const iterator to the begin of the collection.
void Wt::Dbo::collection< C >::clear | ( | ) |
Clears the collection.
int Wt::Dbo::collection< C >::count | ( | C | c | ) | const |
Returns the whether the collection contains an object.
This creates a suitable query that checks whether the collection contains ptr<X> objects (without getting the entire collection from the database). The returned value is the number of times the collection contains the object (0 or 1).
bool Wt::Dbo::collection< C >::empty | ( | ) | const |
Returns whether the collection is empty.
Returns whether size() == 0
collection< C >::iterator Wt::Dbo::collection< C >::end | ( | ) |
Returns an iterator to the end of the collection.
collection< C >::const_iterator Wt::Dbo::collection< C >::end | ( | ) | const |
Returns a const iterator to the end of the collection.
void Wt::Dbo::collection< C >::erase | ( | C | c | ) |
Removes an object.
Query< C, DynamicBinding > Wt::Dbo::collection< C >::find | ( | ) | const |
Returns the query that backs the collection.
Returns the query that backs the collection. This can be used to search for a subset or to browse the results in a particular order.
C Wt::Dbo::collection< C >::front | ( | ) | const |
Returns a reference to the first object.
This is equivalent to:
void Wt::Dbo::collection< C >::insert | ( | C | c | ) |
Inserts an object.
collection< C >::size_type Wt::Dbo::collection< C >::size | ( | ) | const |