ADi-FontEngine  1.0
PDF Optimized FontEngine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FontEngine::TDBank< T, S, N, P > Class Template Reference

flexible data bank class template More...

#include <FontEngineDBank.h>

Classes

struct  TIterator
 

Public Types

typedef TIterator iterator
 
typedef const TIterator const_iterator
 
typedef TDataVec TDataImportVec
 
typedef TDataVec::size_type TDataIndex
 

Public Member Functions

 TDBank ()
 default ctor More...
 
 TDBank (const TDBank &db)
 copy ctor More...
 
TDBankoperator= (const TDBank &db)
 assignment operator More...
 
bool operator== (const TDBank &db) const
 to compare two objects of struct TDBank More...
 
const value_type & operator[] (TDataIndex didx) const
 index operator More...
 
bool empty () const
 return the size state More...
 
size_t size () const
 return the size of data bank storage More...
 
size_t size (selector_type sel) const
 return the size of data bank storage with selector More...
 
void clear ()
 reset data bank storage More...
 
void insert (const value_type &vt)
 insert a new value item into data bank storage this function will call the the comparison function object, see struct TDBComp More...
 
iterator begin (selector_type sel) const
 get storage iterator from first item with selector More...
 
iterator end (selector_type sel) const
 get storage iterator from end with selector, this is the invalid iterator for this selector to compare with other iterators More...
 
size_t count (const value_type &vt, selector_type sel) const
 get number of value items in same range as given value with selector More...
 
iterator lower_bound (const value_type &vt, selector_type sel) const
 get storage first iterator in same range as given value with selector More...
 
iterator upper_bound (const value_type &vt, selector_type sel) const
 get storage first iterator from outside same range as given value with selector More...
 
iterator find (const value_type &vt, selector_type sel) const
 find storage first iterator from given value with selector More...
 
iterator erase (const iterator &it)
 earse value item from storage with iterator More...
 
void modify (const iterator &it, const value_type &vt)
 modify existing value item with iterator More...
 
void swap (TDBank &db)
 swap all storage date between other data bank instance More...
 
void merge (const TDBank &db, selector_type sel)
 merge from other data bank storage into own instance with selector More...
 
void import (TDataImportVec &data)
 import from value array into own instance More...
 

Detailed Description

template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
class FontEngine::TDBank< T, S, N, P >

flexible data bank class template

The data bank template and example to demonstrate how the TDBank template works:

Parameters
Tthe data bank item type
Sthe data bank selector type
Nthe number of selectors used to define number of primary key sets
Pthe comparison function object, see struct TDBComp
// ADiFEDBankDemo.cpp
//
#include <stdio.h>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/*! \brief The demo data bank address struct
*/
struct TAdrData
{
//! the selector enum to define data bank search indices
enum ESelector
{
esName
, esFamilyName
, esAge
, esPhone
, esMobile
, esPostcode
, esCity
, esAddress
};
//-----------------------------------------------------------------------------
//! ctor default
TAdrData()
{}
//-----------------------------------------------------------------------------
/*! ctor with parameter
\param name the family name
\param fname the first name
\param age theage of person
\param phone the phone number
\param mobile the mobile phone number
\param postcode the postcode numer
\param city the city the person live
\param address the address the person live
*/
TAdrData( const std::string & name, const std::string & fname, unsigned int age, const std::string & phone,
const std::string & mobile, unsigned int postcode, const std::string & city, const std::string & address)
: _name( name)
, _familyname( fname)
, _age( age)
, _phone( phone)
, _mobile( mobile)
, _postcode( postcode)
, _city( city)
, _address( address)
{}
//-----------------------------------------------------------------------------
/*! \brief callback comparison function to sort TAdrData into the data bank class. This function will be used
to generate sort std::sets for fast searching.
\param d1 the first address item
\param d2 the second address item
\param sel the sort selector
\return true if ci1 < ci2, depends from sel
*/
bool operator()( const TAdrData & d1, const TAdrData & d2, ESelector sel) const
{
switch( sel) {
case esName: return d1._name < d2._name;
case esFamilyName: return d1._familyname < d2._familyname;
case esAge: return d1._age < d2._age;
case esPhone: return d1._phone < d2._phone;
case esMobile: return d1._mobile < d2._mobile;
case esPostcode: return d1._postcode < d2._postcode;
case esCity: return d1._city < d2._city;
case esAddress: return d1._address < d2._address;
}
return false;
}
//-----------------------------------------------------------------------------
/*! \brief callback function called by data bank class before insert an item. This function give user
opportunity to control inserting of an new item.
\param ci the address item to insert
\param sel the sort selector
\return one of the EDBCompActionRes values to set insert action
*/
FontEngine::EDBCompActionRes operator()( const TAdrData & /*v*/, ESelector /*sel*/) const
{
}
//-----------------------------------------------------------------------------
std::string _name; //!< the family name
std::string _familyname; //!< the first name
unsigned int _age; //!< the age of person
std::string _phone; //!< the phone number
std::string _mobile; //!< the mobile phone number
unsigned int _postcode; //!< the postcode numer
std::string _city; //!< the city the person live
std::string _address; //!< the address the person live
};
//! \brief create a type of data bank object, this is the instance type of the data bank
//! \brief a iterator type to make it easier for access
typedef TAdrDataBank::iterator TAdrDataBankIT;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! \brief demo main function
int main( int argc, char* argv[])
{
//! create an instance of own data bank type
TAdrDataBank adrDB;
//! Fill some new persons into own data bank with 'insert' function (no living persons are referenced here!)
adrDB.insert( TAdrData( "Max", "Musterman", 32, "030 1234567", "0176 77665544", 13052, "Berlin", "Akazienweg 12a"));
adrDB.insert( TAdrData( "Beate", "Musterman", 28, "030 1234567", "0176 33445566", 13052, "Berlin", "Akazienweg 12a"));
adrDB.insert( TAdrData( "Karl", "Grosse", 65, "030 9988776", "0174 2344567", 13012, "Berlin", "Sommerstr. 1"));
adrDB.insert( TAdrData( "Willi", "Klein", 78, "040 7736635", "0172 12345678", 10012, "Hamburg", "Seeweg 126"));
adrDB.insert( TAdrData( "Sophie", "Klein", 69, "040 7736635", "", 10012, "Hamburg", "Seeweg 126"));
TAdrData adr;
adr._name = "Max";
/*! Search a person called "Max" with 'find' method, the selector will define the search criteria.
It is not necessary to fill out the complete TAdrData struct.
*/
TAdrDataBankIT it( adrDB.find( adr, TAdrData::esName));
//! Check if such item could be found.
if( adrDB.end( TAdrData::esName) != it) {
const TAdrData & maxadr = *it;
adr = maxadr;
adr._name = "Maximilian";
//! Modify the existing item with correct name "Maximilian" here.
adrDB.modify( it, adr);
}
return 0;
}

Member Typedef Documentation

template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
typedef const TIterator FontEngine::TDBank< T, S, N, P >::const_iterator
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
typedef TIterator FontEngine::TDBank< T, S, N, P >::iterator
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
typedef TDataVec FontEngine::TDBank< T, S, N, P >::TDataImportVec
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
typedef TDataVec::size_type FontEngine::TDBank< T, S, N, P >::TDataIndex

Constructor & Destructor Documentation

template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
FontEngine::TDBank< T, S, N, P >::TDBank ( )
inline

default ctor

template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
FontEngine::TDBank< T, S, N, P >::TDBank ( const TDBank< T, S, N, P > &  db)
inline

copy ctor

Parameters
dbdata bank to copy

Member Function Documentation

template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
iterator FontEngine::TDBank< T, S, N, P >::begin ( selector_type  sel) const
inline

get storage iterator from first item with selector

Parameters
selthe comparison selector to get iterator
Returns
first iterator
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
void FontEngine::TDBank< T, S, N, P >::clear ( )
inline

reset data bank storage

template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
size_t FontEngine::TDBank< T, S, N, P >::count ( const value_type &  vt,
selector_type  sel 
) const
inline

get number of value items in same range as given value with selector

Parameters
vtthe search value item
selthe comparison selector
Returns
number of value items in same range as given value
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
bool FontEngine::TDBank< T, S, N, P >::empty ( ) const
inline

return the size state

Returns
true if the data bank is empty
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
iterator FontEngine::TDBank< T, S, N, P >::end ( selector_type  sel) const
inline

get storage iterator from end with selector, this is the invalid iterator for this selector to compare with other iterators

Parameters
selthe comparison selector to get end iterator
Returns
end iterator
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
iterator FontEngine::TDBank< T, S, N, P >::erase ( const iterator it)
inline

earse value item from storage with iterator

Parameters
itan valid iterator
Returns
the following iterator can be end
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
iterator FontEngine::TDBank< T, S, N, P >::find ( const value_type &  vt,
selector_type  sel 
) const
inline

find storage first iterator from given value with selector

Parameters
vtthe search value item
selthe comparison selector
Returns
storage first iterator in same range as given value with selector
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
void FontEngine::TDBank< T, S, N, P >::import ( TDataImportVec data)
inline

import from value array into own instance

Parameters
datathe value array
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
void FontEngine::TDBank< T, S, N, P >::insert ( const value_type &  vt)
inline

insert a new value item into data bank storage this function will call the the comparison function object, see struct TDBComp

Parameters
vtthe new value item
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
iterator FontEngine::TDBank< T, S, N, P >::lower_bound ( const value_type &  vt,
selector_type  sel 
) const
inline

get storage first iterator in same range as given value with selector

Parameters
vtthe search value item
selthe comparison selector
Returns
storage first iterator from same range as given value with selector
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
void FontEngine::TDBank< T, S, N, P >::merge ( const TDBank< T, S, N, P > &  db,
selector_type  sel 
)
inline

merge from other data bank storage into own instance with selector

Parameters
dbother data bank instance
selthe comparison selector
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
void FontEngine::TDBank< T, S, N, P >::modify ( const iterator it,
const value_type &  vt 
)
inline

modify existing value item with iterator

Parameters
itan valid iterator
vtthe new value to replace
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
TDBank& FontEngine::TDBank< T, S, N, P >::operator= ( const TDBank< T, S, N, P > &  db)
inline

assignment operator

Parameters
dbdata bank to copy
Returns
this
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
bool FontEngine::TDBank< T, S, N, P >::operator== ( const TDBank< T, S, N, P > &  db) const
inline

to compare two objects of struct TDBank

Parameters
dbinstance to compare
Returns
true if this is equal to db
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
const value_type& FontEngine::TDBank< T, S, N, P >::operator[] ( TDataIndex  didx) const
inline

index operator

Parameters
didxindex into data bank storage must be valid
Returns
reference to indexed value
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
size_t FontEngine::TDBank< T, S, N, P >::size ( ) const
inline

return the size of data bank storage

Returns
the data bank size
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
size_t FontEngine::TDBank< T, S, N, P >::size ( selector_type  sel) const
inline

return the size of data bank storage with selector

Parameters
selthe comparison selector to get size
Returns
the data bank size
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
void FontEngine::TDBank< T, S, N, P >::swap ( TDBank< T, S, N, P > &  db)
inline

swap all storage date between other data bank instance

Parameters
dbother data bank instance
template<typename T, typename S, size_t N, typename P = TDBComp< T, S >>
iterator FontEngine::TDBank< T, S, N, P >::upper_bound ( const value_type &  vt,
selector_type  sel 
) const
inline

get storage first iterator from outside same range as given value with selector

Parameters
vtthe search value item
selthe comparison selector
Returns
storage first iterator from outside same range as given value with selector

The documentation for this class was generated from the following file:
InsideFont and ADI-FontEngine : Andreas Dippe, © 2013
http://www.insidefont.de