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.
Definition at line 123 of file CSimpleDatabase.h.
#include <mrpt/utils/CSimpleDatabase.h>
Public Member Functions | |
void * | operator new (size_t size) |
void * | operator new[] (size_t size) |
void | operator delete (void *ptr) noexcept |
void | operator delete[] (void *ptr) noexcept |
void | operator delete (void *memory, void *ptr) noexcept |
void * | operator new (size_t size, const std::nothrow_t &) noexcept |
void | operator delete (void *ptr, const std::nothrow_t &) noexcept |
CSimpleDatabase () | |
Default constructor. More... | |
virtual | ~CSimpleDatabase () |
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 mxArray * | writeToMatlab () 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 | |
mrpt::utils::CObject::Ptr | 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 void * | operator new (size_t size, void *ptr) |
Protected Member Functions | |
CSerializable virtual methods | |
void | writeToStream (mrpt::utils::CStream &out, int *getVersion) const override |
Introduces a pure virtual method responsible for writing to a CStream. More... | |
void | readFromStream (mrpt::utils::CStream &in, int version) override |
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, CSimpleDatabaseTable::Ptr > | TTableList |
The tables of the DB indexed by their names: More... | |
typedef std::map< std::string, CSimpleDatabaseTable::Ptr >::iterator | iterator |
typedef std::map< std::string, CSimpleDatabaseTable::Ptr >::const_iterator | const_iterator |
Private Attributes | |
TTableList | m_tables |
RTTI stuff | |
using | Ptr = std::shared_ptr< CSimpleDatabase > |
using | ConstPtr = std::shared_ptr< const CSimpleDatabase > |
static mrpt::utils::CLASSINIT | _init_CSimpleDatabase |
static const mrpt::utils::TRuntimeClassId | runtimeClassId |
static constexpr const char * | className = "CSimpleDatabase" |
static const mrpt::utils::TRuntimeClassId * | _GetBaseClass () |
static const mrpt::utils::TRuntimeClassId & | GetRuntimeClassIdStatic () |
static mrpt::utils::CObject * | CreateObject () |
template<typename... Args> | |
static Ptr | Create (Args &&... args) |
virtual const mrpt::utils::TRuntimeClassId * | GetRuntimeClass () const override |
Returns information about the class of an object in runtime. More... | |
virtual mrpt::utils::CObject * | clone () const override |
Returns a deep copy (clone) of the object, indepently of its class. More... | |
|
private |
Definition at line 192 of file CSimpleDatabase.h.
using mrpt::utils::CSimpleDatabase::ConstPtr = std::shared_ptr<const CSimpleDatabase > |
Definition at line 125 of file CSimpleDatabase.h.
|
private |
Definition at line 190 of file CSimpleDatabase.h.
using mrpt::utils::CSimpleDatabase::Ptr = std::shared_ptr< CSimpleDatabase > |
A typedef for the associated smart pointer
Definition at line 125 of file CSimpleDatabase.h.
|
private |
The tables of the DB indexed by their names:
Definition at line 189 of file CSimpleDatabase.h.
CSimpleDatabase::CSimpleDatabase | ( | ) |
Default constructor.
Definition at line 142 of file CSimpleDatabase.cpp.
|
virtual |
Destructor.
Definition at line 146 of file CSimpleDatabase.cpp.
References mrpt::utils::clear().
|
staticprotected |
void CSimpleDatabase::clear | ( | ) |
Clears the DB.
Definition at line 150 of file CSimpleDatabase.cpp.
|
overridevirtual |
Returns a deep copy (clone) of the object, indepently of its class.
Implements mrpt::utils::CObject.
|
inlinestatic |
Definition at line 125 of file CSimpleDatabase.h.
|
static |
CSimpleDatabaseTable::Ptr CSimpleDatabase::createTable | ( | const std::string & | name | ) |
Creates a new table in the DB, initially empty.
Definition at line 205 of file CSimpleDatabase.cpp.
Referenced by mrpt::hmtslam::CHierarchicalMHMap::dumpAsXMLfile().
void CSimpleDatabase::dropTable | ( | const std::string & | tableName | ) |
Deletes the given table.
std::exception | On table not found. |
Definition at line 518 of file CSimpleDatabase.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.
|
overridevirtual |
Returns information about the class of an object in runtime.
Reimplemented from mrpt::utils::CSerializable.
|
static |
CSimpleDatabaseTable::Ptr CSimpleDatabase::getTable | ( | const std::string & | tableName | ) |
Returns the table with the indicated name.
std::exception | On table not found. |
Definition at line 154 of file CSimpleDatabase.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.
Referenced by mrpt::hmtslam::CHierarchicalMHMap::loadFromXMLfile().
CSimpleDatabaseTable::Ptr CSimpleDatabase::getTable | ( | size_t | tableIndex | ) |
Returns the table by index.
std::exception | On index out of bounds |
Definition at line 170 of file CSimpleDatabase.cpp.
References ASSERT_, MRPT_END, and MRPT_START.
bool CSimpleDatabase::loadFromXML | ( | const std::string & | fileName | ) |
Loads the content of this database from a a XML file.
Definition at line 433 of file CSimpleDatabase.cpp.
References ASSERT_, mrpt::utils::clear(), XMLResults::error, eXMLErrorNone, XMLNode::getAttribute(), XMLNode::getChildNode(), XMLNode::getError(), XMLNode::isEmpty(), XMLNode::nChildNode(), XMLResults::nColumn, XMLResults::nLine, XMLNode::parseFile(), and XMLCSTR.
Referenced by mrpt::hmtslam::CHierarchicalMHMap::loadFromXMLfile().
Definition at line 125 of file CSimpleDatabase.h.
Definition at line 125 of file CSimpleDatabase.h.
|
inlinenoexcept |
Definition at line 125 of file CSimpleDatabase.h.
Definition at line 125 of file CSimpleDatabase.h.
|
inline |
Definition at line 125 of file CSimpleDatabase.h.
Definition at line 125 of file CSimpleDatabase.h.
|
inlinenoexcept |
Definition at line 125 of file CSimpleDatabase.h.
|
inline |
Definition at line 125 of file CSimpleDatabase.h.
|
overrideprotectedvirtual |
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.
in | The input binary stream where the object data must read from. |
version | The version of the object stored in the stream: use this version number in your code to know how to read the incoming data. |
std::exception | On any error, see CStream::ReadBuffer |
Implements mrpt::utils::CSerializable.
Definition at line 54 of file CSimpleDatabase.cpp.
References mrpt::utils::clear(), and MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION.
void CSimpleDatabase::renameTable | ( | const std::string & | tableName, |
const std::string & | newTableName | ||
) |
Changes the name of a given table.
std::exception | On table not found or new name already existed. |
Definition at line 534 of file CSimpleDatabase.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.
bool CSimpleDatabase::saveAsXML | ( | const std::string & | fileName | ) | const |
Saves this database as a XML file.
Definition at line 375 of file CSimpleDatabase.cpp.
References XMLNode::addAttribute(), XMLNode::addChild(), XMLNode::addText(), XMLNode::createXMLTopNode(), and XMLNode::writeToFile().
Referenced by mrpt::hmtslam::CHierarchicalMHMap::dumpAsXMLfile().
size_t CSimpleDatabase::tablesCount | ( | ) | const |
Returns the tables count in the DB.
Definition at line 186 of file CSimpleDatabase.cpp.
string CSimpleDatabase::tablesName | ( | size_t | tableIndex | ) | const |
Returns the tables names in the DB.
std::exception | On index out of bounds |
Definition at line 190 of file CSimpleDatabase.cpp.
References ASSERT_, MRPT_END, and MRPT_START.
|
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.
mxArray
(caller is responsible of memory freeing) or nullptr is class does not support conversion to MATLAB. Definition at line 89 of file CSerializable.h.
|
overrideprotectedvirtual |
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.
out | The output binary stream where object must be dumped. |
getVersion | If nullptr, 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. |
std::exception | On any error, see CStream::WriteBuffer |
Implements mrpt::utils::CSerializable.
Definition at line 33 of file CSimpleDatabase.cpp.
|
staticprotected |
Definition at line 125 of file CSimpleDatabase.h.
|
static |
Definition at line 125 of file CSimpleDatabase.h.
|
private |
Definition at line 194 of file CSimpleDatabase.h.
|
staticprotected |
Definition at line 125 of file CSimpleDatabase.h.
Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019 |