Rumba C++ SDK
Dict.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2018
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "Value.h"
18 #include "Impl.h"
19 #include "Array.h"
20 
21  namespace maquina
22  {
24  class MAQUINA_EXPORT Dict : public Value
25  {
26  public:
27  Dict();
28 
30 
31  Dict(const Value &v);
32 
34  bool has_key(const char *key) const;
35 
37  const Value read(const char *key) const;
38 
40 
41  bool as_bool( const char *key ) const;
42 
48  bool as_bool( const char *key, bool default_value ) const;
49 
51 
52  int as_int( const char *key ) const;
53 
59  int as_int( const char *key, int default_value ) const;
60 
62 
63  float as_float( const char *key ) const;
64 
70  float as_float(const char* key, float default_value) const;
71 
73 
74  double as_double( const char *key ) const;
75 
81  double as_double( const char *key, double default_value ) const;
82 
84 
85  const std::string& as_string( const char *key ) const;
86 
92  const std::string& as_string(const char* key, const std::string& default_value) const;
93 
95 
96  std::wstring as_wstring( const char *key ) const;
97 
103  std::wstring as_wstring(const char* key, const std::wstring& default_value) const;
104 
106 
107  Imath::V2f as_V2f( const char *key ) const;
108 
114  Imath::V2f as_V2f(const char* key, const Imath::V2f& default_value) const;
115 
117 
118  Imath::V3f as_V3f( const char *key ) const;
119 
125  Imath::V3f as_V3f( const char *key, const Imath::V3f& default_value ) const;
126 
128 
129  Imath::V4f as_V4f( const char *key ) const;
130 
136  Imath::V4f as_V4f(const char* key, const Imath::V4f& default_value) const;
137 
139 
140  const Imath::V2d& as_V2d( const char *key ) const;
141 
147  const Imath::V2d& as_V2d(const char* key, const Imath::V2d& default_value) const;
148 
150 
151  const Imath::V3d& as_V3d( const char *key ) const;
152 
158  const Imath::V3d& as_V3d( const char *key, const Imath::V3d& default_value ) const;
159 
161 
162  const Imath::V4d& as_V4d( const char *key ) const;
163 
169  const Imath::V4d& as_V4d(const char* key, const Imath::V4d& default_value) const;
170 
172 
173  Imath::M44f as_M44f( const char *key ) const;
174 
180  Imath::M44f as_M44f(const char* key, const Imath::M44f& default_value) const;
181 
183 
184  const Imath::M44d& as_M44d( const char *key ) const;
185 
191  const Imath::M44d& as_M44d(const char* key, const Imath::M44d& default_value) const;
192 
194 
195  const Imath::Box3f& as_Box3f( const char *key ) const;
196 
202  const Imath::Box3f& as_Box3f(const char* key, const Imath::Box3f& default_value) const;
203 
205 
206  Imath::Quatf as_Quatf( const char *key ) const;
207 
213  Imath::Quatf as_Quatf(const char* key, const Imath::Quatf& default_value) const;
214 
216 
217  const Imath::Quatd& as_Quatd( const char *key ) const;
218 
224  const Imath::Quatd& as_Quatd(const char* key, const Imath::Quatd& default_value) const;
225 
227 
228  const maquina::Dict as_Dict(const char* key ) const;
229 
235  const maquina::Dict as_Dict(const char* key, const maquina::Dict& default_value) const;
236 
238 
239  const maquina::Array as_Array(const char* key ) const;
240 
246  const maquina::Array as_Array(const char* key, const maquina::Array& default_value) const;
247 
249 
251  {
252  public:
255  {
256  public:
257  using iterator_category = std::forward_iterator_tag;
258  using value_type = std::pair<std::string, Value>;
259  using difference_type = std::ptrdiff_t;
260  using pointer = std::pair<std::string, Value>;
261  using reference = std::pair<std::string, Value>;
262 
263  reference operator*() const;
264  bool operator==(const Iterator &other) const;
265  bool operator!=(const Iterator &other) const;
266  Iterator& operator++();
267  Iterator( void *iterator );
268  Iterator( const Iterator &other );
269  ~Iterator();
270  private:
271  void *_internal;
272  };
273 
274  Values( const std::shared_ptr< Impl >& node )
275  : _node{ node }
276  {}
277  Iterator begin();
278  Iterator end();
279  private:
280  std::shared_ptr< Impl > _node;
281  };
282 
283  Values values() const;
284 
285  bool empty() const noexcept;
286  size_t size() const noexcept;
287 
289 
290  bool insert(const StringView& key, const Value &value);
291 
293 
294  bool erase(const StringView& key);
295 
297  static const Dict default_value;
298 
300  Dict(std::shared_ptr<Impl> impl) { _impl=impl; }
301  };
302  }
Definition: ImathBox.h:71
Definition: ImathFrame.h:42
Definition: ImathFrame.h:43
Definition: Plug.h:527
std::ptrdiff_t difference_type
Definition: Dict.h:259
Definition: ImathVec.h:63
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
StringViewBase< char, std::string > StringView
Definition: StringView.h:376
MAQUINA_EXPORT Value default_value(const maquina::StringView &type_name)
Return the default value of a type.
A value accessor.
Definition: Dict.h:250
std::pair< std::string, Value > value_type
Definition: Dict.h:258
An array of values.
Definition: Array.h:26
std::pair< std::string, Value > reference
Definition: Dict.h:261
Definition: ImathQuat.h:71
#define MAQUINA_EXPORT
Definition: Export.h:31
bool operator!=(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:306
Definition: ImathVec.h:61
A Plug iterator.
Definition: Dict.h:254
bool operator==(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:274
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
A dictionnary to associate strings to values.
Definition: Dict.h:24
std::pair< std::string, Value > pointer
Definition: Dict.h:260
Values(const std::shared_ptr< Impl > &node)
Definition: Dict.h:274
std::forward_iterator_tag iterator_category
Definition: Dict.h:257
Base class of all Rumba values.
Definition: Value.h:34