Elements  5.8
A C++ base framework for the Euclid Software.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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  */
44 public:
48  class Variable {
49 
50  public:
51  Variable() = delete;
52  Variable(Environment& env, const std::string& index);
53  Variable(const Variable& other);
54  Variable(Variable&& other);
55  Variable& operator=(const Variable& other);
56  Variable& operator=(Variable&& other);
57  Variable& operator=(const std::string&);
58  Variable& set(const std::string&);
59  Variable& unSet();
60  Variable& append(const std::string&);
61  Variable& operator+=(const std::string&);
62  Variable& prepend(const std::string&);
64  const std::string& index() const;
65  Environment& env() const;
66  std::string value() const;
68  operator std::string() const;
69  bool empty() const;
70  bool exists() const;
71 
72  private:
73 
74  void checkCompatibility(const Variable&);
75 
78 
81  };
82 
83  explicit Environment(bool keep_same = true);
84  virtual ~Environment();
85 
86  Variable operator[](const std::string&);
87  const Variable operator[](const std::string& index) const;
88  Environment& restore();
89  Environment& set(const std::string&, const std::string&);
90  Environment& unSet(const std::string&);
91  Environment& append(const std::string&, const std::string&);
92  Environment& prepend(const std::string&, const std::string&);
93  std::string get(const std::string& index, const std::string& default_value = "") const;
94  static bool hasKey(const std::string&);
95  void commit();
96 
97  enum ShellType {sh, csh};
98 
99  std::string generateScript(ShellType) const;
100 
101 private:
102 
106  static void checkOutOfRange(const std::string&);
107 
110 
112 
115 
116 };
117 
119 
121 
122 } // namespace Elements
123 
124 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_ENVIRONMENT_H_
125 
std::reference_wrapper< Environment > m_env
a copiable and movable reference
Definition: Environment.h:77
proxy class to overload the assignment
Definition: Environment.h:48
std::string m_index
The Name of the variable.
Definition: Environment.h:80
STL class.
defines the macros to be used for explicit export of the symbols
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Definition: Export.h:74
std::vector< std::string > m_added_variables
variable added to the environment
Definition: Environment.h:114
std::map< std::string, std::string > m_old_values
old value for changed variables
Definition: Environment.h:109
ELEMENTS_API Environment::Variable operator+(const std::string &, const Environment::Variable &)
ELEMENTS_API std::ostream & operator<<(std::ostream &, const Environment::Variable &)
STL class.