iRoCS Toolbox  1.1.0
Public Member Functions | Protected Attributes
svt::StDataASCIIFile Class Reference

#include <StDataASCIIFile.hh>

Inheritance diagram for svt::StDataASCIIFile:
Collaboration diagram for svt::StDataASCIIFile:

Public Member Functions

double asDouble (const std::string &key) const
 
const std::string & asString (const std::string &key) const
 return the associated string to the given key directly More...
 
unsigned int asUint (const std::string &key) const
 
std::map< std::string, std::string >::const_iterator begin () const
 const access to internal map More...
 
void debugPrint (std::ostream &os) const
 for debugging print whole internal map More...
 
std::map< std::string, std::string >::const_iterator end () const
 
bool exceptionFlag () const
 
template<typename ForwardIter >
void getArray (const std::string &key, const ForwardIter &arrBegin, int containerSize=-1) const
 getArray. More...
 
size_t getArraySize (std::string key) const
 get size of Array associated with given key. More...
 
template<typename ForwardIter >
void getFVArray (const std::string &key, const ForwardIter &arrBegin, int containerSize=-1) const
 get a list (or a 1D array) of feature vectors. More...
 
size_t getFVArraySize (std::string key) const
 get number of Feature vectors in the list associated with that kay More...
 
template<typename T >
void getValue (const std::string &key, T &value) const
 get a value (with arbitrary type) from the internal map<string,string> specified by the given key. More...
 
void load (std::istream &is, int compatibilityFlag=0)
 loads the map from given istream in the style key[space]value[newline], e.g., two_class_type c_svc kernel_type rbf gamma 40 ... More...
 
void readArraySizeFromStream (std::istream &is, size_t &size) const
 
void save (std::ostream &os, int compatibilityFlag=0) const
 saves the map to given ostream in the style key[space]value[newline], e.g., two_class_type c_svc kernel_type rbf gamma 40 ... More...
 
char separatorChar () const
 
template<typename ForwardIter >
void setArray (const std::string &key, const ForwardIter &arrBegin, size_t size)
 setArray writes/adds an array of values (with arbitrary type) to the internal map<string,string>. More...
 
void setExceptionFlag (bool f)
 Specify, if getValue() should throw expcetions for unknown keys. More...
 
template<typename ForwardIter >
void setFVArray (const std::string &key, const ForwardIter &arrBegin, size_t size)
 setFVPList writes/adds a list (or a 1D array) of feature vectors to the internal map<string,string>. More...
 
void setSeparatorChar (char c)
 set character to separate elements of vectors within the value-string. More...
 
template<typename T >
void setValue (const std::string &key, const T &value)
 setValue writes/adds a value (with arbitrary type) to the internal map<string,string>. More...
 
template<typename T >
void stringToValue (const std::string &s, T &value) const
 convert any std::string to any type using an std::istringstream. More...
 
void stringToValue (const std::string &s, std::string &value) const
 
bool valueExists (const std::string &key) const
 check wether a value exists for requested key More...
 

Protected Attributes

bool _exceptionFlag
 
std::map< std::string, std::string > _map
 
char _separatorChar
 

Detailed Description

Definition at line 58 of file StDataASCIIFile.hh.

Member Function Documentation

◆ load()

void svt::StDataASCIIFile::load ( std::istream &  is,
int  compatibilityFlag = 0 
)

loads the map from given istream in the style key[space]value[newline], e.g., two_class_type c_svc kernel_type rbf gamma 40 ...

To be compatible with Chih-Jen Lin's libsvm model files set the compatibilityFlag to 1. Attention: the map is not cleared before loading the new key/value pairs!

Parameters
isinput stream
compatibilityFlag0 or 1
Exceptions
LoadErrorincompatible file format

◆ save()

void svt::StDataASCIIFile::save ( std::ostream &  os,
int  compatibilityFlag = 0 
) const

saves the map to given ostream in the style key[space]value[newline], e.g., two_class_type c_svc kernel_type rbf gamma 40 ...

To be compatible with Chih-Jen Lin's libsvm model files set the compatibilityFlag to 1

Parameters
osoutput stream
compatibilityFlag0 or 1

◆ setExceptionFlag()

void svt::StDataASCII::setExceptionFlag ( bool  f)
inlineinherited

Specify, if getValue() should throw expcetions for unknown keys.

Parameters
ftrue: getValue() should throw expcetions for unknown keys

Definition at line 105 of file StDataASCII.hh.

◆ exceptionFlag()

bool svt::StDataASCII::exceptionFlag ( ) const
inlineinherited
Returns
value of exceptionFlag (see setExceptionFlag())

Definition at line 116 of file StDataASCII.hh.

◆ valueExists()

bool svt::StDataASCII::valueExists ( const std::string &  key) const
inlineinherited

check wether a value exists for requested key

Parameters
keythe key
Returns
true or false

Definition at line 131 of file StDataASCII.hh.

◆ setValue()

template<typename T >
void svt::StDataASCII::setValue ( const std::string &  key,
const T &  value 
)
inherited

setValue writes/adds a value (with arbitrary type) to the internal map<string,string>.

Parameters
keythe key for that value
valuethe value itself

Referenced by svt::Model< FV >::setTrainingInfoValue(), and svt::StDataASCII::valueExists().

◆ setArray()

template<typename ForwardIter >
void svt::StDataASCII::setArray ( const std::string &  key,
const ForwardIter &  arrBegin,
size_t  size 
)
inherited

setArray writes/adds an array of values (with arbitrary type) to the internal map<string,string>.

Parameters
keythe key for that value
arrBeginbegin of container
sizenumber of elements

Referenced by svt::StDataASCII::valueExists().

◆ setFVArray()

template<typename ForwardIter >
void svt::StDataASCII::setFVArray ( const std::string &  key,
const ForwardIter &  arrBegin,
size_t  size 
)
inherited

setFVPList writes/adds a list (or a 1D array) of feature vectors to the internal map<string,string>.

arrBegin must point to the begin of linear array with pointers to the feature vectors, e.g. std::vector<BasicFV*>

Parameters
keythe key for that value
arrBeginbegin of container
sizenumber of elements in the container

Referenced by svt::StDataASCII::valueExists().

◆ getValue()

template<typename T >
void svt::StDataASCII::getValue ( const std::string &  key,
T &  value 
) const
inherited

get a value (with arbitrary type) from the internal map<string,string> specified by the given key.

If key is not found, the value remains unchanged and depending on exceptionFlag() a KeyNotFoundError exception is thrown.

Parameters
keythe key for the requested value
value(output) returned value.
Exceptions
KeyNotFoundErrorthe requested key does not exist
InvalidDataTypeErrorthe value string couldn't be converted to the requested type

Referenced by svt::StDataASCII::asDouble(), svt::StDataASCII::asUint(), svt::StDataCmdLine::getValue(), svt::Model< FV >::saveTrainingInfo(), and svt::StDataASCII::valueExists().

◆ getArraySize()

size_t svt::StDataASCII::getArraySize ( std::string  key) const
inherited

get size of Array associated with given key.

Parameters
keythe key for that value
Returns
number of elements

Referenced by svt::StDataASCII::valueExists().

◆ getFVArraySize()

size_t svt::StDataASCII::getFVArraySize ( std::string  key) const
inherited

get number of Feature vectors in the list associated with that kay

Parameters
keythe key for that value
Returns
number of elements

Referenced by svt::StDataASCII::valueExists().

◆ getArray()

template<typename ForwardIter >
void svt::StDataASCII::getArray ( const std::string &  key,
const ForwardIter &  arrBegin,
int  containerSize = -1 
) const
inherited

getArray.

The values must be separated by separatorChar(), e.g. mymap["nr_sv"] = "150 120". See getValue() above for further details.

Parameters
keythe key for the requested value
arrBeginiterator pointing to your container, that has enough space to store all values. You can query the required size with getArraySize().
containerSizeoptional parameter to tell the size of your container, so that an error can be thrown, wenn it would be exeeded.
Exceptions
KeyNotFoundErrorthe requested key does not exist
InvalidDataTypeErrorthe value string couldn't be converted to the requested type

Referenced by svt::StDataCmdLine::getArray(), and svt::StDataASCII::valueExists().

◆ getFVArray()

template<typename ForwardIter >
void svt::StDataASCII::getFVArray ( const std::string &  key,
const ForwardIter &  arrBegin,
int  containerSize = -1 
) const
inherited

get a list (or a 1D array) of feature vectors.

The Iterator must point to a container with Feature vector pointers. The pointers must point to already allocated feature vectors

Parameters
keythe key for the requested value
arrBeginiterator pointing to your container, that has enough space to store all values. You can query the required size with getFVArraySize().
containerSizeoptional parameter to tell the size of your container, so that an error can be thrown, wenn it would be exeeded.
Exceptions
KeyNotFoundErrorthe requested key does not exist
InvalidDataTypeErrorthe value string couldn't be converted to the requested type

Referenced by svt::StDataASCII::valueExists().

◆ setSeparatorChar()

void svt::StDataASCII::setSeparatorChar ( char  c)
inlineinherited

set character to separate elements of vectors within the value-string.

Default is ','

Definition at line 293 of file StDataASCII.hh.

◆ separatorChar()

char svt::StDataASCII::separatorChar ( ) const
inlineinherited

Definition at line 298 of file StDataASCII.hh.

◆ asString()

const std::string& svt::StDataASCII::asString ( const std::string &  key) const
inlineinherited

return the associated string to the given key directly

Parameters
keythe key for the requested value
Exceptions
KeyNotFoundErrorthe requested key does not exist
Returns
const reference to string

Definition at line 315 of file StDataASCII.hh.

◆ asDouble()

double svt::StDataASCII::asDouble ( const std::string &  key) const
inlineinherited

Definition at line 331 of file StDataASCII.hh.

Referenced by svt::Model< FV >::getTrainingInfoValue().

◆ asUint()

unsigned int svt::StDataASCII::asUint ( const std::string &  key) const
inlineinherited

Definition at line 339 of file StDataASCII.hh.

◆ stringToValue() [1/2]

template<typename T >
void svt::StDataASCII::stringToValue ( const std::string &  s,
T &  value 
) const
inlineinherited

convert any std::string to any type using an std::istringstream.

Has special overload for converting string to string, which does not split it at the first white space

Parameters
sstring
val(output) value
Exceptions
InvalidDataTypeErrorif conversion failed

Definition at line 360 of file StDataASCII.hh.

◆ stringToValue() [2/2]

void svt::StDataASCII::stringToValue ( const std::string &  s,
std::string &  value 
) const
inlineinherited

Definition at line 373 of file StDataASCII.hh.

◆ readArraySizeFromStream()

void svt::StDataASCII::readArraySizeFromStream ( std::istream &  is,
size_t &  size 
) const
inherited

◆ begin()

std::map<std::string, std::string>::const_iterator svt::StDataASCII::begin ( ) const
inlineinherited

const access to internal map

Parameters

Definition at line 392 of file StDataASCII.hh.

Referenced by svt::StDataCmdLine::findUnusedParameters(), svt::Model< FV >::saveTrainingInfo(), and svt::Model< FV >::trainingInfoPlainText().

◆ end()

std::map<std::string, std::string>::const_iterator svt::StDataASCII::end ( ) const
inlineinherited

◆ debugPrint()

void svt::StDataASCII::debugPrint ( std::ostream &  os) const
inlineinherited

for debugging print whole internal map

Parameters

Definition at line 413 of file StDataASCII.hh.

Field Documentation

◆ _map

std::map<std::string, std::string> svt::StDataASCII::_map
protectedinherited

◆ _exceptionFlag

bool svt::StDataASCII::_exceptionFlag
protectedinherited

◆ _separatorChar

char svt::StDataASCII::_separatorChar
protectedinherited

The documentation for this class was generated from the following file: