roadrunner  2.6.0
Fast simulator for SBML models
Dictionary.h
1 /*
2  * Dictionary.h
3  *
4  * Created on: Jul 14, 2014
5  * Author: andy
6  */
7 
8 #ifndef DICTIONARY_H_
9 #define DICTIONARY_H_
10 
11 #include "Setting.h"
12 #include <string>
13 #include <vector>
14 #include <unordered_map>
15 #include "rrExporter.h"
16 
17 #if defined(SWIG) || defined(SWIGPYTHON)
18 #include "PyUtils.h"
19 #endif
20 
21 
22 namespace rr {
23 
29 class RR_DECLSPEC Dictionary // Yes, I know this is a pure virtual *INTERFACE*
30 { // so it should NOT need to be exported, but MSVC
31 public: // *mistakenly* complains in ONE instance.
32  // add the declspec just to shut it up.
33 
34 #ifndef SWIG
35 
49  virtual void setItem(const std::string& key, const rr::Setting& value) = 0;
50 
66  virtual Setting getItem(const std::string& key) const = 0;
67 
71  virtual bool hasKey(const std::string& key) const = 0;
72 
76  virtual size_t deleteItem(const std::string& key) = 0;
77 
81  virtual std::vector<std::string> getKeys() const = 0;
82 
87  virtual ~Dictionary() {};
88 
89 #endif
90 
98 #if defined(SWIGPYTHON)
99  PyObject *keys() {
100  return dictionary_keys(this);
101  }
102 
103  PyObject *values() {
104  return dictionary_values(this);
105  }
106 
107  PyObject *items() {
108  return dictionary_items(this);
109  }
110 
111  PyObject *__getitem__(const char* key) {
112  return dictionary_getitem(this, key);
113  }
114 
115  PyObject *__setitem__(const char* key, PyObject* value) {
116  return dictionary_setitem(this, key, value);
117  }
118 
119  void __delitem__(const char* key) {
120  return dictionary_delitem(this, key);
121  }
122 
123  PyObject *__contains__(const char* key) {
124  return dictionary_contains(this, key);
125  }
126 
127  std::string helloPython() {
128  return "hello python";
129  }
130 #endif
131 };
132 
133 
139 class RR_DECLSPEC BasicDictionary : public Dictionary
140 {
141 public:
142  using item = std::pair<std::string, Setting>;
143  BasicDictionary() = default;
144 
145  BasicDictionary(std::initializer_list<item> initializerList);
146 
150  void setItem(const std::string& key, const rr::Setting& value) override;
151 
155  Setting getItem(const std::string& key) const override;
156 
162  bool hasKey(const std::string& key) const override;
163 
167  size_t deleteItem(const std::string& key) override;
168 
172  std::vector<std::string> getKeys() const override;
173 
178  ~BasicDictionary() override = default;
179 
180 protected:
181  typedef std::unordered_map<std::string, Setting> VariantMap;
182  VariantMap items;
183 };
184 
185 }
186 
187 
188 
189 
190 
191 #endif /* DICTIONARY_H_ */
This class is frozen, no new features Basic implementation of the Dictionary interface which uses a s...
Definition: Dictionary.h:140
~BasicDictionary() override=default
Pure virtual interface, you should never have to delete an instance of this type directly.
This class is frozen, no new features A dictionary interface that objects can implement.
Definition: Dictionary.h:30
virtual Setting getItem(const std::string &key) const =0
Get a value.
virtual void setItem(const std::string &key, const rr::Setting &value)=0
Set the value for an arbitrary key.
virtual bool hasKey(const std::string &key) const =0
is there a key matching this name.
virtual size_t deleteItem(const std::string &key)=0
remove a value
virtual ~Dictionary()
Pure virtual interface, you should never have to delete an instance of this type directly.
Definition: Dictionary.h:87
virtual std::vector< std::string > getKeys() const =0
list of keys in this object.
Store a roadrunner option (or setting) as a Variant type.
Definition: Setting.h:78