Dv::Sql::Set< T > Class Template Reference

A Dv::Sql::Set<T> represents a set of T-objects retrieved from the database. More...

#include <set.h>

List of all members.

Public Types

typedef Dv::shared_ptr< Set< T > > Ref
 Type of a reference-counted pointer to a set.
typedef std::vector
< Dv::shared_ptr< T > > 
Container
 The underlying container type, which contains reference counted pointers to T-objects.
typedef Container::const_iterator const_iterator
typedef
Container::const_reverse_iterator 
const_reverse_iterator
typedef Container::iterator iterator
typedef Container::reverse_iterator reverse_iterator

Public Member Functions

 Set (Dv::Sql::Command &q) throw (std::logic_error)
 Initialize a set using the result of a query.
 Set (Dv::Sql::Db &db, const std::string &prefix, SelectExp select_exp=SelectExp(new Dv::Sql::true_boolexp()), const std::string &rest="") throw (std::logic_error)
 Initialize a set using the result of a query.
 Set (const Dv::Sql::Table::Ref &table, SelectExp select_exp=SelectExp(new Dv::Sql::true_boolexp()), const std::string &rest="") throw (std::logic_error)
 Initialize a set using the result of a query.
 Set (const T &t, const std::string &rest="") throw (std::logic_error)
 Initialize the set with all objects that match the dirty column values in t.
template<typename Source >
 Set (const Source &target, const Dv::Sql::Reference &reference, const std::string &rest="") throw (std::logic_error)
 Initialize a set to contain all source objects that are linked via a Reference to a given target object.
size_t set (Dv::Sql::Command &q) throw (std::logic_error)
 Append the result of a query to this set.
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
const_iterator begin () const
const_iterator end () const
size_t size () const
template<typename C >
void get (size_t i, C &container, const_iterator i0, const_iterator i1) const throw (std::logic_error)
 Retrieve a column value for all objects in this set.
template<typename C >
void get_insert (size_t i, C &container, const_iterator i0, const_iterator i1) const throw (std::logic_error)
 Retrieve a column value for all objects in this set.
template<typename C >
void get (size_t i, C &container) const throw (std::logic_error)
template<typename C >
void get (const Table::Column &c, C &container) const throw (std::logic_error)
template<typename C >
void get (const std::string &col_name, C &container) const throw (std::logic_error)
void append (const Set< T > &source)

Private Attributes

Container objects_

Detailed Description

template<typename T = Dv::Sql::Object>
class Dv::Sql::Set< T >

A Dv::Sql::Set<T> represents a set of T-objects retrieved from the database.

Normally, the template parameter is derived from Dv::Sql::Object.

See also:
Dv::Sql::Object
Dv::Sql::Row

Definition at line 24 of file set.h.


Member Typedef Documentation

template<typename T = Dv::Sql::Object>
typedef Dv::shared_ptr<Set<T> > Dv::Sql::Set< T >::Ref

Type of a reference-counted pointer to a set.

Definition at line 27 of file set.h.

template<typename T = Dv::Sql::Object>
typedef std::vector<Dv::shared_ptr<T> > Dv::Sql::Set< T >::Container

The underlying container type, which contains reference counted pointers to T-objects.

Definition at line 31 of file set.h.

template<typename T = Dv::Sql::Object>
typedef Container::const_iterator Dv::Sql::Set< T >::const_iterator

Definition at line 32 of file set.h.

template<typename T = Dv::Sql::Object>
typedef Container::const_reverse_iterator Dv::Sql::Set< T >::const_reverse_iterator

Definition at line 33 of file set.h.

template<typename T = Dv::Sql::Object>
typedef Container::iterator Dv::Sql::Set< T >::iterator

Definition at line 34 of file set.h.

template<typename T = Dv::Sql::Object>
typedef Container::reverse_iterator Dv::Sql::Set< T >::reverse_iterator

Definition at line 35 of file set.h.


Constructor & Destructor Documentation

template<typename T = Dv::Sql::Object>
Dv::Sql::Set< T >::Set ( Dv::Sql::Command q  )  throw (std::logic_error) [inline]

Initialize a set using the result of a query.

Parameters:
q query to initialize set with
Exceptions:
std::logic_error if executing the query fails

Definition at line 41 of file set.h.

template<typename T = Dv::Sql::Object>
Dv::Sql::Set< T >::Set ( Dv::Sql::Db db,
const std::string &  prefix,
SelectExp  select_exp = SelectExp(new Dv::Sql::true_boolexp()),
const std::string &  rest = "" 
) throw (std::logic_error) [inline]

Initialize a set using the result of a query.

The query is built using a prefix, usually of the form

 select * from tablename where select_exp rest
Example
 std::string zip;
 // retrieve sorted list of ages of customers in a certain area,
 Dv::Sql::Set<Object> ages(db, 
    "select age from customer where ", 
    Customer::zip = zip and age > 10,
    "order by age");
Parameters:
db database connection to use
prefix of the query text
select_exp condition to be used in the query text
rest suffix of the query text
Exceptions:
std::logic_error if executing the query fails

Definition at line 65 of file set.h.

template<typename T = Dv::Sql::Object>
Dv::Sql::Set< T >::Set ( const Dv::Sql::Table::Ref table,
SelectExp  select_exp = SelectExp(new Dv::Sql::true_boolexp()),
const std::string &  rest = "" 
) throw (std::logic_error) [inline]

Initialize a set using the result of a query.

The query has the following form.

 select table.c1, table.c2, .. , table.cn from table where select_exp rest

where (c1 .. cn) are all columns of table.

Example
 Dv::Sql::Table::Ref customer;
 std::string zip;
 // list of customers in area ordered by age
 Dv::Sql::Set<Object> customers(customer, 
                        Customer::zip = zip and age > 10,
                        "order by age");
Parameters:
table database table to select from
select_exp condition to be used in the query text
rest suffix of the query text, may be 0
Exceptions:
std::logic_error if executing the query fails

Definition at line 97 of file set.h.

template<typename T = Dv::Sql::Object>
Dv::Sql::Set< T >::Set ( const T &  t,
const std::string &  rest = "" 
) throw (std::logic_error) [inline]

Initialize the set with all objects that match the dirty column values in t.

Parameters:
t object to match
rest optional suffix for the constructed query
Exceptions:
std::logic_error iff executing the query fails
See also:
Object::match

Definition at line 116 of file set.h.

template<typename T = Dv::Sql::Object>
template<typename Source >
Dv::Sql::Set< T >::Set ( const Source &  target,
const Dv::Sql::Reference reference,
const std::string &  rest = "" 
) throw (std::logic_error) [inline]

Initialize a set to contain all source objects that are linked via a Reference to a given target object.

Thus, this constructor follows the reference in the "reverse" direction (from target to source). Since, usually, references are (in the normal direction) many-to-one, the reverse mapping is one-to-many.

Example
 const Dv::Sql::Reference acct_cust(
           Database::account, (cols = &Account::customer_id), 
           Database::customer, (cols = &Customer::id)
           );
 Dv::Sql::Row<Database::customer> cust;
 cust.set(Customer::id, 1000);
 Dv::Sql::Set<Dv::Sql::Row<Database::account> > accounts(cust, acct_cust);
 // Now accounts contains all accounts for the given customer @p cust.
Parameters:
target object whose column values will be copied to a source object, according to ref
reference object describing ma
Exceptions:
std::logic_error if the query fails.

Definition at line 144 of file set.h.


Member Function Documentation

template<typename T = Dv::Sql::Object>
size_t Dv::Sql::Set< T >::set ( Dv::Sql::Command q  )  throw (std::logic_error) [inline]

Append the result of a query to this set.

Parameters:
q query for which result will be appended to the set
Returns:
new size of the set
Exceptions:
std::logic_error if query execution fails

Definition at line 158 of file set.h.

template<typename T = Dv::Sql::Object>
const_reverse_iterator Dv::Sql::Set< T >::rbegin (  )  const [inline]

Definition at line 173 of file set.h.

template<typename T = Dv::Sql::Object>
const_reverse_iterator Dv::Sql::Set< T >::rend (  )  const [inline]

Definition at line 174 of file set.h.

template<typename T = Dv::Sql::Object>
const_iterator Dv::Sql::Set< T >::begin (  )  const [inline]
template<typename T = Dv::Sql::Object>
const_iterator Dv::Sql::Set< T >::end (  )  const [inline]
template<typename T = Dv::Sql::Object>
size_t Dv::Sql::Set< T >::size (  )  const [inline]
template<typename T = Dv::Sql::Object>
template<typename C >
void Dv::Sql::Set< T >::get ( size_t  i,
C &  container,
const_iterator  i0,
const_iterator  i1 
) const throw (std::logic_error) [inline]

Retrieve a column value for all objects in this set.

Parameters:
i index (0-based) of the column value to retrieve
Returns:
the (converted) column value
Exceptions:
std::logic_error if i exceeds the object's arity
std::logic_error if the conversion from a string fails

Definition at line 189 of file set.h.

template<typename T = Dv::Sql::Object>
template<typename C >
void Dv::Sql::Set< T >::get_insert ( size_t  i,
C &  container,
const_iterator  i0,
const_iterator  i1 
) const throw (std::logic_error) [inline]

Retrieve a column value for all objects in this set.

Parameters:
i index (0-based) of the column value to retrieve
Returns:
the (converted) column value
Exceptions:
std::logic_error if i exceeds the object's arity
std::logic_error if the conversion from a string fails

Definition at line 204 of file set.h.

template<typename T = Dv::Sql::Object>
template<typename C >
void Dv::Sql::Set< T >::get ( size_t  i,
C &  container 
) const throw (std::logic_error) [inline]

Definition at line 213 of file set.h.

template<typename T = Dv::Sql::Object>
template<typename C >
void Dv::Sql::Set< T >::get ( const Table::Column c,
C &  container 
) const throw (std::logic_error) [inline]

Definition at line 217 of file set.h.

template<typename T = Dv::Sql::Object>
template<typename C >
void Dv::Sql::Set< T >::get ( const std::string &  col_name,
C &  container 
) const throw (std::logic_error) [inline]

Definition at line 221 of file set.h.

template<typename T = Dv::Sql::Object>
void Dv::Sql::Set< T >::append ( const Set< T > &  source  )  [inline]

Definition at line 226 of file set.h.


Member Data Documentation

template<typename T = Dv::Sql::Object>
Container Dv::Sql::Set< T >::objects_ [private]

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

dvmysql-1.0.3 [17 November, 2010]