MRPT  1.9.9
mrpt::db::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 119 of file CSimpleDatabase.h.

#include <mrpt/db/CSimpleDatabase.h>

Inheritance diagram for mrpt::db::CSimpleDatabase:

Public Member Functions

 CSimpleDatabase ()
 Default constructor. More...
 
 ~CSimpleDatabase () override
 Destructor. More...
 
void clear ()
 Clears the DB. More...
 
CSimpleDatabaseTable::Ptr createTable (const std::string &name)
 Creates a new table in the DB, initially empty. More...
 
CSimpleDatabaseTable::Ptr 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...
 
CSimpleDatabaseTable::Ptr 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...
 
RTTI classes and functions for polymorphic hierarchies
mrpt::rtti::CObject::Ptr duplicateGetSmartPtr () const
 Makes a deep copy of the object and returns a smart pointer to it. More...
 

Protected Member Functions

CSerializable virtual methods
uint8_t serializeGetVersion () const override
 Must return the current versioning number of the object. More...
 
void serializeTo (mrpt::serialization::CArchive &out) const override
 Pure virtual method for writing (serializing) to an abstract archive. More...
 
void serializeFrom (mrpt::serialization::CArchive &in, uint8_t serial_version) override
 Pure virtual method for reading (deserializing) from an abstract archive. More...
 
CSerializable virtual methods
virtual void serializeTo (CSchemeArchiveBase &out) const
 Virtual method for writing (serializing) to an abstract schema based archive. More...
 
virtual void serializeFrom (CSchemeArchiveBase &in)
 Virtual method for reading (deserializing) from an abstract schema based archive. More...
 

Private Types

using TTableList = std::map< std::string, CSimpleDatabaseTable::Ptr >
 The tables of the DB indexed by their names: More...
 
using iterator = std::map< std::string, CSimpleDatabaseTable::Ptr >::iterator
 
using const_iterator = std::map< std::string, CSimpleDatabaseTable::Ptr >::const_iterator
 

Private Attributes

TTableList m_tables
 

RTTI stuff

using Ptr = std::shared_ptr< CSimpleDatabase >
 
using ConstPtr = std::shared_ptr< const CSimpleDatabase >
 
using UniquePtr = std::unique_ptr< CSimpleDatabase >
 
using ConstUniquePtr = std::unique_ptr< const CSimpleDatabase >
 
static const mrpt::rtti::TRuntimeClassId runtimeClassId
 
static constexpr const char * className = "CSimpleDatabase"
 
static const mrpt::rtti::TRuntimeClassId_GetBaseClass ()
 
static constexpr auto getClassName ()
 
static const mrpt::rtti::TRuntimeClassIdGetRuntimeClassIdStatic ()
 
static std::shared_ptr< CObjectCreateObject ()
 
template<typename... Args>
static Ptr Create (Args &&... args)
 
template<typename Alloc , typename... Args>
static Ptr CreateAlloc (const Alloc &alloc, Args &&... args)
 
template<typename... Args>
static UniquePtr CreateUnique (Args &&... args)
 
virtual const mrpt::rtti::TRuntimeClassIdGetRuntimeClass () const override
 Returns information about the class of an object in runtime. More...
 
virtual mrpt::rtti::CObjectclone () const override
 Returns a deep copy (clone) of the object, indepently of its class. More...
 

Member Typedef Documentation

◆ const_iterator

◆ ConstPtr

◆ ConstUniquePtr

Definition at line 121 of file CSimpleDatabase.h.

◆ iterator

◆ Ptr

A type for the associated smart pointer

Definition at line 121 of file CSimpleDatabase.h.

◆ TTableList

The tables of the DB indexed by their names:

Definition at line 185 of file CSimpleDatabase.h.

◆ UniquePtr

Definition at line 121 of file CSimpleDatabase.h.

Constructor & Destructor Documentation

◆ CSimpleDatabase()

CSimpleDatabase::CSimpleDatabase ( )
default

Default constructor.

◆ ~CSimpleDatabase()

CSimpleDatabase::~CSimpleDatabase ( )
override

Destructor.

Definition at line 126 of file CSimpleDatabase.cpp.

References mrpt::containers::clear().

Here is the call graph for this function:

Member Function Documentation

◆ _GetBaseClass()

static const mrpt::rtti::TRuntimeClassId* mrpt::db::CSimpleDatabase::_GetBaseClass ( )
staticprotected

◆ clear()

void CSimpleDatabase::clear ( )

Clears the DB.

Definition at line 130 of file CSimpleDatabase.cpp.

◆ clone()

virtual mrpt::rtti::CObject* mrpt::db::CSimpleDatabase::clone ( ) const
overridevirtual

Returns a deep copy (clone) of the object, indepently of its class.

Implements mrpt::rtti::CObject.

◆ Create()

template<typename... Args>
static Ptr mrpt::db::CSimpleDatabase::Create ( Args &&...  args)
inlinestatic

Definition at line 121 of file CSimpleDatabase.h.

◆ CreateAlloc()

template<typename Alloc , typename... Args>
static Ptr mrpt::db::CSimpleDatabase::CreateAlloc ( const Alloc &  alloc,
Args &&...  args 
)
inlinestatic

Definition at line 121 of file CSimpleDatabase.h.

◆ CreateObject()

static std::shared_ptr<CObject> mrpt::db::CSimpleDatabase::CreateObject ( )
static

◆ createTable()

CSimpleDatabaseTable::Ptr CSimpleDatabase::createTable ( const std::string name)

Creates a new table in the DB, initially empty.

Definition at line 184 of file CSimpleDatabase.cpp.

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

Here is the caller graph for this function:

◆ CreateUnique()

template<typename... Args>
static UniquePtr mrpt::db::CSimpleDatabase::CreateUnique ( Args &&...  args)
inlinestatic

Definition at line 121 of file CSimpleDatabase.h.

◆ dropTable()

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

Deletes the given table.

Exceptions
std::exceptionOn table not found.

Definition at line 492 of file CSimpleDatabase.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.

◆ duplicateGetSmartPtr()

mrpt::rtti::CObject::Ptr CObject::duplicateGetSmartPtr ( ) const
inlineinherited

Makes a deep copy of the object and returns a smart pointer to it.

Definition at line 191 of file CObject.h.

References mrpt::rtti::CObject::clone().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getClassName()

static constexpr auto mrpt::db::CSimpleDatabase::getClassName ( )
inlinestatic

Definition at line 121 of file CSimpleDatabase.h.

◆ GetRuntimeClass()

virtual const mrpt::rtti::TRuntimeClassId* mrpt::db::CSimpleDatabase::GetRuntimeClass ( ) const
overridevirtual

Returns information about the class of an object in runtime.

Reimplemented from mrpt::serialization::CSerializable.

◆ GetRuntimeClassIdStatic()

static const mrpt::rtti::TRuntimeClassId& mrpt::db::CSimpleDatabase::GetRuntimeClassIdStatic ( )
static

◆ getTable() [1/2]

CSimpleDatabaseTable::Ptr CSimpleDatabase::getTable ( const std::string tableName)

Returns the table with the indicated name.

Exceptions
std::exceptionOn table not found.

Definition at line 134 of file CSimpleDatabase.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.

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

Here is the caller graph for this function:

◆ getTable() [2/2]

CSimpleDatabaseTable::Ptr CSimpleDatabase::getTable ( size_t  tableIndex)

Returns the table by index.

Exceptions
std::exceptionOn index out of bounds

Definition at line 150 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ loadFromXML()

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

Loads the content of this database from a a XML file.

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

Definition at line 410 of file CSimpleDatabase.cpp.

References ASSERT_, mrpt::containers::clear(), eXMLErrorNone, XMLNode::getAttribute(), XMLNode::getChildNode(), XMLNode::getError(), XMLNode::isEmpty(), XMLNode::nChildNode(), XMLNode::parseFile(), results, and XMLCSTR.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 508 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 352 of file CSimpleDatabase.cpp.

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ serializeFrom() [1/2]

virtual void mrpt::serialization::CSerializable::serializeFrom ( CSchemeArchiveBase in)
inlineprotectedvirtualinherited

Virtual method for reading (deserializing) from an abstract schema based archive.

Definition at line 74 of file CSerializable.h.

References mrpt::serialization::CSerializable::GetRuntimeClass(), and THROW_EXCEPTION.

Here is the call graph for this function:

◆ serializeFrom() [2/2]

void CSimpleDatabase::serializeFrom ( mrpt::serialization::CArchive in,
uint8_t  serial_version 
)
overrideprotectedvirtual

Pure virtual method for reading (deserializing) from an abstract archive.

Users don't call this method directly. Instead, use stream >> object;.

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 I/O error

Implements mrpt::serialization::CSerializable.

Definition at line 43 of file CSimpleDatabase.cpp.

References mrpt::containers::clear(), and MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION.

Here is the call graph for this function:

◆ serializeGetVersion()

uint8_t CSimpleDatabase::serializeGetVersion ( ) const
overrideprotectedvirtual

Must return the current versioning number of the object.

Start in zero for new classes, and increments each time there is a change in the stored format.

Implements mrpt::serialization::CSerializable.

Definition at line 30 of file CSimpleDatabase.cpp.

◆ serializeTo() [1/2]

virtual void mrpt::serialization::CSerializable::serializeTo ( CSchemeArchiveBase out) const
inlineprotectedvirtualinherited

Virtual method for writing (serializing) to an abstract schema based archive.

Definition at line 64 of file CSerializable.h.

References mrpt::serialization::CSerializable::GetRuntimeClass(), and THROW_EXCEPTION.

Here is the call graph for this function:

◆ serializeTo() [2/2]

void CSimpleDatabase::serializeTo ( mrpt::serialization::CArchive out) const
overrideprotectedvirtual

Pure virtual method for writing (serializing) to an abstract archive.

Users don't call this method directly. Instead, use stream << object;.

Exceptions
std::exceptionOn any I/O error

Implements mrpt::serialization::CSerializable.

Definition at line 31 of file CSimpleDatabase.cpp.

◆ tablesCount()

size_t CSimpleDatabase::tablesCount ( ) const

Returns the tables count in the DB.

Definition at line 165 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 169 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ writeToMatlab()

virtual mxArray* mrpt::serialization::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 nullptr is class does not support conversion to MATLAB.

Definition at line 90 of file CSerializable.h.

Member Data Documentation

◆ className

constexpr const char* mrpt::db::CSimpleDatabase::className = "CSimpleDatabase"
static

Definition at line 121 of file CSimpleDatabase.h.

◆ m_tables

TTableList mrpt::db::CSimpleDatabase::m_tables
private

Definition at line 190 of file CSimpleDatabase.h.

◆ runtimeClassId

const mrpt::rtti::TRuntimeClassId mrpt::db::CSimpleDatabase::runtimeClassId
staticprotected

Definition at line 121 of file CSimpleDatabase.h.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 765b969e7 Sun Sep 22 19:55:28 2019 +0200 at dom sep 22 20:00:14 CEST 2019