bpp-core3
3.0.0
|
Some functions to deal with attributes, i.e. parameters passed to a program/method. More...
#include <Bpp/Utils/AttributesTools.h>
Public Member Functions | |
AttributesTools () | |
virtual | ~AttributesTools () |
Static Public Member Functions | |
static std::vector< std::string > | getVector (int argc, char *argv[]) |
Get attributes a vector of strings from command line arguments. More... | |
static std::map< std::string, std::string > | getAttributesMap (const std::vector< std::string > &argv, const std::string &delimiter="=") |
Get an attribute map from a vector of arguments. More... | |
static void | getAttributesMap (const std::vector< std::string > &argv, std::map< std::string, std::string > &am, const std::string &delimiter="=") |
Get an attribute map from a vector of arguments. More... | |
static std::map< std::string, std::string > | getAttributesMapFromFile (const std::string &file, const std::string &delimiter) |
Get an attribute map from a file. More... | |
static void | getAttributesMapFromFile (const std::string &file, std::map< std::string, std::string > ¶ms, const std::string &delimiter) |
Get an attribute map from a file. More... | |
static void | actualizeAttributesMap (std::map< std::string, std::string > &attMap, const std::map< std::string, std::string > &atts, bool replace=true) |
Actualizes an attribute map with another. More... | |
static void | resolveVariables (std::map< std::string, std::string > &am, char varCode='$', char varBeg='(', char varEnd=')') |
Resolve the variables. More... | |
static std::map< std::string, std::string > | parseOptions (int args, char **argv) |
Global function that reads all parameters from command line and files, and set the values in a map. More... | |
Static Private Member Functions | |
static std::string | removeComments (const std::string &s, const std::string &begin, const std::string &end) |
Remove comments from a string. More... | |
Static Private Attributes | |
static std::vector< std::string > | vParam_ |
Some functions to deal with attributes, i.e. parameters passed to a program/method.
These methods allows you to retrieve attributes from command line arguments or from a file. The underlying syntax is attributeName = argument
. Here the delimiter char is '=', but another character may be used.
In files, shell comments: # my comment line here
, C comments: / * my comment block here * /
(but multiline not supported!) and C++ comments: // my comment line here
are allowed, and ignored while parsing.
Lines may be broken, using the bash character '\' at the end of the line:
will be read as
Attributes are stored as a map<string, string>, with attributes names as keys, and arguments as values.
Here is an example of use. This piece of code typically is at the begining of the main function. It uses the FileTools and ApplicationTools classes, for checking file existence and displaying messages respectively.
These pieces of code does the following:
Support for variable is also available. A variable character is specified (typically '$()') and may be used to de-reference any argument. For instance,
will be equivalent to
Definition at line 93 of file AttributesTools.h.
|
inline |
Definition at line 104 of file AttributesTools.h.
|
inlinevirtual |
Definition at line 105 of file AttributesTools.h.
References actualizeAttributesMap(), getAttributesMap(), getAttributesMapFromFile(), getVector(), parseOptions(), removeComments(), and resolveVariables().
|
static |
Actualizes an attribute map with another.
All fields in map 2 will be added to map 1. If two attributes have the same name, then map 1 value will be overwritten.
attMap | The attributes map. |
atts | The attributes to add to the map. |
replace | if existing params of attMap should be replaced |
Definition at line 121 of file AttributesTools.cpp.
Referenced by ~AttributesTools().
|
static |
Get an attribute map from a vector of arguments.
This method also resolve all variable calls.
argv | The vector of arguments. |
delimiter | The string that separates attribute names from arguments (for instance '='). |
Definition at line 40 of file AttributesTools.cpp.
Referenced by ~AttributesTools().
|
static |
Get an attribute map from a vector of arguments.
This method also resolve all variable calls.
argv | The vector of arguments. |
am | The attribute map to fill. |
delimiter | The string that separates attribute names from arguments (for instance '='). |
Definition at line 51 of file AttributesTools.cpp.
References bpp::TextTools::removeWhiteSpaces().
|
static |
Get an attribute map from a file.
file | The file with all arguments. |
delimiter | The string that separates attribute names from arguments (for instance '='). |
Definition at line 110 of file AttributesTools.cpp.
Referenced by ~AttributesTools().
|
static |
Get an attribute map from a file.
file | The file with all arguments. |
params | An attribute map to fill. |
delimiter | The string that separates attribute names from arguments (for instance '='). |
Definition at line 97 of file AttributesTools.cpp.
|
static |
Get attributes a vector of strings from command line arguments.
argc | The number of arguments. |
argv | The array with all arguments. |
Definition at line 26 of file AttributesTools.cpp.
Referenced by ~AttributesTools().
|
static |
Global function that reads all parameters from command line and files, and set the values in a map.
args | Number of arguments, as passed to the main function. |
argv | Array of values, as passed to the main function. |
Exception | in case an option file is not found. |
Definition at line 216 of file AttributesTools.cpp.
References bpp::StringTokenizer::hasMoreToken(), and bpp::StringTokenizer::nextToken().
Referenced by bpp::BppApplication::BppApplication(), and ~AttributesTools().
|
staticprivate |
Remove comments from a string.
s | The string to parse. |
begin | Comments front delimiter. |
end | Comments end delimiter. |
Definition at line 187 of file AttributesTools.cpp.
Referenced by ~AttributesTools().
|
static |
Resolve the variables.
If used prior to the actualizeAttributesMap, this function will make the variables 'local', whereas using them after will make them 'global'.
am | The attributes map. |
varCode | The code that defines variable recalls. |
varBeg | Variables begin name code. |
varEnd | Variables end name code. |
Exception | If there is a syntax error. |
Definition at line 135 of file AttributesTools.cpp.
References bpp::TextTools::toString().
Referenced by ~AttributesTools().
|
staticprivate |
Definition at line 101 of file AttributesTools.h.