Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes
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 121 of file CSimpleDatabase.h.

#include <mrpt/db/CSimpleDatabase.h>

Inheritance diagram for mrpt::db::CSimpleDatabase:
Inheritance graph

Public Member Functions

voidoperator new (size_t size)
 
voidoperator new[] (size_t size)
 
void operator delete (void *ptr) noexcept
 
void operator delete[] (void *ptr) noexcept
 
void operator delete (void *memory, void *ptr) noexcept
 
voidoperator 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 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...
 

Static Public Member Functions

static voidoperator 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::TRuntimeClassIdGetRuntimeClassIdStatic ()
 
static mrpt::rtti::CObjectCreateObject ()
 
template<typename... Args>
static Ptr Create (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

Definition at line 190 of file CSimpleDatabase.h.

◆ ConstPtr

using mrpt::db::CSimpleDatabase::ConstPtr = std::shared_ptr<const CSimpleDatabase >

Definition at line 123 of file CSimpleDatabase.h.

◆ ConstUniquePtr

Definition at line 123 of file CSimpleDatabase.h.

◆ iterator

Definition at line 188 of file CSimpleDatabase.h.

◆ Ptr

using mrpt::db::CSimpleDatabase::Ptr = std::shared_ptr< CSimpleDatabase >

A type for the associated smart pointer

Definition at line 123 of file CSimpleDatabase.h.

◆ TTableList

The tables of the DB indexed by their names:

Definition at line 187 of file CSimpleDatabase.h.

◆ UniquePtr

Definition at line 123 of file CSimpleDatabase.h.

Constructor & Destructor Documentation

◆ CSimpleDatabase()

CSimpleDatabase::CSimpleDatabase ( )

Default constructor.

Definition at line 122 of file CSimpleDatabase.cpp.

◆ ~CSimpleDatabase()

CSimpleDatabase::~CSimpleDatabase ( )
virtual

Destructor.

Definition at line 126 of file CSimpleDatabase.cpp.

References mrpt::containers::clear().

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 123 of file CSimpleDatabase.h.

◆ CreateObject()

static mrpt::rtti::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().

◆ CreateUnique()

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

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

References MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.

◆ duplicateGetSmartPtr()

mrpt::rtti::CObject::Ptr 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 169 of file CObject.h.

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

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

◆ getClassName()

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

Definition at line 123 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().

◆ 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)

◆ operator delete() [1/3]

void mrpt::db::CSimpleDatabase::operator delete ( void memory,
void ptr 
)
inlinenoexcept

Definition at line 123 of file CSimpleDatabase.h.

◆ operator delete() [2/3]

void mrpt::db::CSimpleDatabase::operator delete ( void ptr)
inlinenoexcept

Definition at line 123 of file CSimpleDatabase.h.

◆ operator delete() [3/3]

void mrpt::db::CSimpleDatabase::operator delete ( void ptr,
const std::nothrow_t &   
)
inlinenoexcept

Definition at line 123 of file CSimpleDatabase.h.

◆ operator delete[]()

void mrpt::db::CSimpleDatabase::operator delete[] ( void ptr)
inlinenoexcept

Definition at line 123 of file CSimpleDatabase.h.

◆ operator new() [1/3]

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

Definition at line 123 of file CSimpleDatabase.h.

◆ operator new() [2/3]

void* mrpt::db::CSimpleDatabase::operator new ( size_t  size,
const std::nothrow_t &   
)
inlinenoexcept

Definition at line 123 of file CSimpleDatabase.h.

◆ operator new() [3/3]

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

Definition at line 123 of file CSimpleDatabase.h.

◆ operator new[]()

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

Definition at line 123 of file CSimpleDatabase.h.

◆ 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 509 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 353 of file CSimpleDatabase.cpp.

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

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

◆ serializeFrom()

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.

◆ 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()

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 70 of file CSerializable.h.

Member Data Documentation

◆ _init_CSimpleDatabase

mrpt::rtti::CLASSINIT mrpt::db::CSimpleDatabase::_init_CSimpleDatabase
staticprotected

Definition at line 123 of file CSimpleDatabase.h.

◆ className

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

Definition at line 123 of file CSimpleDatabase.h.

◆ m_tables

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

Definition at line 192 of file CSimpleDatabase.h.

◆ runtimeClassId

const mrpt::rtti::TRuntimeClassId mrpt::db::CSimpleDatabase::runtimeClassId
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