75 m_tables[aux] = newTb;
98 for (col=0;col<nFie;col++)
99 out << field_names[col];
102 for (col=0;col<nFie;col++)
121 field_names.resize(nFie);
123 for (col=0;col<nFie;col++)
124 in >> field_names[col];
130 for (col=0;col<nFie;col++)
172 iterator it = m_tables.find(tableName);
173 if (it!=m_tables.end())
188 ASSERT_(tableIndex<tablesCount() )
191 std::advance(it,tableIndex);
202 return m_tables.size();
212 ASSERT_( tableIndex<tablesCount() )
214 std::advance(it,tableIndex);
249 return field_names.size();
257 field_names.push_back(
string(fieldName));
268 ASSERT_( fieldIndex<fieldsCount() );
269 return field_names[fieldIndex];
281 size_t i,
n = field_names.size();
308 ASSERT_(recordIndex<getRecordCount());
309 return data[recordIndex][fieldIndex(field.c_str())];
318 size_t fieldIndex )
const
321 ASSERT_(recordIndex<getRecordCount());
322 ASSERT_(fieldIndex<fieldsCount() );
323 return data[recordIndex][fieldIndex];
337 ASSERT_(recordIndex<getRecordCount());
338 data[recordIndex][fieldIndex(field.c_str())]=
value;
353 ASSERT_(recordIndex<getRecordCount());
354 ASSERT_(fieldIndex<fieldsCount() );
367 int fieldInd,i,
n = (
uint32_t) getRecordCount();
371 fieldInd = (
uint32_t) fieldIndex(field.c_str());
395 new_rec.resize( fieldsCount() );
396 data.push_back( new_rec );
398 return data.size()-1;
407 ASSERT_(recordIndex<getRecordCount())
410 std::advance(it,recordIndex);
430 CSimpleDatabaseTablePtr
t = it->second;
436 size_t nFields =
t->fieldsCount();
437 size_t nRecs =
t->getRecordCount();
440 for (
unsigned int i=0;i<nFields;i++)
441 fNod.
addChild(
t->getFieldName(i).c_str() );
445 for (
unsigned int i=0;i<nRecs;i++)
448 for (
size_t j=0;j<nFields;j++)
451 recContent.
addText(
t->get(i,j).c_str() );
463 cerr <<
"[CSimpleDatabase::saveAsXML] Exception ignored:" << endl << e.what() << endl;
485 cerr <<
"[CSimpleDatabase::loadFromXML] Error loading XML file: " <<
490 root = root.
getChildNode(
"CSimpleDatabase-MRPT-Object");
493 cerr <<
"[CSimpleDatabase::loadFromXML] Loaded XML file does not have a 'CSimpleDatabase-MRPT-Object' tag";
501 size_t i,j, nTables = root.
nChildNode(
"table");
502 for (i=0;i<nTables;i++)
508 CSimpleDatabaseTablePtr
t = createTable( tabNod.
getAttribute(
"name") );
515 for (j=0;j<nFields;j++)
522 for (
size_t k=0;k<nRecs;k++)
524 size_t recIdx =
t->appendRecord();
529 for (j=0;j<nFields;j++)
532 t->set(recIdx,j, str!=NULL ?
string(str) :
string() );
543 cerr <<
"[CSimpleDatabase::loadFromXML] Exception ignored:" << endl << e.what() << endl;
559 iterator it = m_tables.find(tableName);
560 if (it==m_tables.end())
578 if (tableName==newTableName)
return;
580 iterator it = m_tables.find(tableName);
581 if (it==m_tables.end())
585 iterator itNew = m_tables.find(newTableName);
586 if (itNew !=m_tables.end())
590 CSimpleDatabaseTablePtr tb = it->second;
593 m_tables[newTableName] = tb;
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
The virtual base class which provides a unified interface for all persistent objects in MRPT.
This class impements a very simple database system.
virtual ~CSimpleDatabase()
Destructor.
void clear()
Clears the DB.
std::string tablesName(size_t tableIndex) const
Returns the tables names in the DB.
CSimpleDatabaseTablePtr getTable(const std::string &tableName)
Returns the table with the indicated name.
std::map< std::string, CSimpleDatabaseTablePtr >::iterator iterator
bool saveAsXML(const std::string &fileName) const
Saves this database as a XML file.
void renameTable(const std::string &tableName, const std::string &newTableName)
Changes the name of a given table.
CSimpleDatabaseTablePtr createTable(const std::string &name)
Creates a new table in the DB, initially empty.
bool loadFromXML(const std::string &fileName)
Loads the content of this database from a a XML file.
std::map< std::string, CSimpleDatabaseTablePtr >::const_iterator const_iterator
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
void dropTable(const std::string &tableName)
Deletes the given table.
CSimpleDatabase()
Default constructor.
size_t tablesCount() const
Returns the tables count in the DB.
This class implements the tables of databases.
size_t fieldIndex(const char *fieldName) const
Get the index for a given field name.
static CSimpleDatabaseTablePtr Create()
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void addField(const char *fieldName)
Add a new field to the table.
size_t fieldsCount() const
Get the count of fields.
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".
void deleteRecord(size_t recordIndex)
Delete the record at the given index.
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 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 readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
CSimpleDatabaseTable()
Default constructor.
size_t getRecordCount() const
Get the records count in the table.
std::string getFieldName(size_t fieldIndex) const
Get the name of a field 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...
virtual ~CSimpleDatabaseTable()
Destructor.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
GLenum GLenum GLvoid * row
GLsizei GLsizei GLenum GLenum const GLvoid * data
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLenum GLsizei GLenum GLenum const GLvoid * table
GLuint const GLchar * name
GLsizei const GLfloat * value
GLsizei const GLchar ** string
static XMLCSTR getError(XMLError error)
this gives you a user-friendly explanation of the parsing error
static XMLNode parseFile(XMLCSTR filename, XMLCSTR tag=NULL, XMLResults *pResults=NULL)
Parse an XML file and return the root of a XMLNode tree representing the file.
XMLError writeToFile(XMLCSTR filename, const char *encoding=NULL, char nFormat=1) const
Save the content of an xmlNode inside a file.
XMLCSTR addText(XMLCSTR lpszValue, XMLElementPosition pos=-1)
Add a new text content.
XMLNode addChild(XMLCSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1)
Add a new child node.
static XMLNode createXMLTopNode(XMLCSTR lpszName, char isDeclaration=FALSE)
Create the top node of an XMLNode structure.
XMLAttribute * addAttribute(XMLCSTR lpszName, XMLCSTR lpszValuev)
Add a new attribute.
std::vector< std::string > vector_string
A type for passing a vector of strings.
int BASE_IMPEXP _strcmpi(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmpi.
int nChildNode(XMLCSTR name) const
return the number of child node with specific name
XMLAttribute getAttribute(int i=0) const
return ith attribute
XMLCSTR getName() const
name of the node
char isEmpty() const
is this node Empty?
XMLNode getChildNode(int i=0) const
return ith child node
XMLCSTR getText(int i=0) const
return ith text field
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
void clear()
Clear the contents of this container.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int32 uint32_t
Main Class representing a XML node.
Structure used to obtain error details if the parse fails.