Main MRPT website > C++ reference
MRPT logo
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 49 of file CStringList.h.

#include <mrpt/utils/CStringList.h>

Inheritance diagram for mrpt::utils::CStringList:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CStringList ()
 Default constructor (empty string list).
 CStringList (const std::string &text)
 Constructor from a text.
void add (const std::string &str)
 Appends a new string at the end of the string list.
CStringListoperator<< (const std::string &s)
 An alternative way of adding strings to the list.
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,...).
void set (size_t index, const std::string &str)
 Overwrites an existing position with a new value (0=first elements).
void clear ()
 Clear the whole list.
size_t size () const
 Returns the number of text lines in the list.
void remove (size_t index)
 Delete the element at a given position (0=first element).
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.
void get (size_t index, std::string &outText) const
 Returns one string from the line list.
std::string operator() (size_t index) const
 Returns one string from the line list.
std::string & operator() (size_t index)
 Returns a reference to one string from the line list.
void getText (std::string &outText) const
 Returns the whole string list as a single string with '
' characters for newlines.
std::string getText () const
 Returns the whole string list as a single string with '
' characters for newlines.
void setText (const std::string &inText)
 Fills the string list by parsing a single string with '', '
', or '
' characters indicatng newlines.
void loadFromFile (const std::string &fileName)
 Load the string list from a file.
void saveToFile (const std::string &fileName) const
 Save the string list to a file.
std::string get_string (const std::string &keyName)
 Returns the value of the given key ("key=value").
float get_float (const std::string &keyName)
 Returns the value of the given key ("key=value").
int get_int (const std::string &keyName)
 Returns the value of the given key ("key=value").
double get_double (const std::string &keyName)
 Returns the value of the given key ("key=value").
bool get_bool (const std::string &keyName)
 Returns the value of the given key ("key=value").
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.
void set (const std::string &keyName, const int &value)
 Sets the value of a given key ("key=value"), overwritten previous value if it existed.
void set (const std::string &keyName, const float &value)
 Sets the value of a given key ("key=value"), overwritten previous value if it existed.
void set (const std::string &keyName, const double &value)
 Sets the value of a given key ("key=value"), overwritten previous value if it existed.
void set (const std::string &keyName, const bool &value)
 Sets the value of a given key ("key=value"), overwritten previous value if it existed.

Protected Attributes

std::deque< std::string > m_strings
 The internal list of strings.

RTTI stuff



typedef CStringListPtr SmartPtr
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.
virtual mrpt::utils::CObjectduplicate () const
 Returns a copy of the object, indepently of its class.
static mrpt::utils::CObjectCreateObject ()
static CStringListPtr Create ()

Member Typedef Documentation

A typedef for the associated smart pointer

Definition at line 52 of file CStringList.h.


Constructor & Destructor Documentation

mrpt::utils::CStringList::CStringList (  ) 

Default constructor (empty string list).

mrpt::utils::CStringList::CStringList ( const std::string &  text  ) 

Constructor from a text.


Member Function Documentation

static const mrpt::utils::TRuntimeClassId* mrpt::utils::CStringList::_GetBaseClass (  )  [static, protected]

Reimplemented from mrpt::utils::CSerializable.

void mrpt::utils::CStringList::add ( const std::string &  str  ) 

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

See also:
insert,set
void mrpt::utils::CStringList::clear (  ) 

Clear the whole list.

static CStringListPtr mrpt::utils::CStringList::Create (  )  [static]
static mrpt::utils::CObject* mrpt::utils::CStringList::CreateObject (  )  [static]
virtual mrpt::utils::CObject* mrpt::utils::CStringList::duplicate (  )  const [virtual]

Returns a copy of the object, indepently of its class.

Implements mrpt::utils::CObject.

bool mrpt::utils::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.
void mrpt::utils::CStringList::get ( size_t  index,
std::string &  outText 
) const

Returns one string from the line list.

bool mrpt::utils::CStringList::get_bool ( const std::string &  keyName  ) 

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

Exceptions:
std::exception If the key is not found in the string list.
double mrpt::utils::CStringList::get_double ( const std::string &  keyName  ) 

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

Exceptions:
std::exception If the key is not found in the string list.
float mrpt::utils::CStringList::get_float ( const std::string &  keyName  ) 

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

Exceptions:
std::exception If the key is not found in the string list.
int mrpt::utils::CStringList::get_int ( const std::string &  keyName  ) 

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

Exceptions:
std::exception If the key is not found in the string list.
std::string mrpt::utils::CStringList::get_string ( const std::string &  keyName  ) 

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

Exceptions:
std::exception If the key is not found in the string list.
virtual const mrpt::utils::TRuntimeClassId* mrpt::utils::CStringList::GetRuntimeClass (  )  const [virtual]

Returns information about the class of an object in runtime.

Reimplemented from mrpt::utils::CSerializable.

void mrpt::utils::CStringList::getText ( std::string &  outText  )  const

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

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

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

Definition at line 124 of file CStringList.h.

void mrpt::utils::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
void mrpt::utils::CStringList::loadFromFile ( const std::string &  fileName  ) 

Load the string list from a file.

std::string& mrpt::utils::CStringList::operator() ( size_t  index  ) 

Returns a reference to one string from the line list.

std::string mrpt::utils::CStringList::operator() ( size_t  index  )  const

Returns one string from the line list.

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

An alternative way of adding strings to the list.

Definition at line 74 of file CStringList.h.

void mrpt::utils::CStringList::remove ( size_t  index  ) 

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

void mrpt::utils::CStringList::saveToFile ( const std::string &  fileName  )  const

Save the string list to a file.

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

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

See also:
insert
void mrpt::utils::CStringList::set ( const std::string &  keyName,
const bool &  value 
)

Sets the value of a given key ("key=value"), overwritten previous value if it existed.

void mrpt::utils::CStringList::set ( const std::string &  keyName,
const int &  value 
)

Sets the value of a given key ("key=value"), overwritten previous value if it existed.

void mrpt::utils::CStringList::set ( const std::string &  keyName,
const double &  value 
)

Sets the value of a given key ("key=value"), overwritten previous value if it existed.

void mrpt::utils::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.

void mrpt::utils::CStringList::set ( const std::string &  keyName,
const float &  value 
)

Sets the value of a given key ("key=value"), overwritten previous value if it existed.

void mrpt::utils::CStringList::setText ( const std::string &  inText  ) 

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

size_t mrpt::utils::CStringList::size (  )  const

Returns the number of text lines in the list.


Member Data Documentation

Definition at line 52 of file CStringList.h.

Definition at line 52 of file CStringList.h.

Definition at line 52 of file CStringList.h.

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

The internal list of strings.

Definition at line 57 of file CStringList.h.




Page generated by Doxygen 1.7.1 for MRPT 0.9.4 SVN: at Mon Jan 10 23:33:19 UTC 2011