Dv::Sql::Object::ColumnRef Class Reference

A class that represents a reference to a column value in an Object. More...

#include <object.h>

Collaboration diagram for Dv::Sql::Object::ColumnRef:
Collaboration graph
[legend]

List of all members.

Public Member Functions

template<typename T >
convert () const throw (std::logic_error)
 Obtain the associated column value as a value of type T.
template<typename T >
 operator T () const throw (std::logic_error)
 Obtain the associated column value as a value of type T.
template<typename T >
Objectoperator= (const T &t) throw (std::logic_error)
 Assign a new value to the referenced object column.
Objectoperator= (const ColumnRef &r) throw (std::logic_error)
 Copy one column value to another.
template<typename T >
bool operator== (const T &t) const throw (std::logic_error)
 Check whether the column value referred to equals the parameter.
bool operator== (const char *t) const throw (std::logic_error)
 Special case of check whether the column value referred to equals the parameter.
bool operator== (const ColumnRef &r) throw (std::logic_error)
 Check whether the column value referred to equals the column value referred to by the parameter.
template<typename T >
bool operator!= (const T &t) const throw (std::logic_error)
 Check whether the column value referred to is different from the parameter.
bool operator!= (const char *t) const throw (std::logic_error)
 Special case of check whether the column value referred to is different from the parameter.
bool operator!= (const ColumnRef &r) throw (std::logic_error)
 Check whether the column value referred to is different from the column value referred to by the parameter.
Objectset_null (bool new_value)
 Set the corresponding value to null (or not).
bool null () const
 Check null status of the underlying column value.
Objectset_dirty (bool new_value)
 Set the dirty status of the underlying column value.
Objecttouch ()
 Set the dirty status of the underlying column value to true.
bool dirty () const
 Check dirty status of the underlying column value.

Private Member Functions

 ColumnRef (Object &o, size_t i) throw (std::logic_error)
 Construcor.

Private Attributes

Objectobject_
 This ColumnRef refers to a column value in this object.
size_t index_
 Index of column to which this ColumnRef refers (in object_ ).

Friends

class Object
template<typename T >
bool operator!= (const T &t, const ColumnRef &c) throw (std::logic_error)
 Check whether the column value referred to by the second parameter is different from the first parameter.
template<typename T >
bool operator== (const T &t, const ColumnRef &c) throw (std::logic_error)
 Check whether the column value referred to by the second parameter equals the first parameter.

Detailed Description

A class that represents a reference to a column value in an Object.

ColumnRef objects result from calling operator[] on an object. Such objects can convert to actual data values or be assigned to to change the value of a column in an object.

See also:
Object::operator[].

Definition at line 56 of file object.h.


Constructor & Destructor Documentation

Dv::Sql::Object::ColumnRef::ColumnRef ( Object o,
size_t  i 
) throw (std::logic_error) [private]

Construcor.

Parameters:
o referenced object
i number of referenced column
Exceptions:
std::logic_error if i exceeds the arity of the object
See also:
Object::arity

Member Function Documentation

template<typename T >
T Dv::Sql::Object::ColumnRef::convert (  )  const throw (std::logic_error) [inline]

Obtain the associated column value as a value of type T.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 Dv::Util::Date birth_date = cust["birth_date"]; // will convert
Exceptions:
std::logic_error if the conversion failed.

Definition at line 69 of file object.h.

References Dv::Sql::Object::data_, index_, and object_.

template<typename T >
Dv::Sql::Object::ColumnRef::operator T (  )  const throw (std::logic_error) [inline]

Obtain the associated column value as a value of type T.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 Dv::Util::Date birth_date = cust["birth_date"]; // will convert
Exceptions:
std::logic_error if the conversion failed.

Definition at line 88 of file object.h.

template<typename T >
Object& Dv::Sql::Object::ColumnRef::operator= ( const T &  t  )  throw (std::logic_error) [inline]

Assign a new value to the referenced object column.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 cust["id"] = 123;
Parameters:
t value to be assigned
Returns:
a reference to the underlying object
Exceptions:
std::logic_error if the ColumnRef object refers to a nonexisting colum in the associated Object

Definition at line 105 of file object.h.

References index_, object_, and Dv::Sql::Object::set_data().

Object& Dv::Sql::Object::ColumnRef::operator= ( const ColumnRef r  )  throw (std::logic_error) [inline]

Copy one column value to another.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 Dv::Sql::Table::Ref account;
 Dv::Sql::Object acct(account);
 cust["id"] = acct["customer_id"] 
Parameters:
r the ColumnRef for which the associated column value is to be assigned to the column value associated with this ColumnRef
Returns:
a reference to the underlying Object of this ColumnRef
Exceptions:
std::logic_error if this or ColumnRef object refers to a nonexisting colum in the associated Object

Definition at line 126 of file object.h.

References index_, object_, and Dv::Sql::Object::set_data().

template<typename T >
bool Dv::Sql::Object::ColumnRef::operator== ( const T &  t  )  const throw (std::logic_error) [inline]

Check whether the column value referred to equals the parameter.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 if ( cust["id"] == 123) {
   ..
 }
Parameters:
t the value to compare with
Returns:
true iff the values are equal
false iff the values are not equal
Exceptions:
std::logic_error if the conversion fails

Definition at line 146 of file object.h.

bool Dv::Sql::Object::ColumnRef::operator== ( const char *  t  )  const throw (std::logic_error) [inline]

Special case of check whether the column value referred to equals the parameter.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 if ( cust["name"] == "Jones") {
   ..
 }
Parameters:
t the value to compare with
Returns:
true iff the values are equal
false iff the values are not equal
Exceptions:
std::logic_error if the conversion fails

Definition at line 166 of file object.h.

bool Dv::Sql::Object::ColumnRef::operator== ( const ColumnRef r  )  throw (std::logic_error) [inline]

Check whether the column value referred to equals the column value referred to by the parameter.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 Dv::Sql::Table::Ref account;
 Dv::Sql::Object acct(account);
 if (cust["id"] == acct["customer_id"]) {
   ..
 }
Parameters:
r the ColumnRef to compare with
Returns:
true iff the values are both null or are equal and (both) not null
false otherwise
Exceptions:
std::logic_error if the conversion fails

Definition at line 187 of file object.h.

References Dv::Sql::Object::data_, index_, Dv::Sql::Object::null_, and object_.

template<typename T >
bool Dv::Sql::Object::ColumnRef::operator!= ( const T &  t  )  const throw (std::logic_error) [inline]

Check whether the column value referred to is different from the parameter.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 if ( cust["id"] != 123) {
   ..
 }
Parameters:
t the value to compare with
Returns:
true iff the values are different
false iff the values are equal
Exceptions:
std::logic_error if the conversion fails

Definition at line 210 of file object.h.

bool Dv::Sql::Object::ColumnRef::operator!= ( const char *  t  )  const throw (std::logic_error) [inline]

Special case of check whether the column value referred to is different from the parameter.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 if ( cust["name"] != "Jones") {
   ..
 }
Parameters:
t the value to compare with
Returns:
true iff the values are different
false iff the values are equal
Exceptions:
std::logic_error if the conversion fails

Definition at line 229 of file object.h.

bool Dv::Sql::Object::ColumnRef::operator!= ( const ColumnRef r  )  throw (std::logic_error) [inline]

Check whether the column value referred to is different from the column value referred to by the parameter.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 Dv::Sql::Table::Ref account;
 Dv::Sql::Object acct(account);
 if (cust["id"] != acct["customer_id"]) {
   ..
 }
Parameters:
r the ColumnRef to compare with
Returns:
false iff the values are both null or are equal and (both) not null
true otherwise
Exceptions:
std::logic_error if the conversion fails

Definition at line 250 of file object.h.

Object& Dv::Sql::Object::ColumnRef::set_null ( bool  new_value  ) 

Set the corresponding value to null (or not).

A null column corresponds to a database NULL value.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 cust["id"].set_null(true);
Parameters:
new_value if true, the column value will be set to null, if false, it will be set to non-null.
Returns:
a reference to the referenced Object
bool Dv::Sql::Object::ColumnRef::null (  )  const

Check null status of the underlying column value.

A null column corresponds to a database NULL value.

Returns:
true iff the underlying column value is null
Object& Dv::Sql::Object::ColumnRef::set_dirty ( bool  new_value  ) 

Set the dirty status of the underlying column value.

A dirty column value represents the assumption that the value was not retrieved from the database, but was set explicitly by the user.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 cust["id"] = 123; 
 std::cout << cust.dirty("id"); // prints 1
 cust["id"].set_dirty(false);
 std::cout << cust.dirty("id"); // prints 0
Parameters:
new_value if true, the dirty status will be set to true
Returns:
a reference to the referenced Object

Referenced by touch().

Object& Dv::Sql::Object::ColumnRef::touch (  )  [inline]

Set the dirty status of the underlying column value to true.

A dirty column value represents the assumption that the value was not retrieved from the database, but was set explicitly by the user.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 cust["id"].touch(); 
 std::cout << cust.dirty("id"); // prints 1
Returns:
a reference to the referenced Object

Definition at line 353 of file object.h.

References set_dirty().

bool Dv::Sql::Object::ColumnRef::dirty (  )  const

Check dirty status of the underlying column value.

A dirty column value represents the assumption that the value was not retrieved from the database, but was set explicitly by the user.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 cust["id"] = 123; 
 std::cout << cust.dirty("id"); // prints 1
 cust["id"].set_dirty(false);
 std::cout << cust.dirty("id"); // prints 0
Returns:
true iff the underlying column value is null

Friends And Related Function Documentation

friend class Object [friend]

Definition at line 57 of file object.h.

template<typename T >
bool operator!= ( const T &  t,
const ColumnRef c 
) throw (std::logic_error) [friend]

Check whether the column value referred to by the second parameter is different from the first parameter.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 if ( 123 != cust["id"] ) {
   ..
 }
Parameters:
t the value to compare with
c the ColumnRef referring to the column value to compare t with
Returns:
true iff the values are different
false iff the values are equal
Exceptions:
std::logic_error if the conversion fails

Definition at line 273 of file object.h.

template<typename T >
bool operator== ( const T &  t,
const ColumnRef c 
) throw (std::logic_error) [friend]

Check whether the column value referred to by the second parameter equals the first parameter.

This is an ordinary function.

Example
 Dv::Sql::Table::Ref customer;
 Dv::Sql::Object cust(customer);
 if ( 123 == cust["id"] ) {
   ..
 }
Parameters:
t the value to compare with
c the ColumnRef referring to the column value to compare t with
Returns:
true iff the values are equal
false iff the values are not equal
Exceptions:
std::logic_error if the conversion fails

Definition at line 295 of file object.h.


Member Data Documentation

This ColumnRef refers to a column value in this object.

Definition at line 383 of file object.h.

Referenced by convert(), operator=(), and operator==().

Index of column to which this ColumnRef refers (in object_ ).

Definition at line 385 of file object.h.

Referenced by convert(), operator=(), and operator==().


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

dvmysql-1.0.3 [17 November, 2010]