Elements  6.0.1
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 <functional> // for reference_wrapper
31 #include <iostream> // for ostream
32 #include <map> // for map
33 #include <string> // for string
34 #include <vector> // for vector
35 
36 #include "ElementsKernel/Export.h" // for ELEMENTS_API
37 
38 namespace Elements {
39 
45 public:
46  class Variable;
47 
48 public:
50  explicit Environment(bool keep_same = true);
51  virtual ~Environment();
52 
53  Variable operator[](const std::string&);
54  const Variable operator[](const std::string& index) const;
55  Environment& restore();
56  Environment& set(const std::string&, const std::string&);
57  Environment& unSet(const std::string&);
58  Environment& append(const std::string&, const std::string&);
59  Environment& prepend(const std::string&, const std::string&);
60  std::string get(const std::string& index, const std::string& default_value = "") const;
61  static bool hasKey(const std::string&);
62  void commit();
63 
64  enum ShellType { sh, csh };
65 
66  std::string generateScript(ShellType) const;
67 
68 private:
73  static void checkOutOfRange(const std::string&);
74 
77 
79 
82 };
83 
89 
90 public:
91  Variable() = delete;
93  Variable(const Variable& other);
94  Variable(Variable&& other);
95  Variable& operator=(const Variable& other);
96  Variable& operator=(Variable&& other);
98  Variable& set(const std::string&);
99  Variable& unSet();
100  Variable& append(const std::string&);
102  Variable& prepend(const std::string&);
104  const std::string& index() const;
105  Environment& env() const;
106  std::string value() const;
108  operator std::string() const;
109  bool empty() const;
110  bool exists() const;
111 
112 private:
113  void checkCompatibility(const Variable&);
114 
117 
120 };
121 
123 
125 
126 } // namespace Elements
127 
128 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_ENVIRONMENT_H_
129 
Variable & append(const std::string &)
Definition: Environment.cpp:94
std::reference_wrapper< Environment > m_env
a copiable and movable reference
Definition: Environment.h:116
Variable & operator=(const Variable &other)
Definition: Environment.cpp:57
void checkCompatibility(const Variable &)
Variable & set(const std::string &)
Definition: Environment.cpp:80
const std::string & index() const
proxy class to overload the assignment
Definition: Environment.h:88
std::string m_index
The Name of the variable.
Definition: Environment.h:119
STL class.
Variable & operator+=(const std::string &)
defines the macros to be used for explicit export of the symbols
Environment & env() const
#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:81
std::string value() const
Python dictionary-like Environment interface.
Definition: Environment.h:44
std::map< std::string, std::string > m_old_values
old value for changed variables
Definition: Environment.h:76
ELEMENTS_API Environment::Variable operator+(const std::string &, const Environment::Variable &)
Variable & prepend(const std::string &)
ELEMENTS_API std::ostream & operator<<(std::ostream &, const Environment::Variable &)
STL class.
Variable operator+(const std::string &)