Main MRPT website > C++ reference for MRPT 1.5.9
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Attributes
mrpt::utils::CSimpleDatabase Class Reference

Detailed Description

This class impements a very simple database system.

A database is a collection of tables, each one being a CSimpleDatabaseTable object. Tables are a rectangular arrrangement of cells, organized as records of fields. There are XML export/import methods in saveAsXML, loadFromXML.

Note
This class is NOT safe for read/write access from different threads. If needed, use critical sections.
See also
CSimpleDatabaseTable

Definition at line 122 of file CSimpleDatabase.h.

#include <mrpt/utils/CSimpleDatabase.h>

Inheritance diagram for mrpt::utils::CSimpleDatabase:
Inheritance graph

Public Member Functions

voidoperator new (size_t size)
 
voidoperator new[] (size_t size)
 
void operator delete (void *ptr) throw ()
 
void operator delete[] (void *ptr) throw ()
 
void operator delete (void *memory, void *ptr) throw ()
 
voidoperator new (size_t size, const std::nothrow_t &) throw ()
 
void operator delete (void *ptr, const std::nothrow_t &) throw ()
 
 CSimpleDatabase ()
 Default constructor. More...
 
virtual ~CSimpleDatabase ()
 Destructor. More...
 
void clear ()
 Clears the DB. More...
 
CSimpleDatabaseTablePtr createTable (const std::string &name)
 Creates a new table in the DB, initially empty. More...
 
CSimpleDatabaseTablePtr getTable (const std::string &tableName)
 Returns the table with the indicated name. More...
 
void dropTable (const std::string &tableName)
 Deletes the given table. More...
 
void renameTable (const std::string &tableName, const std::string &newTableName)
 Changes the name of a given table. More...
 
CSimpleDatabaseTablePtr getTable (size_t tableIndex)
 Returns the table by index. More...
 
size_t tablesCount () const
 Returns the tables count in the DB. More...
 
std::string tablesName (size_t tableIndex) const
 Returns the tables names in the DB. More...
 
bool saveAsXML (const std::string &fileName) const
 Saves this database as a XML file. More...
 
bool loadFromXML (const std::string &fileName)
 Loads the content of this database from a a XML file. More...
 
virtual mxArraywriteToMatlab () const
 Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class. More...
 
CObjectclone () const
 Cloning interface for smart pointers. More...
 
RTTI classes and functions
mrpt::utils::CObjectPtr duplicateGetSmartPtr () const
 Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer). More...
 

Static Public Member Functions

static voidoperator new (size_t size, void *ptr)
 

Static Public Attributes

static const mrpt::utils::TRuntimeClassId classCObject
 
RTTI stuff
static const mrpt::utils::TRuntimeClassId classCSerializable
 

Protected Member Functions

CSerializable virtual methods
void writeToStream (mrpt::utils::CStream &out, int *getVersion) const
 Introduces a pure virtual method responsible for writing to a CStream. More...
 
void readFromStream (mrpt::utils::CStream &in, int version)
 Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori. More...
 

Private Types

typedef std::map< std::string, CSimpleDatabaseTablePtr > TTableList
 The tables of the DB indexed by their names: More...
 
typedef std::map< std::string, CSimpleDatabaseTablePtr >::iterator iterator
 
typedef std::map< std::string, CSimpleDatabaseTablePtr >::const_iterator const_iterator
 

Private Attributes

TTableList m_tables
 

RTTI stuff

typedef CSimpleDatabasePtr Ptr
 
typedef CSimpleDatabasePtr ConstPtr
 
static mrpt::utils::CLASSINIT _init_CSimpleDatabase
 
static mrpt::utils::TRuntimeClassId classCSimpleDatabase
 
static const mrpt::utils::TRuntimeClassIdclassinfo
 
static const mrpt::utils::TRuntimeClassId_GetBaseClass ()
 
virtual const mrpt::utils::TRuntimeClassIdGetRuntimeClass () const
 Returns information about the class of an object in runtime. More...
 
virtual mrpt::utils::CObjectduplicate () const
 Returns a copy of the object, indepently of its class. More...
 
static mrpt::utils::CObjectCreateObject ()
 
static CSimpleDatabasePtr Create ()
 

Member Typedef Documentation

◆ const_iterator

typedef std::map<std::string, CSimpleDatabaseTablePtr>::const_iterator mrpt::utils::CSimpleDatabase::const_iterator
private

Definition at line 193 of file CSimpleDatabase.h.

◆ ConstPtr

typedef CSimpleDatabasePtr mrpt::utils::CSimpleDatabase::ConstPtr

Definition at line 125 of file CSimpleDatabase.h.

◆ iterator

typedef std::map<std::string, CSimpleDatabaseTablePtr>::iterator mrpt::utils::CSimpleDatabase::iterator
private

Definition at line 192 of file CSimpleDatabase.h.

◆ Ptr

typedef CSimpleDatabasePtr mrpt::utils::CSimpleDatabase::Ptr

A typedef for the associated smart pointer

Definition at line 125 of file CSimpleDatabase.h.

◆ TTableList

typedef std::map<std::string, CSimpleDatabaseTablePtr> mrpt::utils::CSimpleDatabase::TTableList
private

The tables of the DB indexed by their names:

Definition at line 191 of file CSimpleDatabase.h.

Constructor & Destructor Documentation

◆ CSimpleDatabase()

CSimpleDatabase::CSimpleDatabase ( )

Default constructor.

Definition at line 144 of file CSimpleDatabase.cpp.

◆ ~CSimpleDatabase()

CSimpleDatabase::~CSimpleDatabase ( )
virtual

Destructor.

Definition at line 152 of file CSimpleDatabase.cpp.

References mrpt::utils::clear().

Member Function Documentation

◆ _GetBaseClass()

static const mrpt::utils::TRuntimeClassId* mrpt::utils::CSimpleDatabase::_GetBaseClass ( )
staticprotected

◆ clear()

void CSimpleDatabase::clear ( )

Clears the DB.

Definition at line 160 of file CSimpleDatabase.cpp.

◆ clone()

CObject* mrpt::utils::CObject::clone ( ) const
inlineinherited

Cloning interface for smart pointers.

Definition at line 133 of file CObject.h.

◆ Create()

static CSimpleDatabasePtr mrpt::utils::CSimpleDatabase::Create ( )
static

◆ CreateObject()

static mrpt::utils::CObject* mrpt::utils::CSimpleDatabase::CreateObject ( )
static

◆ createTable()

CSimpleDatabaseTablePtr CSimpleDatabase::createTable ( const std::string name)

Creates a new table in the DB, initially empty.

Definition at line 223 of file CSimpleDatabase.cpp.

References mrpt::utils::CSimpleDatabaseTable::Create().

Referenced by mrpt::hmtslam::CHierarchicalMHMap::dumpAsXMLfile().

◆ dropTable()

void CSimpleDatabase::dropTable ( const std::string tableName)

Deletes the given table.

Exceptions
std::exceptionOn table not found.

Definition at line 555 of file CSimpleDatabase.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.

◆ duplicate()

virtual mrpt::utils::CObject* mrpt::utils::CSimpleDatabase::duplicate ( ) const
virtual

Returns a copy of the object, indepently of its class.

Implements mrpt::utils::CObject.

◆ duplicateGetSmartPtr()

mrpt::utils::CObjectPtr CObject::duplicateGetSmartPtr ( ) const
inlineinherited

Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer).

Definition at line 162 of file CObject.h.

References mrpt::utils::CObjectPtr.

Referenced by mrpt::obs::CRawlog::addActions(), mrpt::slam::CIncrementalMapPartitioner::addMapFrame(), and mrpt::obs::CRawlog::addObservations().

◆ GetRuntimeClass()

virtual const mrpt::utils::TRuntimeClassId* mrpt::utils::CSimpleDatabase::GetRuntimeClass ( ) const
virtual

Returns information about the class of an object in runtime.

Reimplemented from mrpt::utils::CSerializable.

◆ getTable() [1/2]

CSimpleDatabaseTablePtr CSimpleDatabase::getTable ( const std::string tableName)

Returns the table with the indicated name.

Exceptions
std::exceptionOn table not found.

Definition at line 168 of file CSimpleDatabase.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.

Referenced by mrpt::hmtslam::CHierarchicalMHMap::loadFromXMLfile().

◆ getTable() [2/2]

CSimpleDatabaseTablePtr CSimpleDatabase::getTable ( size_t  tableIndex)

Returns the table by index.

Exceptions
std::exceptionOn index out of bounds

Definition at line 184 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ loadFromXML()

bool CSimpleDatabase::loadFromXML ( const std::string fileName)

◆ operator delete() [1/3]

void mrpt::utils::CSimpleDatabase::operator delete ( void ptr)
throw (
)
inline

Definition at line 125 of file CSimpleDatabase.h.

◆ operator delete() [2/3]

void mrpt::utils::CSimpleDatabase::operator delete ( void memory,
void ptr 
)
throw (
)
inline

Definition at line 125 of file CSimpleDatabase.h.

◆ operator delete() [3/3]

void mrpt::utils::CSimpleDatabase::operator delete ( void ptr,
const std::nothrow_t &   
)
throw (
)
inline

Definition at line 125 of file CSimpleDatabase.h.

◆ operator delete[]()

void mrpt::utils::CSimpleDatabase::operator delete[] ( void ptr)
throw (
)
inline

Definition at line 125 of file CSimpleDatabase.h.

◆ operator new() [1/3]

static void* mrpt::utils::CSimpleDatabase::operator new ( size_t  size,
void ptr 
)
inlinestatic

Definition at line 125 of file CSimpleDatabase.h.

◆ operator new() [2/3]

void* mrpt::utils::CSimpleDatabase::operator new ( size_t  size,
const std::nothrow_t &   
)
throw (
)
inline

Definition at line 125 of file CSimpleDatabase.h.

◆ operator new() [3/3]

void* mrpt::utils::CSimpleDatabase::operator new ( size_t  size)
inline

Definition at line 125 of file CSimpleDatabase.h.

◆ operator new[]()

void* mrpt::utils::CSimpleDatabase::operator new[] ( size_t  size)
inline

Definition at line 125 of file CSimpleDatabase.h.

◆ readFromStream()

void CSimpleDatabase::readFromStream ( mrpt::utils::CStream in,
int  version 
)
protectedvirtual

Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori.

Parameters
inThe input binary stream where the object data must read from.
versionThe version of the object stored in the stream: use this version number in your code to know how to read the incoming data.
Exceptions
std::exceptionOn any error, see CStream::ReadBuffer
See also
CStream

Implements mrpt::utils::CSerializable.

Definition at line 53 of file CSimpleDatabase.cpp.

References mrpt::utils::clear(), mrpt::utils::CSimpleDatabaseTable::Create(), MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION, and version.

◆ renameTable()

void CSimpleDatabase::renameTable ( const std::string tableName,
const std::string newTableName 
)

Changes the name of a given table.

Exceptions
std::exceptionOn table not found or new name already existed.

Definition at line 572 of file CSimpleDatabase.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.

◆ saveAsXML()

bool CSimpleDatabase::saveAsXML ( const std::string fileName) const

Saves this database as a XML file.

Returns
false on any error, true if successful.
See also
loadFromXML

Definition at line 420 of file CSimpleDatabase.cpp.

References XMLNode::addAttribute(), XMLNode::addChild(), XMLNode::addText(), XMLNode::createXMLTopNode(), and XMLNode::writeToFile().

Referenced by mrpt::hmtslam::CHierarchicalMHMap::dumpAsXMLfile().

◆ tablesCount()

size_t CSimpleDatabase::tablesCount ( ) const

Returns the tables count in the DB.

Definition at line 200 of file CSimpleDatabase.cpp.

◆ tablesName()

string CSimpleDatabase::tablesName ( size_t  tableIndex) const

Returns the tables names in the DB.

Exceptions
std::exceptionOn index out of bounds

Definition at line 208 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ writeToMatlab()

virtual mxArray* mrpt::utils::CSerializable::writeToMatlab ( ) const
inlinevirtualinherited

Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class.

Returns
A new mxArray (caller is responsible of memory freeing) or NULL is class does not support conversion to MATLAB.

Definition at line 79 of file CSerializable.h.

◆ writeToStream()

void CSimpleDatabase::writeToStream ( mrpt::utils::CStream out,
int *  getVersion 
) const
protectedvirtual

Introduces a pure virtual method responsible for writing to a CStream.

This can not be used directly be users, instead use "stream << object;" for writing it to a stream.

Parameters
outThe output binary stream where object must be dumped.
getVersionIf NULL, the object must be dumped. If not, only the version of the object dump must be returned in this pointer. This enables the versioning of objects dumping and backward compatibility with previously stored data.
Exceptions
std::exceptionOn any error, see CStream::WriteBuffer
See also
CStream

Implements mrpt::utils::CSerializable.

Definition at line 33 of file CSimpleDatabase.cpp.

Member Data Documentation

◆ _init_CSimpleDatabase

mrpt::utils::CLASSINIT mrpt::utils::CSimpleDatabase::_init_CSimpleDatabase
staticprotected

Definition at line 125 of file CSimpleDatabase.h.

◆ classCObject

const mrpt::utils::TRuntimeClassId mrpt::utils::CObject::classCObject
staticinherited

Definition at line 118 of file CObject.h.

◆ classCSerializable

const mrpt::utils::TRuntimeClassId mrpt::utils::CSerializable::classCSerializable
staticinherited

Definition at line 42 of file CSerializable.h.

◆ classCSimpleDatabase

mrpt::utils::TRuntimeClassId mrpt::utils::CSimpleDatabase::classCSimpleDatabase
static

Definition at line 125 of file CSimpleDatabase.h.

◆ classinfo

const mrpt::utils::TRuntimeClassId* mrpt::utils::CSimpleDatabase::classinfo
static

Definition at line 125 of file CSimpleDatabase.h.

◆ m_tables

TTableList mrpt::utils::CSimpleDatabase::m_tables
private

Definition at line 195 of file CSimpleDatabase.h.




Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020