9#ifndef CSimpleDatabase_H
10#define CSimpleDatabase_H
56 addField(fieldName.c_str());
73 return fieldIndex(fieldName.c_str());
83 std::string
get(
size_t recordIndex, std::string field)
const;
88 std::string
get(
size_t recordIndex,
size_t fieldIndex)
const;
93 void set(
size_t recordIndex, std::string field, std::string value);
98 void set(
size_t recordIndex,
size_t fieldIndex, std::string value);
102 int query(std::string field, std::string value)
const;
109 std::vector<vector_string>
data;
147 CSimpleDatabaseTablePtr
getTable(
const std::string &tableName);
158 const std::string &tableName,
159 const std::string &newTableName );
164 CSimpleDatabaseTablePtr
getTable(
size_t tableIndex);
191 typedef std::map<std::string, CSimpleDatabaseTablePtr>
TTableList;
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
The virtual base class which provides a unified interface for all persistent objects in MRPT.
This class impements a very simple database system.
bool loadFromXML(const std::string &fileName)
Loads the content of this database from a a XML file.
void clear()
Clears the DB.
std::map< std::string, CSimpleDatabaseTablePtr >::const_iterator const_iterator
bool saveAsXML(const std::string &fileName) const
Saves this database as a XML file.
std::map< std::string, CSimpleDatabaseTablePtr >::iterator iterator
virtual ~CSimpleDatabase()
Destructor.
CSimpleDatabaseTablePtr getTable(size_t tableIndex)
Returns the table by index.
CSimpleDatabaseTablePtr createTable(const std::string &name)
Creates a new table in the DB, initially empty.
CSimpleDatabaseTablePtr getTable(const std::string &tableName)
Returns the table with the indicated name.
std::map< std::string, CSimpleDatabaseTablePtr > TTableList
The tables of the DB indexed by their names:
CSimpleDatabase()
Default constructor.
void renameTable(const std::string &tableName, const std::string &newTableName)
Changes the name of a given table.
std::string tablesName(size_t tableIndex) const
Returns the tables names in the DB.
size_t tablesCount() const
Returns the tables count in the DB.
void dropTable(const std::string &tableName)
Deletes the given table.
This class implements the tables of databases.
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.
size_t fieldIndex(const char *fieldName) const
Get the index for a given field name.
CSimpleDatabaseTable()
Default constructor.
void addField(const std::string &fieldName)
Add a new field to the table.
std::vector< vector_string > data
Data for each cell.
vector_string field_names
Field names.
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.
size_t appendRecord()
Append a new and empty record at the end of the table, and return the index of the newly added record...
std::string getFieldName(size_t fieldIndex) const
Get the name of a field by its index.
virtual ~CSimpleDatabaseTable()
Destructor.
size_t fieldIndex(const std::string &fieldName) const
Get the index for a given field name.
void deleteRecord(size_t recordIndex)
Delete the record at the given index.
size_t getRecordCount() const
Get the records count in the table.
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".
size_t fieldsCount() const
Get the count of fields.
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,...
void addField(const char *fieldName)
Add a new field to the table.
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".
const Scalar * const_iterator
std::vector< std::string > vector_string
A type for passing a vector of strings.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.