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

#include <StDataCmdLine.hh>

Inheritance diagram for svt::StDataCmdLine:
Collaboration diagram for svt::StDataCmdLine:

Public Member Functions

 StDataCmdLine ()
 Constructors. More...
 
 StDataCmdLine (int argc, const char **argv)
 
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...
 
void debugPrintShortCutTable (std::ostream &os) const
 
std::map< std::string, std::string >::const_iterator end () const
 
bool exceptionFlag () const
 
const std::vector< std::string > filenames () const
 return the filenames that were extracted by parseCommandline() More...
 
void findUnusedParameters (std::vector< std::string > &unusedParameters) const
 find unused parameters (these are parameters, that were extracted from command line ba parseCommandline()) but not yet accessed via getValue() More...
 
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...
 
bool helpRequested () const
 check if the parameter "--help" was given More...
 
std::map< std::string, int > & keyOccurenceMap ()
 return the key Occurence map. More...
 
const std::string & mode () const
 return the mode (1st Command line argument) that was extracted by parseCommandline() More...
 
void parseCommandline (int argc, const char **argv)
 parse given commandline. More...
 
void readArraySizeFromStream (std::istream &is, size_t &size) const
 
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
 
void translateShortKeys ()
 translate short keys (like "-g") to long keys ("gamma") using the internal short cut table. More...
 
void updateShortCutTable (const std::vector< ParamInfo > &params)
 update shortcut table. More...
 
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 71 of file StDataCmdLine.hh.

Constructor & Destructor Documentation

◆ StDataCmdLine() [1/2]

svt::StDataCmdLine::StDataCmdLine ( )
inline

Constructors.

Definition at line 80 of file StDataCmdLine.hh.

◆ StDataCmdLine() [2/2]

svt::StDataCmdLine::StDataCmdLine ( int  argc,
const char **  argv 
)
inline

Definition at line 85 of file StDataCmdLine.hh.

Member Function Documentation

◆ parseCommandline()

void svt::StDataCmdLine::parseCommandline ( int  argc,
const char **  argv 
)

parse given commandline.

It is interpreted as 'mode' (the first argument, accessible via mode()), after that a list of "--key value" pairs (where the '–' before the keys is removed, accessible via getValue() or getArray()) and a list of filenames (accessible via fileNames()), that are recognized by having no "-" as first character. "Two-minus" parameters are translated directly, e.g.

"--nfold 8"  -->  internalmap["nfold"] = "8";
"--multi_class_type one_vs_one" 
            -->  internalmap["multi_class_type"] = "one_vs_one";

"Single-minus" arguments (like "-g") are store unprocessed and must be translated later with translateShortKeys(). Of course you should updateShortCutTable() before that translation.

Special treatment for "--help": it can occur as first argument after filename (instead of mode), no additional value must be given and the helpRequested() flag will be set

Parameters
argcnumber of arguments including program name
argvarray of c-style-strings containing arguments
Exceptions
ParseCmdLineError

Referenced by StDataCmdLine().

◆ updateShortCutTable()

void svt::StDataCmdLine::updateShortCutTable ( const std::vector< ParamInfo > &  params)

update shortcut table.

This table maps short options (like "-mc") to their approriate long options (e.g. "--multi_class_type"). For the given params vector it iterate through all elements and adds their shorKey and LongKey to internal translation map. Multiple occurences of the same shortKey–>longKey mapping are allowed. If you try to map an existing shortKey to a different longKey, the shortKey is marked as ambiguos and will throw an exception if it occures in translateShortKeys()

Parameters
paramsarray of ParamInfos, where the shortKey() and longKey() of each ParamInfo is used

Referenced by StDataCmdLine().

◆ translateShortKeys()

void svt::StDataCmdLine::translateShortKeys ( )

translate short keys (like "-g") to long keys ("gamma") using the internal short cut table.

You can modify it with updateShortCutTable()

Exceptions
ParseCmdLineErrorunknown short key or ambiguos short key

Referenced by StDataCmdLine().

◆ mode()

const std::string& svt::StDataCmdLine::mode ( ) const
inline

return the mode (1st Command line argument) that was extracted by parseCommandline()

Returns
mode (e.g. "train", "classify", etc.

Definition at line 163 of file StDataCmdLine.hh.

◆ filenames()

const std::vector<std::string> svt::StDataCmdLine::filenames ( ) const
inline

return the filenames that were extracted by parseCommandline()

Returns
filenames

Definition at line 176 of file StDataCmdLine.hh.

◆ getValue()

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

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. In addition to getValue from StDataASCII, each requested key is stored in a second map. This map can be accessed later by keyOccurenceMap()

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

Definition at line 202 of file StDataCmdLine.hh.

◆ getArray()

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

getArray.

The values must be separated by separatorChar(), e.g. mymap["nr_sv"] = "150 120". See getValue() above for further details. In addition to getArray from StDataASCII, each requested key is stored in a second map. This map can be accessed later by keyOccurenceMap()

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

Definition at line 233 of file StDataCmdLine.hh.

◆ keyOccurenceMap()

std::map<std::string, int>& svt::StDataCmdLine::keyOccurenceMap ( )
inline

return the key Occurence map.

In this map each access to a certain key via getValue or getArray is counted

Returns
reference to the keyOccurenceMap

Definition at line 250 of file StDataCmdLine.hh.

◆ findUnusedParameters()

void svt::StDataCmdLine::findUnusedParameters ( std::vector< std::string > &  unusedParameters) const
inline

find unused parameters (these are parameters, that were extracted from command line ba parseCommandline()) but not yet accessed via getValue()

unusedParameters (output) list of unused parameters

Definition at line 266 of file StDataCmdLine.hh.

◆ helpRequested()

bool svt::StDataCmdLine::helpRequested ( ) const
inline

check if the parameter "--help" was given

Returns
true or false

Definition at line 309 of file StDataCmdLine.hh.

◆ debugPrintShortCutTable()

void svt::StDataCmdLine::debugPrintShortCutTable ( std::ostream &  os) const
inline

Definition at line 315 of file StDataCmdLine.hh.

◆ 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().

◆ 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().

◆ 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 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: