Go to the documentation of this file.
   20 #undef _UNICODE  // JLBC 
   37         for (
const_iterator i = m_tables.begin(); i != m_tables.end(); ++i)
 
   64                                         mrpt::make_aligned_shared<CSimpleDatabaseTable>();
 
   67                                 m_tables[aux] = newTb;
 
   84         for (col = 0; col < nFie; col++) out << field_names[col];  
 
   87                 for (col = 0; col < nFie; col++) out << 
data[
row][col];  
 
  102                         field_names.resize(nFie);
 
  104                         for (col = 0; col < nFie; col++) in >> field_names[col];
 
  110                                 for (col = 0; col < nFie; col++) in >> 
data[
row][col];
 
  139         iterator it = m_tables.find(tableName);
 
  140         if (it != m_tables.end()) 
return it->second;
 
  154         ASSERT_(tableIndex < tablesCount());
 
  156         std::advance(it, tableIndex);
 
  173         ASSERT_(tableIndex < tablesCount());
 
  175         std::advance(it, tableIndex);
 
  187                 mrpt::make_aligned_shared<CSimpleDatabaseTable>();
 
  209         field_names.push_back(
string(fieldName));
 
  220         ASSERT_(fieldIndex < fieldsCount());
 
  221         return field_names[fieldIndex];
 
  233         size_t i, 
n = field_names.size();
 
  235         for (i = 0; i < 
n; i++)
 
  236                 if (!
os::_strcmpi(fieldName, field_names[i].c_str())) 
return (
int)i;
 
  253         ASSERT_(recordIndex < getRecordCount());
 
  254         return data[recordIndex][fieldIndex(field.c_str())];
 
  264         ASSERT_(recordIndex < getRecordCount());
 
  265         ASSERT_(fieldIndex < fieldsCount());
 
  266         return data[recordIndex][fieldIndex];
 
  277         ASSERT_(recordIndex < getRecordCount());
 
  278         data[recordIndex][fieldIndex(field.c_str())] = 
value;
 
  287         size_t recordIndex, 
size_t fieldIndex, 
string value)
 
  291         ASSERT_(recordIndex < getRecordCount());
 
  292         ASSERT_(fieldIndex < fieldsCount());
 
  303         int fieldInd, i, 
n = (
uint32_t)getRecordCount();
 
  307                 fieldInd = (
uint32_t)fieldIndex(field.c_str());
 
  314         for (i = 0; i < 
n; i++)
 
  328         std::vector<std::string> new_rec;
 
  330         new_rec.resize(fieldsCount());
 
  331         data.push_back(new_rec);
 
  333         return data.size() - 1;
 
  342         ASSERT_(recordIndex < getRecordCount());
 
  343         std::vector<std::vector<std::string>>
::iterator it = 
data.begin();
 
  344         std::advance(it, recordIndex);
 
  362                 for (
const_iterator it = m_tables.begin(); it != m_tables.end(); ++it)
 
  370                         size_t nFields = 
t->fieldsCount();
 
  371                         size_t nRecs = 
t->getRecordCount();
 
  374                         for (
unsigned int i = 0; i < nFields; i++)
 
  375                                 fNod.
addChild(
t->getFieldName(i).c_str());
 
  379                         for (
unsigned int i = 0; i < nRecs; i++)
 
  382                                 for (
size_t j = 0; j < nFields; j++)
 
  385                                                 recNod.
addChild(
t->getFieldName(j).c_str());
 
  386                                         recContent.
addText(
t->get(i, j).c_str());
 
  398                 cerr << 
"[CSimpleDatabase::saveAsXML] Exception ignored:" << endl
 
  420                         cerr << 
"[CSimpleDatabase::loadFromXML] Error loading XML file: " 
  426                 root = root.
getChildNode(
"CSimpleDatabase-MRPT-Object");
 
  429                         cerr << 
"[CSimpleDatabase::loadFromXML] Loaded XML file does not " 
  430                                         "have a 'CSimpleDatabase-MRPT-Object' tag";
 
  438                 size_t i, j, nTables = root.
nChildNode(
"table");
 
  439                 for (i = 0; i < nTables; i++)
 
  451                         for (j = 0; j < nFields; j++)
 
  458                         for (
size_t k = 0; k < nRecs; k++)
 
  460                                 size_t recIdx = 
t->appendRecord();
 
  464                                 for (j = 0; j < nFields; j++)
 
  469                                         t->set(recIdx, j, str != 
nullptr ? 
string(str) : 
string());
 
  480                 cerr << 
"[CSimpleDatabase::loadFromXML] Exception ignored:" << endl
 
  497         iterator it = m_tables.find(tableName);
 
  498         if (it == m_tables.end())
 
  514         if (tableName == newTableName) 
return;  
 
  516         iterator it = m_tables.find(tableName);
 
  517         if (it == m_tables.end())
 
  521                         iterator itNew = m_tables.find(newTableName);
 
  522                         if (itNew != m_tables.end())
 
  524                                         "A table with the name '%s' already exists",
 
  525                                         newTableName.c_str())
 
  531         m_tables[newTableName] = tb;
 
  
std::map< std::string, CSimpleDatabaseTable::Ptr >::const_iterator const_iterator
 
XMLCSTR getName() const
name of the node
 
std::string getFieldName(size_t fieldIndex) const
Get the name of a field by its index.
 
void clear()
Clear the contents of this container.
 
size_t fieldsCount() const
Get the count of fields.
 
CSimpleDatabaseTable::Ptr getTable(const std::string &tableName)
Returns the table with the indicated name.
 
static XMLNode parseFile(XMLCSTR filename, XMLCSTR tag=nullptr, XMLResults *pResults=nullptr)
Parse an XML file and return the root of a XMLNode tree representing the file.
 
static XMLNode createXMLTopNode(XMLCSTR lpszName, char isDeclaration=FALSE)
Create the top node of an XMLNode structure.
 
void addField(const char *fieldName)
Add a new field to the table.
 
char isEmpty() const
is this node Empty?
 
virtual ~CSimpleDatabase()
Destructor.
 
void deleteRecord(size_t recordIndex)
Delete the record at the given index.
 
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
 
XMLCSTR getText(int i=0) const
return ith text field
 
#define ASSERT_(f)
Defines an assertion mechanism.
 
XMLAttribute getAttribute(int i=0) const
return ith attribute
 
bool saveAsXML(const std::string &fileName) const
Saves this database as a XML file.
 
map< string, CVectorDouble > results
 
std::string tablesName(size_t tableIndex) const
Returns the tables names in the DB.
 
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
 
Virtual base class for "archives": classes abstracting I/O streams.
 
GLuint const GLchar * name
 
Structure used to obtain error details if the parse fails.
 
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,...
 
size_t appendRecord()
Append a new and empty record at the end of the table, and return the index of the newly added record...
 
GLsizei GLsizei GLenum GLenum const GLvoid * data
 
This class implements the tables of databases.
 
CSimpleDatabaseTable()
Default constructor.
 
XMLError writeToFile(XMLCSTR filename, const char *encoding=nullptr, char nFormat=1) const
Save the content of an xmlNode inside a file.
 
size_t getRecordCount() const
Get the records count in the table.
 
std::shared_ptr< CSimpleDatabaseTable > Ptr
 
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".
 
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
 
virtual ~CSimpleDatabaseTable()
Destructor.
 
size_t tablesCount() const
Returns the tables count in the DB.
 
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
 
bool loadFromXML(const std::string &fileName)
Loads the content of this database from a a XML file.
 
void renameTable(const std::string &tableName, const std::string &newTableName)
Changes the name of a given table.
 
void dropTable(const std::string &tableName)
Deletes the given table.
 
XMLCSTR addText(XMLCSTR lpszValue, XMLElementPosition pos=-1)
Add a new text content.
 
GLenum GLsizei GLenum GLenum const GLvoid * table
 
std::map< std::string, CSimpleDatabaseTable::Ptr >::iterator iterator
 
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
 
GLenum GLenum GLvoid * row
 
Main Class representing a XML node.
 
GLsizei const GLfloat * value
 
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".
 
CSimpleDatabase()
Default constructor.
 
This class impements a very simple database system.
 
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
 
GLsizei const GLchar ** string
 
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
 
XMLNode addChild(XMLCSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1)
Add a new child node.
 
int nChildNode(XMLCSTR name) const
return the number of child node with specific name
 
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
 
int _strcmpi(const char *str1, const char *str2) noexcept
An OS-independent version of strcmpi.
 
XMLNode getChildNode(int i=0) const
return ith child node
 
XMLAttribute * addAttribute(XMLCSTR lpszName, XMLCSTR lpszValuev)
it will be detached from it's parents before being attached to the current XMLNode
 
static XMLCSTR getError(XMLError error)
this gives you a
 
size_t fieldIndex(const char *fieldName) const
Get the index for a given field name.
 
unsigned __int32 uint32_t
 
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
 
void clear()
Clears the DB.
 
CSimpleDatabaseTable::Ptr createTable(const std::string &name)
Creates a new table in the DB, initially empty.
 
   |  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 |   |