iRoCS Toolbox
1.1.0
|
#include <StDataCmdLine.hh>
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 > ¶ms) |
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 |
Definition at line 71 of file StDataCmdLine.hh.
|
inline |
Constructors.
Definition at line 80 of file StDataCmdLine.hh.
|
inline |
Definition at line 85 of file StDataCmdLine.hh.
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
argc | number of arguments including program name |
argv | array of c-style-strings containing arguments |
ParseCmdLineError |
Referenced by StDataCmdLine().
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()
params | array of ParamInfos, where the shortKey() and longKey() of each ParamInfo is used |
Referenced by StDataCmdLine().
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()
ParseCmdLineError | unknown short key or ambiguos short key |
Referenced by StDataCmdLine().
|
inline |
return the mode (1st Command line argument) that was extracted by parseCommandline()
Definition at line 163 of file StDataCmdLine.hh.
|
inline |
return the filenames that were extracted by parseCommandline()
Definition at line 176 of file StDataCmdLine.hh.
|
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()
key | the key for the requested value |
value | (output) returned value. |
KeyNotFoundError | the requested key does not exist |
InvalidDataTypeError | the value string couldn't be converted to the requested type |
Definition at line 202 of file StDataCmdLine.hh.
|
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()
key | the key for the requested value |
arrBegin | iterator pointing to your container, that has enough space to store all values. You can query the required size with getArraySize(). |
containerSize | optional parameter to tell the size of your container, so that an error can be thrown, wenn it would be exeeded. |
KeyNotFoundError | the requested key does not exist |
InvalidDataTypeError | the value string couldn't be converted to the requested type |
Definition at line 233 of file StDataCmdLine.hh.
|
inline |
return the key Occurence map.
In this map each access to a certain key via getValue or getArray is counted
Definition at line 250 of file StDataCmdLine.hh.
|
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.
|
inline |
check if the parameter "--help" was given
Definition at line 309 of file StDataCmdLine.hh.
|
inline |
Definition at line 315 of file StDataCmdLine.hh.
|
inlineinherited |
Specify, if getValue() should throw expcetions for unknown keys.
f | true: getValue() should throw expcetions for unknown keys |
Definition at line 105 of file StDataASCII.hh.
|
inlineinherited |
Definition at line 116 of file StDataASCII.hh.
|
inlineinherited |
check wether a value exists for requested key
key | the key |
Definition at line 131 of file StDataASCII.hh.
|
inherited |
setValue writes/adds a value (with arbitrary type) to the internal map<string,string>.
key | the key for that value |
value | the value itself |
Referenced by svt::Model< FV >::setTrainingInfoValue(), and svt::StDataASCII::valueExists().
|
inherited |
setArray writes/adds an array of values (with arbitrary type) to the internal map<string,string>.
key | the key for that value |
arrBegin | begin of container |
size | number of elements |
Referenced by svt::StDataASCII::valueExists().
|
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*>
key | the key for that value |
arrBegin | begin of container |
size | number of elements in the container |
Referenced by svt::StDataASCII::valueExists().
|
inherited |
get size of Array associated with given key.
key | the key for that value |
Referenced by svt::StDataASCII::valueExists().
|
inherited |
get number of Feature vectors in the list associated with that kay
key | the key for that value |
Referenced by svt::StDataASCII::valueExists().
|
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
key | the key for the requested value |
arrBegin | iterator pointing to your container, that has enough space to store all values. You can query the required size with getFVArraySize(). |
containerSize | optional parameter to tell the size of your container, so that an error can be thrown, wenn it would be exeeded. |
KeyNotFoundError | the requested key does not exist |
InvalidDataTypeError | the value string couldn't be converted to the requested type |
Referenced by svt::StDataASCII::valueExists().
|
inlineinherited |
set character to separate elements of vectors within the value-string.
Default is ','
Definition at line 293 of file StDataASCII.hh.
|
inlineinherited |
Definition at line 298 of file StDataASCII.hh.
|
inlineinherited |
return the associated string to the given key directly
key | the key for the requested value |
KeyNotFoundError | the requested key does not exist |
Definition at line 315 of file StDataASCII.hh.
|
inlineinherited |
Definition at line 331 of file StDataASCII.hh.
Referenced by svt::Model< FV >::getTrainingInfoValue().
|
inlineinherited |
Definition at line 339 of file StDataASCII.hh.
|
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
s | string |
val | (output) value |
InvalidDataTypeError | if conversion failed |
Definition at line 360 of file StDataASCII.hh.
|
inlineinherited |
Definition at line 373 of file StDataASCII.hh.
|
inherited |
Referenced by svt::StDataASCII::stringToValue().
|
inlineinherited |
const access to internal map
Definition at line 392 of file StDataASCII.hh.
Referenced by findUnusedParameters(), svt::Model< FV >::saveTrainingInfo(), and svt::Model< FV >::trainingInfoPlainText().
|
inlineinherited |
Definition at line 397 of file StDataASCII.hh.
Referenced by findUnusedParameters(), svt::Model< FV >::saveTrainingInfo(), and svt::Model< FV >::trainingInfoPlainText().
|
inlineinherited |
|
protectedinherited |
Definition at line 469 of file StDataASCII.hh.
Referenced by svt::StDataASCII::asString(), svt::StDataASCII::begin(), svt::StDataASCII::debugPrint(), svt::StDataASCII::end(), and svt::StDataASCII::valueExists().
|
protectedinherited |
Definition at line 470 of file StDataASCII.hh.
Referenced by svt::StDataASCII::debugPrint(), svt::StDataASCII::exceptionFlag(), and svt::StDataASCII::setExceptionFlag().
|
protectedinherited |
Definition at line 471 of file StDataASCII.hh.
Referenced by svt::StDataASCII::separatorChar(), and svt::StDataASCII::setSeparatorChar().