A class for storing a list of text lines.
This class is optimized for managing strings on a "per-line" basis, although methods are also provided to obtain/set the whole string list as a single, multi-line string. There are methods for saving and loading to/from text files. You can access to lines directly by "CStringList::get" or through the operator "CStringList::operator ()". The later can be used both, to read and to write elements. Also methods are provided for accesing the text by key if they are formated as "key=value" lines.
Definition at line 32 of file CStringList.h.
#include <mrpt/utils/CStringList.h>
Public Member Functions | |
void * | operator new (size_t size) |
void * | operator new[] (size_t size) |
void | operator delete (void *ptr) throw () |
void | operator delete[] (void *ptr) throw () |
void | operator delete (void *memory, void *ptr) throw () |
void * | operator new (size_t size, const std::nothrow_t &) throw () |
void | operator delete (void *ptr, const std::nothrow_t &) throw () |
CStringList () | |
Default constructor (empty string list) More... | |
CStringList (const std::string &text) | |
Constructor from a text. More... | |
CStringList (const std::deque< std::string > &lines) | |
Explicit constructor from deque<string> More... | |
CStringList (const std::vector< std::string > &lines) | |
Explicit constructor from vector<string> More... | |
void | add (const std::string &str) |
Appends a new string at the end of the string list. More... | |
CStringList & | operator<< (const std::string &s) |
An alternative way of adding strings to the list. More... | |
void | insert (size_t index, const std::string &str) |
Inserts a new item at a given position (0=insert at the beggining,1=put into the second position,...) More... | |
void | set (size_t index, const std::string &str) |
Overwrites an existing position with a new value (0=first elements) More... | |
void | clear () |
Clear the whole list. More... | |
size_t | size () const |
Returns the number of text lines in the list. More... | |
void | remove (size_t index) |
Delete the element at a given position (0=first element) More... | |
bool | find (const std::string &compareText, size_t foundIndex, bool caseSensitive=true) const |
Looks for a given string in the list, and returns its index, or returns "false" otherwise. More... | |
void | get (size_t index, std::string &outText) const |
Returns one string from the line list. More... | |
std::string | operator() (size_t index) const |
Returns one string from the line list. More... | |
std::string & | operator() (size_t index) |
Returns a reference to one string from the line list. More... | |
void | getText (std::string &outText) const |
Returns the whole string list as a single string with ' ' characters for newlines. More... | |
std::string | getText () const |
Returns the whole string list as a single string with ' ' characters for newlines. More... | |
void | setText (const std::string &inText) |
Fills the string list by parsing a single string with '', ' ', or ' ' characters indicatng newlines. More... | |
void | loadFromFile (const std::string &fileName) |
Load the string list from a file. More... | |
void | saveToFile (const std::string &fileName) const |
Save the string list to a file. More... | |
std::string | get_string (const std::string &keyName) |
Returns the value of the given key ("key=value"). More... | |
float | get_float (const std::string &keyName) |
Returns the value of the given key ("key=value"). More... | |
int | get_int (const std::string &keyName) |
Returns the value of the given key ("key=value"). More... | |
double | get_double (const std::string &keyName) |
Returns the value of the given key ("key=value"). More... | |
bool | get_bool (const std::string &keyName) |
Returns the value of the given key ("key=value"). More... | |
void | set (const std::string &keyName, const std::string &value) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed. More... | |
void | set (const std::string &keyName, const int &value) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed. More... | |
void | set (const std::string &keyName, const float &value) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed. More... | |
void | set (const std::string &keyName, const double &value) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed. More... | |
void | set (const std::string &keyName, const bool &value) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed. More... | |
virtual mxArray * | writeToMatlab () 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... | |
CObject * | clone () const |
Cloning interface for smart pointers. More... | |
RTTI classes and functions | |
mrpt::utils::CObjectPtr | duplicateGetSmartPtr () const |
Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer). More... | |
Static Public Member Functions | |
static void * | operator new (size_t size, void *ptr) |
Static Public Attributes | |
static const mrpt::utils::TRuntimeClassId | classCObject |
RTTI stuff | |
static const mrpt::utils::TRuntimeClassId | classCSerializable |
Protected Member Functions | |
CSerializable virtual methods | |
void | writeToStream (mrpt::utils::CStream &out, int *getVersion) const |
Introduces a pure virtual method responsible for writing to a CStream. More... | |
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 be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori. More... | |
Protected Attributes | |
std::deque< std::string > | m_strings |
The internal list of strings. More... | |
RTTI stuff | |
typedef CStringListPtr | Ptr |
typedef CStringListPtr | ConstPtr |
static mrpt::utils::CLASSINIT | _init_CStringList |
static mrpt::utils::TRuntimeClassId | classCStringList |
static const mrpt::utils::TRuntimeClassId * | classinfo |
static const mrpt::utils::TRuntimeClassId * | _GetBaseClass () |
virtual const mrpt::utils::TRuntimeClassId * | GetRuntimeClass () const |
Returns information about the class of an object in runtime. More... | |
virtual mrpt::utils::CObject * | duplicate () const |
Returns a copy of the object, indepently of its class. More... | |
static mrpt::utils::CObject * | CreateObject () |
static CStringListPtr | Create () |
typedef CStringListPtr mrpt::utils::CStringList::ConstPtr |
Definition at line 35 of file CStringList.h.
typedef CStringListPtr mrpt::utils::CStringList::Ptr |
A typedef for the associated smart pointer
Definition at line 35 of file CStringList.h.
CStringList::CStringList | ( | ) |
Default constructor (empty string list)
Definition at line 30 of file CStringList.cpp.
CStringList::CStringList | ( | const std::string & | text | ) |
Constructor from a text.
Definition at line 38 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
|
inlineexplicit |
Explicit constructor from deque<string>
Definition at line 52 of file CStringList.h.
|
inlineexplicit |
Explicit constructor from vector<string>
Definition at line 55 of file CStringList.h.
|
staticprotected |
void CStringList::add | ( | const std::string & | str | ) |
Appends a new string at the end of the string list.
Definition at line 49 of file CStringList.cpp.
Referenced by mrpt::opengl::CSetOfObjects::dumpListOfObjects(), mrpt::opengl::COpenGLScene::dumpListOfObjects(), mrpt::opengl::COpenGLViewport::dumpListOfObjects(), and mrpt::maps::CBeacon::getAsMatlabDrawCommands().
void CStringList::clear | ( | ) |
Clear the whole list.
Definition at line 84 of file CStringList.cpp.
Referenced by mrpt::hmtslam::CLocalMetricHypothesis::dumpAsText(), mrpt::hmtslam::CHierarchicalMapMHPartition::dumpAsText(), mrpt::opengl::COpenGLScene::dumpListOfObjects(), and mrpt::maps::CBeacon::getAsMatlabDrawCommands().
|
inlineinherited |
|
static |
|
static |
|
virtual |
Returns a copy of the object, indepently of its class.
Implements mrpt::utils::CObject.
|
inlineinherited |
Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer).
Definition at line 162 of file CObject.h.
References mrpt::utils::CObjectPtr.
Referenced by mrpt::obs::CRawlog::addActions(), mrpt::slam::CIncrementalMapPartitioner::addMapFrame(), and mrpt::obs::CRawlog::addObservations().
bool CStringList::find | ( | const std::string & | compareText, |
size_t | foundIndex, | ||
bool | caseSensitive = true |
||
) | const |
Looks for a given string in the list, and returns its index, or returns "false" otherwise.
Definition at line 107 of file CStringList.cpp.
References mrpt::system::os::_strcmp(), mrpt::system::os::_strcmpi(), MRPT_END, and MRPT_START.
void CStringList::get | ( | size_t | index, |
std::string & | outText | ||
) | const |
Returns one string from the line list.
Definition at line 273 of file CStringList.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION.
bool CStringList::get_bool | ( | const std::string & | keyName | ) |
Returns the value of the given key ("key=value").
std::exception | If the key is not found in the string list. |
Definition at line 364 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
double CStringList::get_double | ( | const std::string & | keyName | ) |
Returns the value of the given key ("key=value").
std::exception | If the key is not found in the string list. |
Definition at line 353 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
float CStringList::get_float | ( | const std::string & | keyName | ) |
Returns the value of the given key ("key=value").
std::exception | If the key is not found in the string list. |
Definition at line 331 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
int CStringList::get_int | ( | const std::string & | keyName | ) |
Returns the value of the given key ("key=value").
std::exception | If the key is not found in the string list. |
Definition at line 342 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
string CStringList::get_string | ( | const std::string & | keyName | ) |
Returns the value of the given key ("key=value").
std::exception | If the key is not found in the string list. |
Definition at line 310 of file CStringList.cpp.
References mrpt::format(), MRPT_END, MRPT_START, and THROW_EXCEPTION.
|
virtual |
Returns information about the class of an object in runtime.
Reimplemented from mrpt::utils::CSerializable.
void CStringList::getText | ( | std::string & | outText | ) | const |
Returns the whole string list as a single string with '
' characters for newlines.
Definition at line 135 of file CStringList.cpp.
References mrpt::system::os::memcpy(), MRPT_END, and MRPT_START.
Referenced by mrpt::utils::CConfigFileMemory::CConfigFileMemory(), mrpt::maps::CBeaconMap::saveToMATLABScript3D(), and mrpt::utils::CConfigFileMemory::setContent().
|
inline |
Returns the whole string list as a single string with '
' characters for newlines.
Definition at line 116 of file CStringList.h.
void CStringList::insert | ( | size_t | index, |
const std::string & | str | ||
) |
Inserts a new item at a given position (0=insert at the beggining,1=put into the second position,...)
Definition at line 57 of file CStringList.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION.
void CStringList::loadFromFile | ( | const std::string & | fileName | ) |
Load the string list from a file.
Definition at line 174 of file CStringList.cpp.
References ASSERT_, mrpt::system::fileExists(), mrpt::utils::CFileInputStream::getTotalBytesCount(), MRPT_END, MRPT_START, and THROW_EXCEPTION.
Definition at line 35 of file CStringList.h.
Definition at line 35 of file CStringList.h.
|
inline |
Definition at line 35 of file CStringList.h.
Definition at line 35 of file CStringList.h.
Definition at line 35 of file CStringList.h.
|
inline |
Definition at line 35 of file CStringList.h.
|
inline |
Definition at line 35 of file CStringList.h.
|
inline |
Definition at line 35 of file CStringList.h.
string CStringList::operator() | ( | size_t | index | ) | const |
Returns one string from the line list.
Definition at line 286 of file CStringList.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION.
string & CStringList::operator() | ( | size_t | index | ) |
Returns a reference to one string from the line list.
Definition at line 298 of file CStringList.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION.
|
inline |
An alternative way of adding strings to the list.
Definition at line 66 of file CStringList.h.
|
protectedvirtual |
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori.
in | The input binary stream where the object data must read from. |
version | The version of the object stored in the stream: use this version number in your code to know how to read the incoming data. |
std::exception | On any error, see CStream::ReadBuffer |
Implements mrpt::utils::CSerializable.
Definition at line 240 of file CStringList.cpp.
References MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION, and version.
void CStringList::remove | ( | size_t | index | ) |
Delete the element at a given position (0=first element)
Definition at line 93 of file CStringList.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION.
void CStringList::saveToFile | ( | const std::string & | fileName | ) | const |
Save the string list to a file.
Definition at line 201 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
void CStringList::set | ( | size_t | index, |
const std::string & | str | ||
) |
Overwrites an existing position with a new value (0=first elements)
Definition at line 70 of file CStringList.cpp.
References MRPT_END, MRPT_START, and THROW_EXCEPTION.
void CStringList::set | ( | const std::string & | keyName, |
const std::string & | value | ||
) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed.
Definition at line 375 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
void CStringList::set | ( | const std::string & | keyName, |
const int & | value | ||
) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed.
Definition at line 400 of file CStringList.cpp.
References mrpt::format(), MRPT_END, and MRPT_START.
void CStringList::set | ( | const std::string & | keyName, |
const float & | value | ||
) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed.
Definition at line 409 of file CStringList.cpp.
References mrpt::format(), MRPT_END, and MRPT_START.
void CStringList::set | ( | const std::string & | keyName, |
const double & | value | ||
) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed.
Definition at line 419 of file CStringList.cpp.
References mrpt::format(), MRPT_END, and MRPT_START.
void CStringList::set | ( | const std::string & | keyName, |
const bool & | value | ||
) |
Sets the value of a given key ("key=value"), overwritten previous value if it existed.
Definition at line 429 of file CStringList.cpp.
References MRPT_END, and MRPT_START.
void CStringList::setText | ( | const std::string & | inText | ) |
Fills the string list by parsing a single string with '', '
', or '
' characters indicatng newlines.
Definition at line 164 of file CStringList.cpp.
References MRPT_END, MRPT_START, and mrpt::system::tokenize().
size_t CStringList::size | ( | ) | const |
Returns the number of text lines in the list.
Definition at line 265 of file CStringList.cpp.
Referenced by mrpt::opengl::CSetOfObjects::dumpListOfObjects(), mrpt::opengl::COpenGLViewport::dumpListOfObjects(), mrpt::hwdrivers::CNTRIPClient::retrieveListOfMountpoints(), and mrpt::utils::PLY_Exporter::saveToPlyFile().
|
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.
mxArray
(caller is responsible of memory freeing) or NULL is class does not support conversion to MATLAB. Definition at line 79 of file CSerializable.h.
|
protectedvirtual |
Introduces a pure virtual method responsible for writing to a CStream.
This can not be used directly be users, instead use "stream << object;" for writing it to a stream.
out | The output binary stream where object must be dumped. |
getVersion | If NULL, the object must be dumped. If not, only the version of the object dump must be returned in this pointer. This enables the versioning of objects dumping and backward compatibility with previously stored data. |
std::exception | On any error, see CStream::WriteBuffer |
Implements mrpt::utils::CSerializable.
Definition at line 221 of file CStringList.cpp.
|
staticprotected |
Definition at line 35 of file CStringList.h.
|
staticinherited |
|
staticinherited |
Definition at line 42 of file CSerializable.h.
|
static |
Definition at line 35 of file CStringList.h.
|
static |
Definition at line 35 of file CStringList.h.
|
protected |
The internal list of strings.
Definition at line 40 of file CStringList.h.
Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020 |