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 121 of file CSimpleDatabase.h.
#include <mrpt/db/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... | |
Static Public Member Functions | |
static void * | operator new (size_t size, void *ptr) |
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... | |
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 mrpt::rtti::CLASSINIT | _init_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::TRuntimeClassId & | GetRuntimeClassIdStatic () |
static mrpt::rtti::CObject * | CreateObject () |
template<typename... Args> | |
static Ptr | Create (Args &&... args) |
template<typename... Args> | |
static UniquePtr | CreateUnique (Args &&... args) |
virtual const mrpt::rtti::TRuntimeClassId * | GetRuntimeClass () const override |
Returns information about the class of an object in runtime. More... | |
virtual mrpt::rtti::CObject * | clone () const override |
Returns a deep copy (clone) of the object, indepently of its class. More... | |
|
private |
Definition at line 190 of file CSimpleDatabase.h.
using mrpt::db::CSimpleDatabase::ConstPtr = std::shared_ptr<const CSimpleDatabase > |
Definition at line 123 of file CSimpleDatabase.h.
using mrpt::db::CSimpleDatabase::ConstUniquePtr = std::unique_ptr<const CSimpleDatabase > |
Definition at line 123 of file CSimpleDatabase.h.
|
private |
Definition at line 188 of file CSimpleDatabase.h.
using mrpt::db::CSimpleDatabase::Ptr = std::shared_ptr< CSimpleDatabase > |
A type for the associated smart pointer
Definition at line 123 of file CSimpleDatabase.h.
|
private |
The tables of the DB indexed by their names:
Definition at line 187 of file CSimpleDatabase.h.
using mrpt::db::CSimpleDatabase::UniquePtr = std::unique_ptr< CSimpleDatabase > |
Definition at line 123 of file CSimpleDatabase.h.
CSimpleDatabase::CSimpleDatabase | ( | ) |
Default constructor.
Definition at line 122 of file CSimpleDatabase.cpp.
|
virtual |
Destructor.
Definition at line 126 of file CSimpleDatabase.cpp.
References mrpt::containers::clear().
|
staticprotected |
void CSimpleDatabase::clear | ( | ) |
Clears the DB.
Definition at line 130 of file CSimpleDatabase.cpp.
|
overridevirtual |
Returns a deep copy (clone) of the object, indepently of its class.
Implements mrpt::rtti::CObject.
|
inlinestatic |
Definition at line 123 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 184 of file CSimpleDatabase.cpp.
Referenced by mrpt::hmtslam::CHierarchicalMHMap::dumpAsXMLfile().
|
inlinestatic |
Definition at line 123 of file CSimpleDatabase.h.
void CSimpleDatabase::dropTable | ( | const std::string & | tableName | ) |
Deletes the given table.
std::exception | On table not found. |
Definition at line 493 of file CSimpleDatabase.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.
|
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 169 of file CObject.h.
References mrpt::rtti::CObject::clone().
Referenced by mrpt::obs::CRawlog::addActions(), and mrpt::obs::CRawlog::addObservations().
|
inlinestaticconstexpr |
Definition at line 123 of file CSimpleDatabase.h.
|
overridevirtual |
Returns information about the class of an object in runtime.
Reimplemented from mrpt::serialization::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 134 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 150 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 411 of file CSimpleDatabase.cpp.
References ASSERT_, mrpt::containers::clear(), eXMLErrorNone, XMLNode::getAttribute(), XMLNode::getChildNode(), XMLNode::getError(), XMLNode::getName(), XMLNode::getText(), XMLNode::isEmpty(), XMLNode::nChildNode(), XMLNode::parseFile(), results, and XMLCSTR.
Referenced by mrpt::hmtslam::CHierarchicalMHMap::loadFromXMLfile().
Definition at line 123 of file CSimpleDatabase.h.
Definition at line 123 of file CSimpleDatabase.h.
|
inlinenoexcept |
Definition at line 123 of file CSimpleDatabase.h.
Definition at line 123 of file CSimpleDatabase.h.
|
inline |
Definition at line 123 of file CSimpleDatabase.h.
|
inlinenoexcept |
Definition at line 123 of file CSimpleDatabase.h.
Definition at line 123 of file CSimpleDatabase.h.
|
inline |
Definition at line 123 of file CSimpleDatabase.h.
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 509 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 353 of file CSimpleDatabase.cpp.
References XMLNode::addAttribute(), XMLNode::addChild(), XMLNode::addText(), XMLNode::createXMLTopNode(), and XMLNode::writeToFile().
Referenced by mrpt::hmtslam::CHierarchicalMHMap::dumpAsXMLfile().
|
overrideprotectedvirtual |
Pure virtual method for reading (deserializing) from an abstract archive.
Users don't call this method directly. Instead, use stream >> object;
.
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 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.
|
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.
|
overrideprotectedvirtual |
Pure virtual method for writing (serializing) to an abstract archive.
Users don't call this method directly. Instead, use stream << object;
.
std::exception | On any I/O error |
Implements mrpt::serialization::CSerializable.
Definition at line 31 of file CSimpleDatabase.cpp.
size_t CSimpleDatabase::tablesCount | ( | ) | const |
Returns the tables count in the DB.
Definition at line 165 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 169 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 70 of file CSerializable.h.
|
staticprotected |
Definition at line 123 of file CSimpleDatabase.h.
|
staticconstexpr |
Definition at line 123 of file CSimpleDatabase.h.
|
private |
Definition at line 192 of file CSimpleDatabase.h.
|
staticprotected |
Definition at line 123 of file CSimpleDatabase.h.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST |