Public Member Functions | Protected Attributes | Private Member Functions
database_interface::DBClass Class Reference

The base class for all C++ classes that can be stored in the database. More...

#include <db_class.h>

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

List of all members.

Public Member Functions

 DBClass ()
DBFieldBasegetField (size_t i)
const DBFieldBasegetField (size_t i) const
DBFieldBasegetField (std::string name)
const DBFieldBasegetField (std::string name) const
bool getForeignKey (std::string table, const DBFieldBase *&key) const
 Returns the name of the foreign key column in a given table that references our primary key.
bool getForeignKey (std::string table, DBFieldBase *&key)
size_t getNumFields () const
DBFieldBasegetPrimaryKeyField ()
const DBFieldBasegetPrimaryKeyField () const
void setAllFieldsReadFromDatabase (bool sync)
void setAllFieldsWriteToDatabase (bool sync)

Protected Attributes

std::vector< DBFieldBase * > fields_
 The addresses of all the other fields.
std::map< std::string,
DBFieldBase * > 
foreign_keys_
 List of foreign keys in OTHER tables that reference our PRIMARY KEY.
DBFieldBaseprimary_key_field_
 The address of the field that acts as a primary key.

Private Member Functions

DBClassoperator= (const DBClass &rhs)
 Makes the class non-assignable.

Detailed Description

The base class for all C++ classes that can be stored in the database.

A DBClass is a collection of fields.

One of the fields is marked as a primary key, which is the only unique identifier for this class. The primary key field is expected to reference the primary key column in the main table where this class is stored in the database.

All the other fields are expected to be stored either in the same table as the primary key, or in other tables that reference our primary key in a foreign key column.

To use this class, any data members that you want to save / load from database must be declared as DBFields. Then, IN THE CONSTRUCTOR, you must tell this interface which of them is the primary key, and store the rest in the fields_ vector. After this, all database functionality will be automagically done for you.

Also in the contructor you can set which fields are read from / written to the database by default, and which should be only when you specifically ask for them

For an example, see the DatabaseOriginalModel implementation.

Definition at line 64 of file db_class.h.


Constructor & Destructor Documentation

Definition at line 86 of file db_class.h.


Member Function Documentation

Definition at line 90 of file db_class.h.

const DBFieldBase* database_interface::DBClass::getField ( size_t  i) const [inline]

Definition at line 91 of file db_class.h.

DBFieldBase* database_interface::DBClass::getField ( std::string  name) [inline]

Definition at line 93 of file db_class.h.

const DBFieldBase* database_interface::DBClass::getField ( std::string  name) const [inline]

Definition at line 102 of file db_class.h.

bool database_interface::DBClass::getForeignKey ( std::string  table,
const DBFieldBase *&  key 
) const [inline]

Returns the name of the foreign key column in a given table that references our primary key.

The list of foreign keys must be inserted here IN THE CONSTRUCTOR, if you have fields that live in other tables than the primary key.

Definition at line 111 of file db_class.h.

bool database_interface::DBClass::getForeignKey ( std::string  table,
DBFieldBase *&  key 
) [inline]

Definition at line 120 of file db_class.h.

size_t database_interface::DBClass::getNumFields ( ) const [inline]

Definition at line 88 of file db_class.h.

Definition at line 104 of file db_class.h.

Definition at line 105 of file db_class.h.

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

Makes the class non-assignable.

Prevents the use of instances of DBClass in std::vectors since deep copies are extremely hard because of the vector of pointers to DBFieldBase, which should have pointers to its own members. Use boost::ptr_vector instead for passing around containers of DBClass.

Definition at line 125 of file db_class.h.

Definition at line 134 of file db_class.h.


Member Data Documentation

The addresses of all the other fields.

Definition at line 79 of file db_class.h.

std::map<std::string, DBFieldBase*> database_interface::DBClass::foreign_keys_ [protected]

List of foreign keys in OTHER tables that reference our PRIMARY KEY.

Foreign keys are expected to have the *same name* in both tables they join

Definition at line 83 of file db_class.h.

The address of the field that acts as a primary key.

Definition at line 76 of file db_class.h.


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


sql_database
Author(s): Matei Ciocarlie and Lorenz Mosenlechner
autogenerated on Fri Aug 28 2015 13:11:16