C API Documentation
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 "Variant.h"
12 #include <string>
13 #include <vector>
14 
15 #include "tr1proxy/rr_memory.h"
16 #include "tr1proxy/rr_unordered_map.h"
17 
18 #if defined(SWIG) || defined(SWIGPYTHON)
19 #include "PyUtils.h"
20 #endif
21 
22 
23 namespace rr {
24 
30 class RR_DECLSPEC Dictionary // Yes, I know this is a pure virtual *INTERFACE*
31 { // so it should NOT need to be exported, but MSVC
32 public: // *mistakenly* complains in ONE instance.
33  // add the declspec just to shut it up.
34 
35 #ifndef SWIG
36 
50  virtual void setItem(const std::string& key, const rr::Variant& value) = 0;
51 
67  virtual Variant getItem(const std::string& key) const = 0;
68 
72  virtual bool hasKey(const std::string& key) const = 0;
73 
77  virtual size_t deleteItem(const std::string& key) = 0;
78 
82  virtual std::vector<std::string> getKeys() const = 0;
83 
88  virtual ~Dictionary() {};
89 
90 #endif
91 
99 #if defined(SWIGPYTHON)
100  PyObject *keys() {
101  return dictionary_keys(this);
102  }
103 
104  PyObject *values() {
105  return dictionary_values(this);
106  }
107 
108  PyObject *items() {
109  return dictionary_items(this);
110  }
111 
112  PyObject *__getitem__(const char* key) {
113  return dictionary_getitem(this, key);
114  }
115 
116  PyObject *__setitem__(const char* key, PyObject* value) {
117  return dictionary_setitem(this, key, value);
118  }
119 
120  void __delitem__(const char* key) {
121  return dictionary_delitem(this, key);
122  }
123 
124  PyObject *__contains__(const char* key) {
125  return dictionary_contains(this, key);
126  }
127 
128  std::string helloPython() {
129  return "hello python";
130  }
131 #endif
132 };
133 
134 
140 class RR_DECLSPEC BasicDictionary : public Dictionary
141 {
142 public:
143  BasicDictionary() = default;;
144 
148  void setItem(const std::string& key, const rr::Variant& value) override;
149 
153  Variant getItem(const std::string& key) const override;
154 
160  bool hasKey(const std::string& key) const override;
161 
165  size_t deleteItem(const std::string& key) override;
166 
170  std::vector<std::string> getKeys() const override;
171 
176  ~BasicDictionary() override = default;
177 
178 protected:
179  typedef cxx11_ns::unordered_map<std::string, Variant> VariantMap;
180  VariantMap items;
181 };
182 
183 }
184 
185 
186 
187 
188 
189 #endif /* DICTIONARY_H_ */
This class is frozen, no new features Basic implementation of the Dictionary interface which uses a s...
Definition: Dictionary.h:141
std::vector< std::string > getKeys() const override
Variant getItem(const std::string &key) const override
bool hasKey(const std::string &key) const override
~BasicDictionary() override=default
void setItem(const std::string &key, const rr::Variant &value) override
size_t deleteItem(const std::string &key) override
This class is frozen, no new features A dictionary interface that objects can implement....
Definition: Dictionary.h:31
virtual Variant getItem(const std::string &key) const =0
virtual void setItem(const std::string &key, const rr::Variant &value)=0
virtual bool hasKey(const std::string &key) const =0
virtual size_t deleteItem(const std::string &key)=0
virtual ~Dictionary()
Definition: Dictionary.h:88
virtual std::vector< std::string > getKeys() const =0
Definition: Variant.h:75