VICUS Library
Documentation of Vicus library
Loading...
Searching...
No Matches
VICUS::Database< T > Class Template Reference

#include <VICUS_Database.h>

Public Member Functions

 Database (unsigned int userIDSpaceStart)
 
const T * operator[] (unsigned int id) const
 
T * operator[] (unsigned int id)
 
const T * findEqual (const T &elem) const
 
std::map< unsignedint, T >::const_iterator begin () const
 
std::map< unsignedint, T >::const_iterator end () const
 
std::map< unsignedint, T >::iterator begin ()
 
std::map< unsignedint, T >::iterator end ()
 
size_t size () const
 
bool empty () const
 
void setData (const std::vector< T > &data)
 
void import (const Database< T > &other)
 
unsigned int add (T &newData, unsigned int suggestedId=0)
 
void remove (unsigned int id)
 
void removeUserElements ()
 
void removeLocalElements ()
 
void removeNotReferencedLocalElements ()
 
void clearChildren ()
 
void readXML (const IBK::Path &fname, const std::string &topLevelTag, const std::string &childTagName, bool builtIn=false)
 
void writeXML (const IBK::Path &fname, const std::string &topLevelTag) const
 

Public Attributes

bool m_modified = false
 

Detailed Description

template<typename T>
class VICUS::Database< T >

Wrapper class for different databases. Template argument classes must provide a public bool member m_builtIn, and the functions readXML(const TiXmlElement * element) and writeXML(TiXmlElement * parent) const.

Usage:

m. .... set parameters
unsigned ínt newId = materials.add(m);
const VICUS::Material * materials[newId]; // -> either VICUS::Material pointer or nullptr, if object doesn't exist
Definition VICUS_Database.h:57
unsigned int add(T &newData, unsigned int suggestedId=0)
Definition VICUS_Database.h:139
Definition VICUS_Material.h:44

Constructor & Destructor Documentation

◆ Database()

template<typename T >
VICUS::Database< T >::Database ( unsigned int  userIDSpaceStart)
inline

Member Function Documentation

◆ add()

template<typename T >
unsigned int VICUS::Database< T >::add ( T &  newData,
unsigned int  suggestedId = 0 
)
inline

Adds a new item to the database.

Parameters
newDataNew object to be added.
suggestedIdID of object to insert (possibly when adding this data object from a project file), or 0, if object was newly created and needs a new ID anyway.
Note
New items are never built-in and will be local DB elements, automatically.

◆ begin() [1/2]

template<typename T >
std::map< unsignedint, T >::iterator VICUS::Database< T >::begin ( )
inline

Returns begin for iterator-type access to data store.

◆ begin() [2/2]

template<typename T >
std::map< unsignedint, T >::const_iterator VICUS::Database< T >::begin ( ) const
inline

Returns begin for iterator-type read-only access to data store.

◆ clearChildren()

template<typename T >
void VICUS::Database< T >::clearChildren ( )
inline

Local utility function which clears parents and children references using const cast

◆ empty()

template<typename T >
bool VICUS::Database< T >::empty ( ) const
inline

Returns true if database is empty.

◆ end() [1/2]

template<typename T >
std::map< unsignedint, T >::iterator VICUS::Database< T >::end ( )
inline

Returns end for iterator-type access to data store.

◆ end() [2/2]

template<typename T >
std::map< unsignedint, T >::const_iterator VICUS::Database< T >::end ( ) const
inline

Returns end for iterator-type read-only access to data store.

◆ findEqual()

template<typename T >
const T * VICUS::Database< T >::findEqual ( const T &  elem) const
inline

Tries to find an element in the DB that matches content-wise the provided element (i.e. ignores ID during comparison, calls T::equal()).

Returns
Returns nullptr if no such element exists, otherwise a pointer to the respective existing element.

◆ import()

template<typename T >
void VICUS::Database< T >::import ( const Database< T > &  other)
inline

Imports elements from other DB that do not yet exist in current DB. The imported DB is expected to holds only IDs that are not yet present in the current DB. For each element with duplicate ID a warning message is issued in IBK_message().

◆ operator[]() [1/2]

template<typename T >
T * VICUS::Database< T >::operator[] ( unsigned int  id)
inline

Returns database element by ID, or nullptr if no element exists with this ID.

◆ operator[]() [2/2]

template<typename T >
const T * VICUS::Database< T >::operator[] ( unsigned int  id) const
inline

Returns const database element by ID, or nullptr if no element exists with this ID.

◆ readXML()

template<typename T >
void VICUS::Database< T >::readXML ( const IBK::Path &  fname,
const std::string &  topLevelTag,
const std::string &  childTagName,
bool  builtIn = false 
)
inline

Reads database from xml file. Usage:

// read built-in material DB
db.readXML("db_materials.xml", "Materials", "Material", true);
Warning
Throws an IBK::Exception if reading fails.

◆ remove()

template<typename T >
void VICUS::Database< T >::remove ( unsigned int  id)
inline

Removes a database element identified by its ID

Warning
Throws an IBK::Exception if no element with given ID exists.

◆ removeLocalElements()

template<typename T >
void VICUS::Database< T >::removeLocalElements ( )
inline

Removes all user elements which are defined as local

◆ removeNotReferencedLocalElements()

template<typename T >
void VICUS::Database< T >::removeNotReferencedLocalElements ( )
inline

Removes all local, not-referenced elements

◆ removeUserElements()

template<typename T >
void VICUS::Database< T >::removeUserElements ( )
inline

Removes all user-defined elements (element not marked as built-in)

◆ setData()

template<typename T >
void VICUS::Database< T >::setData ( const std::vector< T > &  data)
inline

Initializes database with data from a vector. Throws an exception if duplicate IDs are found.

◆ size()

template<typename T >
size_t VICUS::Database< T >::size ( ) const
inline

Returns number of DB elements.

◆ writeXML()

template<typename T >
void VICUS::Database< T >::writeXML ( const IBK::Path &  fname,
const std::string &  topLevelTag 
) const
inline

Writes database to XML file. Usage:

// write user material DB (writes only those materials marked not as built-in and not as local)
db.writeXML("db_materials.xml", "Materials");

Member Data Documentation

◆ m_modified

template<typename T >
bool VICUS::Database< T >::m_modified = false

Modified marker, should be changed to true, whenever a database object was modified. Will be automatically set to true in functions add() and remove().


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