Elements  6.2
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 <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 
Elements::Environment::Variable::m_env
std::reference_wrapper< Environment > m_env
a copiable and movable reference
Definition: Environment.h:116
Elements::Environment::Variable::empty
bool empty() const
Definition: Environment.cpp:139
Elements::Environment::Variable::set
Variable & set(const std::string &)
Definition: Environment.cpp:80
Export.h
defines the macros to be used for explicit export of the symbols
std::string
STL class.
Elements::Environment::Variable::append
Variable & append(const std::string &)
Definition: Environment.cpp:94
Elements::Environment::Variable::index
const std::string & index() const
Definition: Environment.cpp:122
std::vector< std::string >
Elements::Environment::Variable::operator+=
Variable & operator+=(const std::string &)
Definition: Environment.cpp:101
Elements::Environment::Variable
proxy class to overload the assignment
Definition: Environment.h:88
Elements::operator+
ELEMENTS_API Environment::Variable operator+(const std::string &, const Environment::Variable &)
Definition: Environment.cpp:302
Elements::operator<<
ELEMENTS_API std::ostream & operator<<(std::ostream &, const Environment::Variable &)
Definition: Environment.cpp:295
Elements::Environment::Variable::exists
bool exists() const
Definition: Environment.cpp:143
std::reference_wrapper
Elements::Environment::m_added_variables
std::vector< std::string > m_added_variables
variable added to the environment
Definition: Environment.h:81
ELEMENTS_API
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Definition: Export.h:74
Elements::Environment::Variable::m_index
std::string m_index
The Name of the variable.
Definition: Environment.h:119
std::ostream
STL class.
Elements::Environment::m_old_values
std::map< std::string, std::string > m_old_values
old value for changed variables
Definition: Environment.h:76
std::map< std::string, std::string >
Elements::Environment::Variable::value
std::string value() const
Definition: Environment.cpp:130
Elements::Environment::m_keep_same
bool m_keep_same
Definition: Environment.h:78
Elements::Environment::Variable::Variable
Variable()=delete
Elements::Environment::Variable::prepend
Variable & prepend(const std::string &)
Definition: Environment.cpp:106
Elements::Environment::ShellType
ShellType
Definition: Environment.h:64
Elements::Environment
Python dictionary-like Environment interface.
Definition: Environment.h:44
Elements::Environment::Variable::operator+
Variable operator+(const std::string &)
Definition: Environment.cpp:113
Elements::Environment::Variable::unSet
Variable & unSet()
Definition: Environment.cpp:87
Elements::Environment::Variable::env
Environment & env() const
Definition: Environment.cpp:126
Elements::Environment::Variable::operator=
Variable & operator=(const Variable &other)
Definition: Environment.cpp:57
Elements
Definition: callBackExample.h:35
Elements::Environment::Variable::checkCompatibility
void checkCompatibility(const Variable &)
Definition: Environment.cpp:147