20 #undef _UNICODE // JLBC 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") );
514 size_t nFields = fNod.nChildNode();
515 for (j=0;j<nFields;j++)
517 t->addField( fNod.getChildNode((
int)j).getName() );
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;
size_t tablesCount() const
Returns the tables count in the DB.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::string getFieldName(size_t fieldIndex) const
Get the name of a field by its index.
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 readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Main Class representing a XML node.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
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.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
bool loadFromXML(const std::string &fileName)
Loads the content of this database from a a XML file.
virtual ~CSimpleDatabase()
Destructor.
char isEmpty() const
is this node Empty?
GLenum GLsizei GLenum GLenum const GLvoid * table
size_t fieldsCount() const
Get the count of fields.
static XMLNode createXMLTopNode(XMLCSTR lpszName, char isDeclaration=FALSE)
Create the top node of an XMLNode structure.
static CSimpleDatabaseTablePtr Create()
CSimpleDatabase()
Default constructor.
std::map< std::string, CSimpleDatabaseTablePtr >::const_iterator const_iterator
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
bool saveAsXML(const std::string &fileName) const
Saves this database as a XML file.
void clear()
Clear the contents of this container.
static XMLCSTR getError(XMLError error)
this gives you a user-friendly explanation of the parsing error
CSimpleDatabaseTable()
Default constructor.
void renameTable(const std::string &tableName, const std::string &newTableName)
Changes the name of a given table.
std::vector< std::string > vector_string
A type for passing a vector of strings.
void addField(const char *fieldName)
Add a new field to the table.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
This class implements the tables of databases.
std::map< std::string, CSimpleDatabaseTablePtr >::iterator iterator
XMLAttribute getAttribute(int i=0) const
return ith attribute
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void dropTable(const std::string &tableName)
Deletes the given table.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
std::string tablesName(size_t tableIndex) const
Returns the tables names in the DB.
GLsizei const GLchar ** string
size_t getRecordCount() const
Get the records count in the table.
This class impements a very simple database system.
XMLCSTR addText(XMLCSTR lpszValue, XMLElementPosition pos=-1)
Add a new text content.
size_t appendRecord()
Append a new and empty record at the end of the table, and return the index of the newly added record...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual ~CSimpleDatabaseTable()
Destructor.
int BASE_IMPEXP _strcmpi(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmpi.
GLenum GLenum GLvoid * row
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"...
CSimpleDatabaseTablePtr getTable(const std::string &tableName)
Returns the table with the indicated name.
CSimpleDatabaseTablePtr createTable(const std::string &name)
Creates a new table in the DB, initially empty.
GLuint const GLchar * name
XMLError writeToFile(XMLCSTR filename, const char *encoding=NULL, char nFormat=1) const
Save the content of an xmlNode inside a file.
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...
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
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.
XMLNode addChild(XMLCSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1)
Add a new child node.
GLsizei const GLfloat * value
unsigned __int32 uint32_t
void clear()
Clears the DB.
GLsizei GLsizei GLenum GLenum const GLvoid * data
size_t fieldIndex(const char *fieldName) const
Get the index for a given field name.
int nChildNode(XMLCSTR name) const
return the number of child node with specific name
Structure used to obtain error details if the parse fails.
XMLNode getChildNode(int i=0) const
return ith child node
XMLAttribute * addAttribute(XMLCSTR lpszName, XMLCSTR lpszValuev)
Add a new attribute.