diff --git a/include/core/utils/converter.h b/include/core/utils/converter.h index 76e710f75d4aeb31589e27aa819304ec0b8d9cec..0c9502c4ec0cc12ce041611d3a86d5c035af9d09 100644 --- a/include/core/utils/converter.h +++ b/include/core/utils/converter.h @@ -20,9 +20,35 @@ /** @file + converter.h + @brief This file implements a set of simple functions that deal with the correspondence between + classes and their string representation. The YAML autosetup framework makes heavy use of this file. + */ + +//Note: In order to deal with string representations we make heavy use of regexps. +// We use the standard C++11 regular expressions capabilities. + +/* +** This file is structured essentially in two parts: +** in the first part (which starts after the CONVERTERS ~~~~ STRING ----> TYPE line) +** we have functions to convert from string to C++ class. For example: + string v1 = "[3,4,5,6,7,8,9,10,11]"; + vector<int> v = converter<vector<int>>::convert(v1); + This code snippet transforms the string v1 which represents an std::vector into an actual std::vector value. + The second part (which starts after the TYPES ----> ToSTRING line) has the functions to + transform from C++ classes to strings. For instance, if we wanted to convert from a C++ class + to a string we would do something like this: + vector<int> vect{ 10, 20, 30 }; + string str = converter<std::string>::convert(vect); + //str == "[10,20,30]" */ namespace wolf{ + //This definition is a bit of a "hack". The reason of redefining the pair class is to be able + //to have two string representations of a pair, namely + //"(·,·)" -> typical pair/tuple representation + //"{·,·}" -> key-value pair representation used to represent maps. + //This is purely an aesthetic reason and could be removed without problems. template<class A, class B> struct Wpair : std::pair<A,B> { diff --git a/src/yaml/parser_yaml.cpp b/src/yaml/parser_yaml.cpp index d50e1b53096e248e5b5776243ad1aa831b41b50c..6efc250f44ed45f4da571bb747f8cc9fb875f4f6 100644 --- a/src/yaml/parser_yaml.cpp +++ b/src/yaml/parser_yaml.cpp @@ -345,6 +345,12 @@ void ParserYaml::updateActiveName(std::string _tag) { active_name_ = _tag; } +/* +** @brief This function is responsible for parsing the first level of the YAML file. +** The first level here can be thought as the entry point of the YAML file. Since we impose a certain structure +** this function is responsible for enforcing said structure. +** + */ void ParserYaml::parseFirstLevel(YAML::Node _n, std::string _file) { @@ -550,6 +556,9 @@ void ParserYaml::parse() } parsing_file_.pop(); } +/* +** @brief This function gives the ability to run the parser without enforcing the wolf YAML structure. + */ void ParserYaml::parse_freely() { parsing_file_.push(generatePath(file_));