MRPT  1.9.9
mrpt::db::CSimpleDatabaseTable Class Reference

Detailed Description

This class implements the tables of databases.

See also
CSimpleDatabase

Definition at line 19 of file CSimpleDatabase.h.

#include <mrpt/db/CSimpleDatabase.h>

Inheritance diagram for mrpt::db::CSimpleDatabaseTable:

Public Member Functions

 CSimpleDatabaseTable ()
 Default constructor. More...
 
 ~CSimpleDatabaseTable () override
 Destructor. More...
 
size_t fieldsCount () const
 Get the count of fields. More...
 
size_t appendRecord ()
 Append a new and empty record at the end of the table, and return the index of the newly added record. More...
 
void addField (const char *fieldName)
 Add a new field to the table. More...
 
void addField (const std::string &fieldName)
 Add a new field to the table. More...
 
std::string getFieldName (size_t fieldIndex) const
 Get the name of a field by its index. More...
 
size_t fieldIndex (const char *fieldName) const
 Get the index for a given field name. More...
 
size_t fieldIndex (const std::string &fieldName) const
 Get the index for a given field name. More...
 
size_t getRecordCount () const
 Get the records count in the table. More...
 
std::string get (size_t recordIndex, std::string field) const
 Returns the cell content of the record indicates by its index, and the field indicated in "field". More...
 
std::string get (size_t recordIndex, size_t fieldIndex) const
 Returns the cell content of the record indicates by its index, and the field indicated by its index. More...
 
void set (size_t recordIndex, std::string field, std::string value)
 Sets the cell content of the record indicates by its index, and the field indicated in "field". More...
 
void set (size_t recordIndex, size_t fieldIndex, std::string value)
 Sets the cell content of the record indicates by its index, and the field indicated by its index. More...
 
int query (std::string field, std::string value) const
 Executes a query in the table, returning the record index which a given field has a given value, case insensitive, or -1 if not found. More...
 
void deleteRecord (size_t recordIndex)
 Delete the record at the given index. 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 Attributes

std::vector< std::stringfield_names
 Field names. More...
 
std::vector< std::vector< std::string > > data
 Data for each cell. More...
 

RTTI stuff

using Ptr = std::shared_ptr< CSimpleDatabaseTable >
 
using ConstPtr = std::shared_ptr< const CSimpleDatabaseTable >
 
using UniquePtr = std::unique_ptr< CSimpleDatabaseTable >
 
using ConstUniquePtr = std::unique_ptr< const CSimpleDatabaseTable >
 
static mrpt::rtti::CLASSINIT _init_CSimpleDatabaseTable
 
static const mrpt::rtti::TRuntimeClassId runtimeClassId
 
static constexpr const char * className = "CSimpleDatabaseTable"
 
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

◆ ConstPtr

◆ ConstUniquePtr

Definition at line 21 of file CSimpleDatabase.h.

◆ Ptr

A type for the associated smart pointer

Definition at line 21 of file CSimpleDatabase.h.

◆ UniquePtr

Definition at line 21 of file CSimpleDatabase.h.

Constructor & Destructor Documentation

◆ CSimpleDatabaseTable()

CSimpleDatabaseTable::CSimpleDatabaseTable ( )
default

Default constructor.

◆ ~CSimpleDatabaseTable()

CSimpleDatabaseTable::~CSimpleDatabaseTable ( )
overridedefault

Destructor.

Member Function Documentation

◆ _GetBaseClass()

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

◆ addField() [1/2]

void CSimpleDatabaseTable::addField ( const char *  fieldName)

Add a new field to the table.

The table is cleared in this operation.

Definition at line 206 of file CSimpleDatabase.cpp.

◆ addField() [2/2]

void mrpt::db::CSimpleDatabaseTable::addField ( const std::string fieldName)
inline

Add a new field to the table.

The table is cleared in this operation.

Definition at line 45 of file CSimpleDatabase.h.

References addField().

Referenced by addField().

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

◆ appendRecord()

size_t CSimpleDatabaseTable::appendRecord ( )

Append a new and empty record at the end of the table, and return the index of the newly added record.

See also
deleteRecord

Definition at line 325 of file CSimpleDatabase.cpp.

◆ clone()

virtual mrpt::rtti::CObject* mrpt::db::CSimpleDatabaseTable::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::CSimpleDatabaseTable::Create ( Args &&...  args)
inlinestatic

Definition at line 21 of file CSimpleDatabase.h.

◆ CreateAlloc()

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

Definition at line 21 of file CSimpleDatabase.h.

◆ CreateObject()

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

◆ CreateUnique()

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

Definition at line 21 of file CSimpleDatabase.h.

◆ deleteRecord()

void CSimpleDatabaseTable::deleteRecord ( size_t  recordIndex)

Delete the record at the given index.

See also
appendRecord

Definition at line 338 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ 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 200 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:

◆ fieldIndex() [1/2]

size_t CSimpleDatabaseTable::fieldIndex ( const char *  fieldName) const

Get the index for a given field name.

Exceptions
std::exceptionOn field not found

Definition at line 228 of file CSimpleDatabase.cpp.

References mrpt::system::os::_strcmpi(), MRPT_END, MRPT_START, and THROW_EXCEPTION_FMT.

Referenced by fieldIndex().

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

◆ fieldIndex() [2/2]

size_t mrpt::db::CSimpleDatabaseTable::fieldIndex ( const std::string fieldName) const
inline

Get the index for a given field name.

Exceptions
std::exceptionOn field not found

Definition at line 59 of file CSimpleDatabase.h.

References fieldIndex().

Here is the call graph for this function:

◆ fieldsCount()

size_t CSimpleDatabaseTable::fieldsCount ( ) const

Get the count of fields.

Definition at line 202 of file CSimpleDatabase.cpp.

◆ get() [1/2]

string CSimpleDatabaseTable::get ( size_t  recordIndex,
std::string  field 
) const

Returns the cell content of the record indicates by its index, and the field indicated in "field".

Exceptions
std::exceptionOn field or record not found

Definition at line 249 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ get() [2/2]

string CSimpleDatabaseTable::get ( size_t  recordIndex,
size_t  fieldIndex 
) const

Returns the cell content of the record indicates by its index, and the field indicated by its index.

Exceptions
std::exceptionOn field or record not found

Definition at line 260 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ getClassName()

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

Definition at line 21 of file CSimpleDatabase.h.

◆ getFieldName()

string CSimpleDatabaseTable::getFieldName ( size_t  fieldIndex) const

Get the name of a field by its index.

Exceptions
std::exceptionOn index out of bounds

Definition at line 215 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ getRecordCount()

size_t CSimpleDatabaseTable::getRecordCount ( ) const

Get the records count in the table.

Definition at line 245 of file CSimpleDatabase.cpp.

◆ GetRuntimeClass()

virtual const mrpt::rtti::TRuntimeClassId* mrpt::db::CSimpleDatabaseTable::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::CSimpleDatabaseTable::GetRuntimeClassIdStatic ( )
static

◆ query()

int CSimpleDatabaseTable::query ( std::string  field,
std::string  value 
) const

Executes a query in the table, returning the record index which a given field has a given value, case insensitive, or -1 if not found.

Definition at line 300 of file CSimpleDatabase.cpp.

References mrpt::system::os::_strcmpi().

Here is the call graph for this function:

◆ serializeFrom() [1/2]

void CSimpleDatabaseTable::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 89 of file CSimpleDatabase.cpp.

References MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION.

◆ serializeFrom() [2/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:

◆ serializeGetVersion()

uint8_t CSimpleDatabaseTable::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 76 of file CSimpleDatabase.cpp.

◆ serializeTo() [1/2]

void CSimpleDatabaseTable::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 77 of file CSimpleDatabase.cpp.

◆ serializeTo() [2/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:

◆ set() [1/2]

void CSimpleDatabaseTable::set ( size_t  recordIndex,
std::string  field,
std::string  value 
)

Sets the cell content of the record indicates by its index, and the field indicated in "field".

Exceptions
std::exceptionOn field or record not found

Definition at line 272 of file CSimpleDatabase.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ set() [2/2]

void CSimpleDatabaseTable::set ( size_t  recordIndex,
size_t  fieldIndex,
std::string  value 
)

Sets the cell content of the record indicates by its index, and the field indicated by its index.

Exceptions
std::exceptionOn field or record not found

Definition at line 285 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

◆ _init_CSimpleDatabaseTable

mrpt::rtti::CLASSINIT mrpt::db::CSimpleDatabaseTable::_init_CSimpleDatabaseTable
staticprotected

Definition at line 21 of file CSimpleDatabase.h.

◆ className

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

Definition at line 21 of file CSimpleDatabase.h.

◆ data

std::vector<std::vector<std::string> > mrpt::db::CSimpleDatabaseTable::data
private

Data for each cell.

Definition at line 104 of file CSimpleDatabase.h.

◆ field_names

std::vector<std::string> mrpt::db::CSimpleDatabaseTable::field_names
private

Field names.

Definition at line 102 of file CSimpleDatabase.h.

◆ runtimeClassId

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

Definition at line 21 of file CSimpleDatabase.h.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c26d46ba6 Thu Jul 18 13:03:42 2019 +0200 at jue jul 18 13:10:17 CEST 2019