varpar.cpp v1.0.0-build
Parse variables in an env style for C++ from a .varpar file
Loading...
Searching...
No Matches
VP_Parse.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "VPpredefines.hpp"
4
5#if VP_DEFAULT_CPP_STD >= __cplusplus
6#include <string>
7#include <vector>
8#include <map>
9
10namespace vp
11{
12 /**
13 * @brief Set the error and if the `Parser` class was constructed
14 */
15 typedef struct ParserStatus
16 {
17 std::string error;
18
19 bool constructed = false;
21
22 /**
23 * @brief Returned parser information
24 * This includes the configuration, output and success of the `Parser`
25 */
26 typedef struct ParserReturn
27 {
28 std::map<std::string, std::string> config;
29
30 std::vector<std::string> output;
31
32 bool success = false;
34
35 class Parser
36 {
37 private:
38 std::string id;
39 std::string fpath;
40
43
44 std::string extension;
45
46 protected:
47 /**
48 * @brief Private member of the parse function
49 * @return ParserReturn Parsed information
50 */
51 virtual ParserReturn __parse();
52
53 public:
54 /**
55 * @brief Create the object, set errors if there are and set some configuration from the parameters
56 * @param _id Set the ID of the object
57 * @param _file Set the path of the file
58 * @param _extension Set the file extension
59 */
60 Parser(const std::string &_id, const std::string &_file, const std::string &_extension = ".varpar");
61
62 /**
63 * @brief Deconstructor
64 */
66
67 /**
68 * @brief Public API wrapper for `Parser::__parse()` function
69 * @return ParserReturn Parsed information
70 */
72
73 /**
74 * @brief Get value of _key
75 * @param _key Key value to find
76 * @return std::string Return the value
77 */
78 std::string getVal(const std::string &_key) const;
79
80 /**
81 * @brief Get the constructed starts
82 * @return ParserStatus
83 */
85
86 /**
87 * @brief Get the current object ID
88 * @return std::string Current object ID
89 */
90 std::string getID() const;
91 };
92}
93#else
94# error "Use C++17 as the minimum standard"
95#endif // VP_DEFAULT_CPP_STD >= __cplusplus
96
std::string fpath
Definition VP_Parse.hpp:39
ParserStatus checkStatus() const
Get the constructed starts.
Definition VP_Parse.cpp:114
std::string extension
Definition VP_Parse.hpp:44
Parser(const std::string &_id, const std::string &_file, const std::string &_extension=".varpar")
Create the object, set errors if there are and set some configuration from the parameters.
Definition VP_Parse.cpp:16
std::string getVal(const std::string &_key) const
Get value of _key.
Definition VP_Parse.cpp:106
virtual ParserReturn __parse()
Private member of the parse function.
Definition VP_Parse.cpp:55
ParserReturn parse()
Public API wrapper for Parser::__parse() function.
Definition VP_Parse.cpp:48
std::string id
Definition VP_Parse.hpp:38
~Parser()
Deconstructor.
ParserReturn parseRet
Definition VP_Parse.hpp:42
std::string getID() const
Get the current object ID.
Definition VP_Parse.cpp:117
ParserStatus status
Definition VP_Parse.hpp:41
struct vp::ParserStatus ParserStatus
Set the error and if the Parser class was constructed.
struct vp::ParserReturn ParserReturn
Returned parser information This includes the configuration, output and success of the Parser.
Returned parser information This includes the configuration, output and success of the Parser.
Definition VP_Parse.hpp:27
std::vector< std::string > output
Definition VP_Parse.hpp:30
std::map< std::string, std::string > config
Definition VP_Parse.hpp:28
Set the error and if the Parser class was constructed.
Definition VP_Parse.hpp:16
std::string error
Definition VP_Parse.hpp:17