MRPT
1.9.9
|
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 119 of file CSimpleDatabase.h.
#include <mrpt/db/CSimpleDatabase.h>
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 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 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 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 std::shared_ptr< CObject > | CreateObject () |
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::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 188 of file CSimpleDatabase.h.
using mrpt::db::CSimpleDatabase::ConstPtr = std::shared_ptr<const CSimpleDatabase > |
Definition at line 121 of file CSimpleDatabase.h.
using mrpt::db::CSimpleDatabase::ConstUniquePtr = std::unique_ptr<const CSimpleDatabase > |
Definition at line 121 of file CSimpleDatabase.h.
|
private |
Definition at line 186 of file CSimpleDatabase.h.
A type for the associated smart pointer
Definition at line 121 of file CSimpleDatabase.h.
|
private |
The tables of the DB indexed by their names:
Definition at line 185 of file CSimpleDatabase.h.
using mrpt::db::CSimpleDatabase::UniquePtr = std::unique_ptr< CSimpleDatabase > |
Definition at line 121 of file CSimpleDatabase.h.
|
default |
Default constructor.
|
override |
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 121 of file CSimpleDatabase.h.
|
inlinestatic |
Definition at line 121 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 121 of file CSimpleDatabase.h.
void CSimpleDatabase::dropTable | ( | const std::string & | tableName | ) |
Deletes the given table.
std::exception | On table not found. |
Definition at line 492 of file CSimpleDatabase.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.
|
inlineinherited |
Makes a deep copy of the object and returns a smart pointer to it.
Definition at line 200 of file CObject.h.
References mrpt::rtti::CObject::clone().
Referenced by mrpt::obs::CRawlog::addActions(), and mrpt::obs::CRawlog::addObservations().
|
inlinestatic |
Definition at line 121 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 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().
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 508 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 352 of file CSimpleDatabase.cpp.
References XMLNode::addAttribute(), XMLNode::addChild(), XMLNode::addText(), XMLNode::createXMLTopNode(), and XMLNode::writeToFile().
Referenced by mrpt::hmtslam::CHierarchicalMHMap::dumpAsXMLfile().
|
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.
|
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.
|
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.
|
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 90 of file CSerializable.h.
|
staticprotected |
Definition at line 121 of file CSimpleDatabase.h.
|
static |
Definition at line 121 of file CSimpleDatabase.h.
|
private |
Definition at line 190 of file CSimpleDatabase.h.
|
staticprotected |
Definition at line 121 of file CSimpleDatabase.h.
Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019 |