COOLFluiD
Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
|
#include <Map.hpp>
Public Member Functions | |
Map (XmlNode node=XmlNode()) | |
XmlNode | set_value (const std::string &value_key, const std::string type_name, const std::string &value_str, const std::string &descr=std::string()) |
XmlNode | set_array (const std::string &value_key, const std::string element_type_name, const std::string &value_str, const std::string &delimiter, const std::string &descr=std::string()) |
XmlNode | find_value (const std::string &value_key=std::string(), const char *value_type=nullptr) const |
Searches for a value in this map. More... | |
bool | check_entry (const std::string &entry_key) const |
Checks whether an entry exists or not. More... | |
template<typename TYPE > | |
TYPE | get_value (const std::string &val_key) const |
template<typename TYPE > | |
std::vector< TYPE > | get_array (const std::string &val_key) const |
template<typename TYPE > | |
std::vector< TYPE > | array_to_vector (const XmlNode &array_node, std::string *delim=nullptr) const |
Static Public Member Functions | |
static bool | is_single_value (const XmlNode &node) |
static bool | is_array_value (const XmlNode &node) |
static const char * | get_value_type (const XmlNode &node) |
template<typename TYPE > | |
static void | split_string (const std::string &str, const std::string &delimiter, std::vector< TYPE > &result, int size=-1) |
Public Attributes | |
XmlNode | content |
The managed node. More... | |
Static Private Member Functions | |
template<typename TYPE > | |
static bool | value_has_ptr (const XmlNode &node) |
Manages maps in a XML tree. A map is an associative container of values: it contains values identified by a unique name (the "key"). Each value can contain another map. There are two kind of values: single values and array values. Single values contain only one value of a certain type and array ones may contain several values (each of the same type).
A value has an assigned type (one of those supported by #from_value()
) which cannot be changed (from example, a bool
value cannot be changed to int
). An existing value can be modified using set_value()
or set_array()
. If it does not exist, these function automatically add it.
A value can have a restricted list of values. This is an array that defines the acceptable values. Setting a restricted to value is the same as setting a array to it.
std::vector< TYPE > array_to_vector | ( | const XmlNode & | array_node, |
std::string * | delim = nullptr |
||
) | const |
Converts an array XML node to a vector of TYPE
array_node | The array node to convert. Must be valid. |
delim | A pointer a string where the delimiter will be stored. Can be NULL. |
XmlError | if no delimiter is found. |
ParsingFailed | if no size is found or if the found size does not match with the number of found elements. |
bool check_entry | ( | const std::string & | entry_key | ) | const |
XmlNode find_value | ( | const std::string & | value_key = std::string() , |
const char * | value_type = nullptr |
||
) | const |
Searches for a value in this map.
value_key | The key (name) of the wanted value. May be empty. |
value_type | The value type (single value or array). Three values are accepted : Protocol::Tags::node_value() (for a value), Protocol::Tags::node_array() (for an array) and an empty string (any type). |
value_type
is not valid, a null pointer is returned as well. std::vector< TYPE > get_array | ( | const std::string & | val_key | ) | const |
Searches an array in the provided map and converts it to std::vector<TYPE>.
map | The map under which the array has to searched for. |
val_key | The array key. |
TYPE get_value | ( | const std::string & | val_key | ) | const |
|
static |
Gives the type name of a provided value node.
node | The node to process. Must be valid. |
XmlError | If
|
|
static |
Checks whether the provided node represents an array value.
node | The node to check. |
true
if the node represents a array value. Otherwise, returns false
.
|
static |
Checks whether the provided node represents a single value.
node | The node to check. |
true
if the node represents a single value. Otherwise, returns false
. XmlNode set_array | ( | const std::string & | value_key, |
const std::string | element_type_name, | ||
const std::string & | value_str, | ||
const std::string & | delimiter, | ||
const std::string & | descr = std::string() |
||
) |
Adds or modifies an array value. The TYPE must be one of those supported by #from_value()
. If no value with the provided key exists, a single value is created. If it already exists and is a single value, it is modified. An array value cannot be modified as a single one.
value_key | The value key (name). Cannot be empty. |
type_name | The string description of the type of a single element |
value_str | The value, as string, for the entire array |
descr | Description |
BadValue | If the value key is empty. |
XmlNode set_value | ( | const std::string & | value_key, |
const std::string | type_name, | ||
const std::string & | value_str, | ||
const std::string & | descr = std::string() |
||
) |
Adds or modifies a value. The TYPE must be one of those supported by #from_value()
. If no value with the provided key exists, a single value is created. If it already exists and is a single value, it is modified. An array value cannot be modified as a single one.
value_key | The value key (name). Cannot be empty. |
type_name | The string description of the type |
value_str | The value, as string |
descr | Description |
|
static |
Splits a string and casts each resulting part to TYPE. This function can whether the number of elements to read is known or or not. If the size is known the provided vector is cleared and initialized to contain this number of items. This way is more efficient, of course, because there is no reallocation needed. If the size if not defined, elements are appended to the vector by using push_back()
.
str | The string to split. |
delimiter | The string that delimitates the parts. It will not appear in the result . |
result | The vector where cast parts are stored. |
size | If greater or equal to 0, gives the number of elements to read. Otherwise, the vector is reallocated as the elements are added. |
CastingFailed | If an item cannot be cast to TYPE. |
|
staticprivate |
Checks whether the provided has the type TYPE. This function can be called for both single and array values.
node | The node to check. |
true
if the value has the correct type. Otherwise, or if the node is not valid or is neither a signle value nor an array value, returns false
.
Send comments to: COOLFluiD Web Admin |