All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
database_interface::DBFieldBase Class Reference

The base class for a field of a class stored in the database, corresponding to a column in a table. More...

#include <db_field.h>

Inheritance diagram for database_interface::DBFieldBase:
Inheritance graph
[legend]

List of all members.

Public Types

enum  Type { TEXT, BINARY }

Public Member Functions

 DBFieldBase (Type type, DBClass *owner, std::string name, std::string table_name, bool write_permission)
virtual bool fromBinary (const char *binary, size_t length)=0
 Sets the value of this field from a binary chunk of data.
virtual bool fromString (const std::string &str)=0
 Sets the value of this field from a text string.
std::string getName () const
DBClassgetOwner ()
const DBClassgetOwner () const
bool getReadFromDatabase () const
std::string getSequenceName () const
std::string getTableName () const
Type getType () const
bool getWritePermission () const
bool getWriteToDatabase () const
void setReadFromDatabase (bool sync)
void setReadWrite (bool sync)
void setSequenceName (std::string seq)
void setWriteToDatabase (bool sync)
virtual bool toBinary (const char *&binary, size_t &length) const =0
 Gets a pointer to the value of this field as a binary chunk of data.
virtual bool toString (std::string &str) const =0
 Gets the value of this field as a text string.

Protected Member Functions

 DBFieldBase (DBClass *owner, const DBFieldBase *other)
 Copy constructor is protected, it should only be called by derived classes which also copy the data.

Protected Attributes

std::string name_
 The name of the column that this field is stored in in the database.
DBClassowner_
 The class that this field is part of.
bool read_from_database_
 Marks if this field should be read from the database when its owner is read.
std::string sequence_name_
 Optional: the name of a database sequence that is used as a default value for this field.
std::string table_name_
 The name of the table that this field is stored in the database.
Type type_
 The type of this field, either TEXT or BINARY.
bool write_permission_
 Marks if this field is allowed to be used to modify the database.
bool write_to_database_
 Marks if this field should be saved to the database when its owner is saved.

Private Member Functions

const DBFieldBaseoperator= (const DBFieldBase &rhs)
 Makes the class non-assignable, since deep copies are hard because of the owner_ field.

Detailed Description

The base class for a field of a class stored in the database, corresponding to a column in a table.

A class stored in the database (an instance of DBClass) must store all of its database data as instances of a DBField. A DBField (see the DBField class documentation) can store any type of data, as long as it can be converted to/from string or binary, so that it can be retrieved / stored into the database.

For now, all SQL data types except bytea are retreived / stored via text format. That might change in the future. But for now, the requirement for a C++ data type so that it can be used as a DBField is that is can be serialized to / from string. The only exception is std::vector<char> meant to be used in binary form.

This base class provides just the interface for storing / retrieving fields. This is all the database interface needs to use this field.

Definition at line 72 of file db_field.h.


Member Enumeration Documentation

A field marked as TEXT will be serialized to / from string by calling the toString and fromString functions. A field marked as BINARY will be serialized to / from binary by calling the toBinary and fromBinary functions.

Enumerator:
TEXT 
BINARY 

Definition at line 83 of file db_field.h.


Constructor & Destructor Documentation

database_interface::DBFieldBase::DBFieldBase ( DBClass owner,
const DBFieldBase other 
) [inline, protected]

Copy constructor is protected, it should only be called by derived classes which also copy the data.

Definition at line 106 of file db_field.h.

database_interface::DBFieldBase::DBFieldBase ( Type  type,
DBClass owner,
std::string  name,
std::string  table_name,
bool  write_permission 
) [inline]

Definition at line 113 of file db_field.h.


Member Function Documentation

virtual bool database_interface::DBFieldBase::fromBinary ( const char *  binary,
size_t  length 
) [pure virtual]
virtual bool database_interface::DBFieldBase::fromString ( const std::string &  str) [pure virtual]
std::string database_interface::DBFieldBase::getName ( ) const [inline]

Definition at line 149 of file db_field.h.

Definition at line 132 of file db_field.h.

Definition at line 133 of file db_field.h.

Definition at line 135 of file db_field.h.

std::string database_interface::DBFieldBase::getSequenceName ( ) const [inline]

Definition at line 151 of file db_field.h.

std::string database_interface::DBFieldBase::getTableName ( ) const [inline]

Definition at line 150 of file db_field.h.

Definition at line 118 of file db_field.h.

Definition at line 141 of file db_field.h.

Definition at line 138 of file db_field.h.

const DBFieldBase& database_interface::DBFieldBase::operator= ( const DBFieldBase rhs) [private]

Makes the class non-assignable, since deep copies are hard because of the owner_ field.

Use the assignment operator of the DBClass instead, which reasons about this.

Definition at line 136 of file db_field.h.

void database_interface::DBFieldBase::setReadWrite ( bool  sync) [inline]

Definition at line 143 of file db_field.h.

void database_interface::DBFieldBase::setSequenceName ( std::string  seq) [inline]

Definition at line 153 of file db_field.h.

Definition at line 139 of file db_field.h.

virtual bool database_interface::DBFieldBase::toBinary ( const char *&  binary,
size_t &  length 
) const [pure virtual]
virtual bool database_interface::DBFieldBase::toString ( std::string &  str) const [pure virtual]

Member Data Documentation

std::string database_interface::DBFieldBase::name_ [protected]

The name of the column that this field is stored in in the database.

Definition at line 99 of file db_field.h.

The class that this field is part of.

Definition at line 88 of file db_field.h.

Marks if this field should be read from the database when its owner is read.

Definition at line 95 of file db_field.h.

Optional: the name of a database sequence that is used as a default value for this field.

Definition at line 103 of file db_field.h.

The name of the table that this field is stored in the database.

Definition at line 101 of file db_field.h.

The type of this field, either TEXT or BINARY.

Definition at line 86 of file db_field.h.

Marks if this field is allowed to be used to modify the database.

If false, supercedes write_to_database_. Can only be set at construction time. Use this for retrieving information from other tables, but information that you are not allowed to modify through an instance of this class.

Definition at line 93 of file db_field.h.

Marks if this field should be saved to the database when its owner is saved.

Definition at line 97 of file db_field.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends


database_interface
Author(s): Matei Ciocarlie and Lorenz Mosenlechner
autogenerated on Wed Jan 16 2013 13:32:14