Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes
mrpt::utils::CStringList Class Reference

Detailed Description

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>

Inheritance diagram for mrpt::utils::CStringList:
Inheritance graph

Public Member Functions

voidoperator new (size_t size)
 
voidoperator new[] (size_t size)
 
void operator delete (void *ptr) noexcept
 
void operator delete[] (void *ptr) noexcept
 
void operator delete (void *memory, void *ptr) noexcept
 
voidoperator new (size_t size, const std::nothrow_t &) noexcept
 
void operator delete (void *ptr, const std::nothrow_t &) noexcept
 
 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...
 
CStringListoperator<< (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::stringoperator() (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 mxArraywriteToMatlab () 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...
 
RTTI classes and functions
mrpt::utils::CObject::Ptr 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 voidoperator new (size_t size, void *ptr)
 

Protected Member Functions

CSerializable virtual methods
void writeToStream (mrpt::utils::CStream &out, int *getVersion) const override
 Introduces a pure virtual method responsible for writing to a CStream. More...
 
void readFromStream (mrpt::utils::CStream &in, int version) override
 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::stringm_strings
 The internal list of strings. More...
 

RTTI stuff

using Ptr = std::shared_ptr< CStringList >
 
using ConstPtr = std::shared_ptr< const CStringList >
 
static mrpt::utils::CLASSINIT _init_CStringList
 
static const mrpt::utils::TRuntimeClassId runtimeClassId
 
static constexpr const char * className = "CStringList"
 
static const mrpt::utils::TRuntimeClassId_GetBaseClass ()
 
static const mrpt::utils::TRuntimeClassIdGetRuntimeClassIdStatic ()
 
static mrpt::utils::CObjectCreateObject ()
 
template<typename... Args>
static Ptr Create (Args &&... args)
 
virtual const mrpt::utils::TRuntimeClassIdGetRuntimeClass () const override
 Returns information about the class of an object in runtime. More...
 
virtual mrpt::utils::CObjectclone () const override
 Returns a deep copy (clone) of the object, indepently of its class. More...
 

Member Typedef Documentation

◆ ConstPtr

using mrpt::utils::CStringList::ConstPtr = std::shared_ptr<const CStringList >

Definition at line 34 of file CStringList.h.

◆ Ptr

using mrpt::utils::CStringList::Ptr = std::shared_ptr< CStringList >

A typedef for the associated smart pointer

Definition at line 34 of file CStringList.h.

Constructor & Destructor Documentation

◆ CStringList() [1/4]

CStringList::CStringList ( )

Default constructor (empty string list)

Definition at line 29 of file CStringList.cpp.

◆ CStringList() [2/4]

CStringList::CStringList ( const std::string text)

Constructor from a text.

Definition at line 33 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ CStringList() [3/4]

mrpt::utils::CStringList::CStringList ( const std::deque< std::string > &  lines)
inlineexplicit

Explicit constructor from deque<string>

Definition at line 51 of file CStringList.h.

◆ CStringList() [4/4]

mrpt::utils::CStringList::CStringList ( const std::vector< std::string > &  lines)
inlineexplicit

Explicit constructor from vector<string>

Definition at line 57 of file CStringList.h.

References m_strings.

Member Function Documentation

◆ _GetBaseClass()

static const mrpt::utils::TRuntimeClassId* mrpt::utils::CStringList::_GetBaseClass ( )
staticprotected

◆ add()

void CStringList::add ( const std::string str)

Appends a new string at the end of the string list.

See also
insert,set

Definition at line 43 of file CStringList.cpp.

Referenced by mrpt::opengl::CSetOfObjects::dumpListOfObjects(), mrpt::opengl::COpenGLScene::dumpListOfObjects(), mrpt::opengl::COpenGLViewport::dumpListOfObjects(), mrpt::maps::CBeacon::getAsMatlabDrawCommands(), and operator<<().

Here is the caller graph for this function:

◆ clear()

void CStringList::clear ( )

◆ clone()

virtual mrpt::utils::CObject* mrpt::utils::CStringList::clone ( ) const
overridevirtual

Returns a deep copy (clone) of the object, indepently of its class.

Implements mrpt::utils::CObject.

◆ Create()

template<typename... Args>
static Ptr mrpt::utils::CStringList::Create ( Args &&...  args)
inlinestatic

Definition at line 34 of file CStringList.h.

◆ CreateObject()

static mrpt::utils::CObject* mrpt::utils::CStringList::CreateObject ( )
static

◆ find()

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.

Returns
true if string has been found.

Definition at line 90 of file CStringList.cpp.

References mrpt::system::os::_strcmp(), mrpt::system::os::_strcmpi(), MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ get()

void CStringList::get ( size_t  index,
std::string outText 
) const

Returns one string from the line list.

Definition at line 246 of file CStringList.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ get_bool()

bool CStringList::get_bool ( const std::string keyName)

Returns the value of the given key ("key=value").

Exceptions
std::exceptionIf the key is not found in the string list.

Definition at line 337 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ get_double()

double CStringList::get_double ( const std::string keyName)

Returns the value of the given key ("key=value").

Exceptions
std::exceptionIf the key is not found in the string list.

Definition at line 326 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ get_float()

float CStringList::get_float ( const std::string keyName)

Returns the value of the given key ("key=value").

Exceptions
std::exceptionIf the key is not found in the string list.

Definition at line 304 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ get_int()

int CStringList::get_int ( const std::string keyName)

Returns the value of the given key ("key=value").

Exceptions
std::exceptionIf the key is not found in the string list.

Definition at line 315 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ get_string()

string CStringList::get_string ( const std::string keyName)

Returns the value of the given key ("key=value").

Exceptions
std::exceptionIf the key is not found in the string list.

Definition at line 283 of file CStringList.cpp.

References mrpt::format(), MRPT_END, MRPT_START, and THROW_EXCEPTION.

Here is the call graph for this function:

◆ GetRuntimeClass()

virtual const mrpt::utils::TRuntimeClassId* mrpt::utils::CStringList::GetRuntimeClass ( ) const
overridevirtual

Returns information about the class of an object in runtime.

Reimplemented from mrpt::utils::CSerializable.

◆ GetRuntimeClassIdStatic()

static const mrpt::utils::TRuntimeClassId& mrpt::utils::CStringList::GetRuntimeClassIdStatic ( )
static

◆ getText() [1/2]

void CStringList::getText ( std::string outText) const

Returns the whole string list as a single string with '
' characters for newlines.

Definition at line 116 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getText() [2/2]

std::string mrpt::utils::CStringList::getText ( ) const
inline

Returns the whole string list as a single string with '
' characters for newlines.

Definition at line 125 of file CStringList.h.

◆ insert()

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,...)

See also
add,set

Definition at line 47 of file CStringList.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ loadFromFile()

void CStringList::loadFromFile ( const std::string fileName)

Load the string list from a file.

Definition at line 155 of file CStringList.cpp.

References ASSERT_, mrpt::system::fileExists(), mrpt::utils::CFileInputStream::getTotalBytesCount(), MRPT_END, MRPT_START, and THROW_EXCEPTION.

Here is the call graph for this function:

◆ operator delete() [1/3]

void mrpt::utils::CStringList::operator delete ( void ptr)
inlinenoexcept

Definition at line 34 of file CStringList.h.

◆ operator delete() [2/3]

void mrpt::utils::CStringList::operator delete ( void memory,
void ptr 
)
inlinenoexcept

Definition at line 34 of file CStringList.h.

◆ operator delete() [3/3]

void mrpt::utils::CStringList::operator delete ( void ptr,
const std::nothrow_t &   
)
inlinenoexcept

Definition at line 34 of file CStringList.h.

◆ operator delete[]()

void mrpt::utils::CStringList::operator delete[] ( void ptr)
inlinenoexcept

Definition at line 34 of file CStringList.h.

◆ operator new() [1/3]

static void* mrpt::utils::CStringList::operator new ( size_t  size,
void ptr 
)
inlinestatic

Definition at line 34 of file CStringList.h.

◆ operator new() [2/3]

void* mrpt::utils::CStringList::operator new ( size_t  size,
const std::nothrow_t &   
)
inlinenoexcept

Definition at line 34 of file CStringList.h.

◆ operator new() [3/3]

void* mrpt::utils::CStringList::operator new ( size_t  size)
inline

Definition at line 34 of file CStringList.h.

◆ operator new[]()

void* mrpt::utils::CStringList::operator new[] ( size_t  size)
inline

Definition at line 34 of file CStringList.h.

◆ operator()() [1/2]

string CStringList::operator() ( size_t  index) const

Returns one string from the line list.

Definition at line 259 of file CStringList.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ operator()() [2/2]

string & CStringList::operator() ( size_t  index)

Returns a reference to one string from the line list.

Definition at line 271 of file CStringList.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ operator<<()

CStringList& mrpt::utils::CStringList::operator<< ( const std::string s)
inline

An alternative way of adding strings to the list.

Definition at line 68 of file CStringList.h.

References add().

Here is the call graph for this function:

◆ readFromStream()

void CStringList::readFromStream ( mrpt::utils::CStream in,
int  version 
)
overrideprotectedvirtual

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.

Parameters
inThe input binary stream where the object data must read from.
versionThe version of the object stored in the stream: use this version number in your code to know how to read the incoming data.
Exceptions
std::exceptionOn any error, see CStream::ReadBuffer
See also
CStream

Implements mrpt::utils::CSerializable.

Definition at line 219 of file CStringList.cpp.

References MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION.

◆ remove()

void CStringList::remove ( size_t  index)

Delete the element at a given position (0=first element)

Definition at line 77 of file CStringList.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ saveToFile()

void CStringList::saveToFile ( const std::string fileName) const

Save the string list to a file.

Definition at line 182 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ set() [1/6]

void CStringList::set ( size_t  index,
const std::string str 
)

Overwrites an existing position with a new value (0=first elements)

See also
insert

Definition at line 60 of file CStringList.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ set() [2/6]

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 348 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ set() [3/6]

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 374 of file CStringList.cpp.

References mrpt::format(), MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ set() [4/6]

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 383 of file CStringList.cpp.

References mrpt::format(), MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ set() [5/6]

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 393 of file CStringList.cpp.

References mrpt::format(), MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ set() [6/6]

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 403 of file CStringList.cpp.

References MRPT_END, and MRPT_START.

◆ setText()

void CStringList::setText ( const std::string inText)

Fills the string list by parsing a single string with '', '
', or '
' characters indicatng newlines.

Definition at line 145 of file CStringList.cpp.

References MRPT_END, MRPT_START, and mrpt::system::tokenize().

Here is the call graph for this function:

◆ size()

size_t CStringList::size ( ) const

Returns the number of text lines in the list.

Definition at line 242 of file CStringList.cpp.

Referenced by mrpt::opengl::CSetOfObjects::dumpListOfObjects(), mrpt::opengl::COpenGLViewport::dumpListOfObjects(), mrpt::hwdrivers::CNTRIPClient::retrieveListOfMountpoints(), and mrpt::utils::PLY_Exporter::saveToPlyFile().

Here is the caller graph for this function:

◆ writeToMatlab()

virtual mxArray* mrpt::utils::CSerializable::writeToMatlab ( ) const
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.

Returns
A new mxArray (caller is responsible of memory freeing) or nullptr is class does not support conversion to MATLAB.

Definition at line 89 of file CSerializable.h.

◆ writeToStream()

void CStringList::writeToStream ( mrpt::utils::CStream out,
int *  getVersion 
) const
overrideprotectedvirtual

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.

Parameters
outThe output binary stream where object must be dumped.
getVersionIf nullptr, 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.
Exceptions
std::exceptionOn any error, see CStream::WriteBuffer
See also
CStream

Implements mrpt::utils::CSerializable.

Definition at line 201 of file CStringList.cpp.

Member Data Documentation

◆ _init_CStringList

mrpt::utils::CLASSINIT mrpt::utils::CStringList::_init_CStringList
staticprotected

Definition at line 34 of file CStringList.h.

◆ className

constexpr const char* mrpt::utils::CStringList::className = "CStringList"
static

Definition at line 34 of file CStringList.h.

◆ m_strings

std::deque<std::string> mrpt::utils::CStringList::m_strings
protected

The internal list of strings.

Definition at line 39 of file CStringList.h.

Referenced by CStringList().

◆ runtimeClassId

const mrpt::utils::TRuntimeClassId mrpt::utils::CStringList::runtimeClassId
staticprotected

Definition at line 34 of file CStringList.h.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019