Elements  5.12.0
A C++ base framework for the Euclid Software.
Environment.h
Go to the documentation of this file.
1 
27 #ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_ENVIRONMENT_H_
28 #define ELEMENTSKERNEL_ELEMENTSKERNEL_ENVIRONMENT_H_
29 
30 #include <iostream> // for ostream
31 #include <map> // for map
32 #include <string> // for string
33 #include <vector> // for vector
34 #include <functional> // for reference_wrapper
35 
36 #include "ElementsKernel/Export.h" // for ELEMENTS_API
37 
38 namespace Elements {
39 
40 /*
41  * @brief Python dictionary-like Environment interface
42  * @ingroup ElementsKernel
43  */
45 public:
46 
47  class Variable;
48 
49 public:
50 
51  explicit Environment(bool keep_same = true);
52  virtual ~Environment();
53 
54  Variable operator[](const std::string&);
55  const Variable operator[](const std::string& index) const;
56  Environment& restore();
57  Environment& set(const std::string&, const std::string&);
58  Environment& unSet(const std::string&);
59  Environment& append(const std::string&, const std::string&);
60  Environment& prepend(const std::string&, const std::string&);
61  std::string get(const std::string& index, const std::string& default_value = "") const;
62  static bool hasKey(const std::string&);
63  void commit();
64 
65  enum ShellType {sh, csh};
66 
67  std::string generateScript(ShellType) const;
68 
69 private:
70 
75  static void checkOutOfRange(const std::string&);
76 
79 
81 
84 
85 };
86 
92 
93 public:
94  Variable() = delete;
96  Variable(const Variable& other);
97  Variable(Variable&& other);
98  Variable& operator=(const Variable& other);
99  Variable& operator=(Variable&& other);
100  Variable& operator=(const std::string&);
101  Variable& set(const std::string&);
102  Variable& unSet();
103  Variable& append(const std::string&);
105  Variable& prepend(const std::string&);
107  const std::string& index() const;
108  Environment& env() const;
109  std::string value() const;
111  operator std::string() const;
112  bool empty() const;
113  bool exists() const;
114 
115 private:
116 
117  void checkCompatibility(const Variable&);
118 
121 
124 };
125 
127 
129 
130 } // namespace Elements
131 
132 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_ENVIRONMENT_H_
133 
defines the macros to be used for explicit export of the symbols
proxy class to overload the assignment
Definition: Environment.h:91
Variable & operator=(const Variable &other)
Definition: Environment.cpp:62
Variable & set(const std::string &)
Definition: Environment.cpp:88
Variable & operator+=(const std::string &)
std::reference_wrapper< Environment > m_env
a copiable and movable reference
Definition: Environment.h:120
Variable & prepend(const std::string &)
std::string m_index
The Name of the variable.
Definition: Environment.h:123
Variable & append(const std::string &)
void checkCompatibility(const Variable &)
Variable operator+(const std::string &)
const std::string & index() const
Environment & env() const
std::vector< std::string > m_added_variables
variable added to the environment
Definition: Environment.h:83
std::map< std::string, std::string > m_old_values
old value for changed variables
Definition: Environment.h:78
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Definition: Export.h:74
ELEMENTS_API Environment::Variable operator+(const std::string &, const Environment::Variable &)
ELEMENTS_API std::ostream & operator<<(std::ostream &, const Environment::Variable &)