AuboStudio SDK 0.6.3

data_model.h
浏览该文件的文档.
1 #ifndef AUBO_SCOPE_DATA_MODEL_H
2 #define AUBO_SCOPE_DATA_MODEL_H
3
4 #include <stdint.h>
5 #include <string>
6 #include <vector>
7 #include <set>
8
9 #include <aubo_caps/domain/feature/feature.h>
10 #include <aubo_caps/domain/variable/variable.h>
11 #include <aubo_caps/domain/tcp/tcp.h>
12 #include <aubo_caps/domain/io/io.h>
13 #include <aubo_caps/domain/waypoint/waypoint.h>
14 #include <aubo_caps/domain/payload/payload.h>
15 #include <aubo_caps/domain/value/expression/expression.h>
16
17 namespace arcs {
18 namespace aubo_scope {
19 ARCS_CLASS_FORWARD(DataModel);
20
21 /**
22 * <p>
23 * This interface is used for storing and managing data that represents the
24 * current configuration of, e.g. a
25 * {@link ProgramNodeContribution} or {@link InstallationNodeContribution}.
26 * Methods for adding, removing, retrieving and changing values in a dictionary
27 * are provided.
28 * </p>
29 *
30 * <p>
31 * Setting a new value for a key already in use, will overwrite the current
32 * value with the new value. This happens regardless of the type of value (e.g.
33 * storing the value <code>true</code> under the key <i>myBool</i>
34 * and afterwards storing an <code>Angle</code> object under the same key will
35 * overwrite the value <code>true</code> with the provided <code>Angle</code>
36 * object).
37 * </p>
38 *
39 * <p>
40 * A auboCap installation screen has an underlying <code>DataModel</code>
41 * object. That object is saved and loaded along with each AuboScope
42 * installation.
43 * </p>
44 *
45 * <p>
46 * Similarly, each contributed program node instance has an underlying
47 * <code>DataModel</code> object. That object is saved and loaded along with the
48 * program where the node occurs. Undo/redo actions are supported for all
49 * modifications to the <code>DataModel</code> object in HTML-based program node
50 * contributions. Swing-based aubo_studio plugins must use the {@link
51 * UndoRedoManager} to record the changes on the undo/redo stack.
52 * </p>
53 *
54 * <p>
55 * When retrieving an object, both key and object type must match what was
56 * previously stored. This means that if a
57 * <code>TCP</code> object was stored using the key <i>myAngle</i>, then
58 * attempting to retrieve it using
59 * {@link #get(std::string key, Angle default_value)} with the key
60 * <i>myAngle</i> will not return the stored value, since the types do not
61 * match. Instead the provided <code>default_value</code> will be returned.
62 * </p>
63 *
64 */
65 class ARCS_ABI_EXPORT DataModel
66 {
67 public:
68 DataModel(DataModel &f);
69 DataModel(DataModel &&f);
70 ~DataModel();
71
72 /**
73 * Assign a <code>bool</code> value to the specified key.
74 *
75 * @param key key in the data model (not <code>null</code> and not an empty
76 * <code>std::string</code>).
77 * @param value value assigned to key.
78 *
79 * @throws IllegalArgumentException if the key is <code>null</code> or an
80 * empty <code>std::string</code>.
81 * @throws IllegalStateException if called from a Swing-based AuboCap
82 * program node outside of an {@link UndoableChanges} scope (see also {@link
83 * UndoRedoManager}).
84 */
85 void set(const std::string &key, bool value);
86
87 /**
88 * Get the <code>bool</code> value assigned to the specified key.
89 *
90 * @param key key in the data model.
91 * @param default_value value to be returned, if key does not exist.
92 * @return the value assigned to the key. If not exist, default_value is
93 * returned.
94 */
95 bool get(const std::string &key, bool default_value) const;
96
97 /**
98 * Assign an <code>int</code> value to the specified key.
99 *
100 * @param key key in the data model (not <code>null</code> and not an empty
101 * <code>std::string</code>).
102 * @param value value assigned to key.
103 *
104 * @throws IllegalArgumentException if the key is <code>null</code> or an
105 * empty <code>std::string</code>.
106 * @throws IllegalStateException if called from a Swing-based AuboCap
107 * program node outside of an {@link UndoableChanges} scope (see also {@link
108 * UndoRedoManager}).
109 */
110 void set(const std::string &key, int value);
111
112 /**
113 * Get the <code>int</code> value assigned to the specified key.
114 *
115 * @param key key in the data model.
116 * @param default_value value to be returned, if key does not exist.
117 * @return the value assigned to the key. If not exist, default_value is
118 * returned.
119 */
120 int get(const std::string &key, int default_value) const;
121
122 /**
123 * Assign a <code>long</code> value to the specified key.
124 *
125 * @param key key in the data model (not <code>null</code> and not an empty
126 * <code>std::string</code>).
127 * @param value value assigned to key.
128 *
129 * @throws IllegalArgumentException if the key is <code>null</code> or an
130 * empty <code>std::string</code>.
131 * @throws IllegalStateException if called from a Swing-based AuboCap
132 * program node outside of an {@link UndoableChanges} scope (see also {@link
133 * UndoRedoManager}).
134 */
135 void set(const std::string &key, long value);
136 void set(const std::string &key, uint64_t value);
137
138 /**
139 * Get the <code>long</code> value assigned to the specified key.
140 *
141 * @param key key in the data model.
142 * @param default_value value to be returned, if key does not exist.
143 * @return the value assigned to the key. If not exist, default_value is
144 * returned.
145 */
146 long get(const std::string &key, long default_value) const;
147 uint64_t get(const std::string &key, uint64_t default_value) const;
148
149 /**
150 * Assign a <code>float</code> value to the specified key.
151 *
152 * @param key key in the data model (not <code>null</code> and not an empty
153 * <code>std::string</code>).
154 * @param value value assigned to key.
155 *
156 * @throws IllegalArgumentException if the key is <code>null</code> or an
157 * empty <code>std::string</code>.
158 * @throws IllegalStateException if called from a Swing-based AuboCap
159 * program node outside of an {@link UndoableChanges} scope (see also {@link
160 * UndoRedoManager}).
161 */
162 void set(const std::string &key, float value);
163
164 /**
165 * Get the <code>float</code> value assigned to the specified key.
166 *
167 * @param key key in the data model.
168 * @param default_value value to be returned, if key does not exist.
169 * @return the value assigned to the key. If not exist, default_value is
170 * returned.
171 */
172 float get(const std::string &key, float default_value) const;
173
174 /**
175 * Assign a <code>double</code> value to the specified key.
176 *
177 * @param key key in the data model (not <code>null</code> and not an empty
178 * <code>std::string</code>).
179 * @param value value assigned to key.
180 *
181 * @throws IllegalArgumentException if the key is <code>null</code> or an
182 * empty <code>std::string</code>.
183 * @throws IllegalStateException if called from a Swing-based AuboCap
184 * program node outside of an {@link UndoableChanges} scope (see also {@link
185 * UndoRedoManager}).
186 */
187 void set(const std::string &key, double value);
188
189 /**
190 * Get the <code>double</code> value assigned to the specified key.
191 *
192 * @param key key in the data model.
193 * @param default_value value to be returned, if key does not exist.
194 * @return the value assigned to the key. If not exist, default_value is
195 * returned.
196 */
197 double get(const std::string &key, double default_value) const;
198
199 /**
200 * Assign a <code>std::string</code> value to the specified key.
201 *
202 * @param key key in the data model (not <code>null</code> and not an empty
203 * <code>std::string</code>).
204 * @param value value assigned to key.
205 *
206 * @throws IllegalArgumentException if the key is <code>null</code> or an
207 * empty <code>std::string</code>.
208 * @throws IllegalStateException if called from a Swing-based AuboCap
209 * program node outside of an {@link UndoableChanges} scope (see also {@link
210 * UndoRedoManager).
211 */
212 void set(const std::string &key, const std::string &value);
213
214 /**
215 * Get the <code>std::string</code> value assigned to the specified key.
216 *
217 * @param key key in the data model.
218 * @param default_value value to be returned, if key does not exist.
219 * @return the value assigned to the key. If not exist, default_value is
220 * returned.
221 */
222 std::string get(const std::string &key,
223 const std::string &default_value) const;
224 /**
225 * Assign a <code>Variable</code> value to the specified key.
226 *
227 * @param key key in the data model (not <code>null</code> and not an empty
228 * <code>std::string</code>).
229 * @param value value assigned to key.
230 *
231 * @throws IllegalArgumentException if the key is <code>null</code> or an
232 * empty <code>std::string</code>.
233 * @throws IllegalStateException if called from a Swing-based AuboCap
234 * program node outside of an {@link UndoableChanges} scope (see also {@link
235 * UndoRedoManager}).
236 */
237 void set(const std::string &key, VariablePtr value);
238 void set(const std::string &key, ExpressionPtr value);
239 void set(const std::string &key, PayloadPtr value);
240 void set(const std::string &key, IoPtr value);
241 void set(const std::string &key, WaypointPtr value);
242
243 /**
244 * Get the <code>Variable</code> value assigned to the specified key.
245 *
246 * @param key key in the data model.
247 * @param default_value value to be returned, if key does not exist.
248 * @return the value assigned to the key. If not exist, default_value is
249 * returned.
250 */
251 VariablePtr get(const std::string &key, VariablePtr default_value) const;
252 ExpressionPtr get(const std::string &key,
253 ExpressionPtr default_value) const;
254 PayloadPtr get(const std::string &key, PayloadPtr default_value) const;
255 IoPtr get(const std::string &key, IoPtr default_value) const;
256 WaypointPtr get(const std::string &key, WaypointPtr default_value) const;
257
258 /**
259 * Assign a <code>bool[]</code> as value to the specified key.
260 * @param key key in the data model (not <code>null} and not an empty
261 * <code>std::string</code>).
262 * @param value value assigned to key.
263 *
264 * @throws IllegalArgumentException if the key is <code>null</code> or an
265 * empty <code>std::string</code>.
266 * @throws IllegalStateException if called from a Swing-based AuboCap
267 * program node outside of an {@link UndoableChanges} scope (see also {@link
268 * UndoRedoManager).
269 */
270 void set(const std::string &key, const std::vector<bool> &value);
271
272 /**
273 * Get the <code>bool[]</code> as value assigned to the specified key.
274 *
275 * @param key key in the data model.
276 * @param default_value value to be returned, if key does not exist.
277 * @return the value assigned to the key. If not exist, default_value is
278 * returned.
279 */
280 std::vector<bool> get(const std::string &key,
281 const std::vector<bool> &default_value) const;
282
283 /**
284 * Assign a <code>int[]</code> as value to the specified key.
285 *
286 * @param key key in the data model (not <code>null</code> and not an empty
287 * <code>std::string</code>).
288 * @param value value assigned to key.
289 *
290 * @throws IllegalArgumentException if the key is <code>null</code> or an
291 * empty <code>std::string</code>.
292 * @throws IllegalStateException if called from a Swing-based AuboCap
293 * program node outside of an {@link UndoableChanges} scope (see also {@link
294 * UndoRedoManager}).
295 */
296 void set(const std::string &key, const std::vector<int> &value);
297
298 /**
299 * Get the <code>int[]</code> as value assigned to the specified key.
300 *
301 * @param key key in the data model.
302 * @param default_value value to be returned, if key does not exist.
303 * @return the value assigned to the key. If not exist, default_value is
304 * returned.
305 */
306 std::vector<int> get(const std::string &key,
307 const std::vector<int> &default_value) const;
308
309 /**
310 * Assign a <code>long[]</code> as value to the specified key.
311 *
312 * @param key key in the data model (not <code>null</code> and not an empty
313 * <code>std::string</code>).
314 * @param value value assigned to key.
315 *
316 * @throws IllegalArgumentException if the key is <code>null} or an empty
317 * <code>std::string</code>.
318 * @throws IllegalStateException if called from a Swing-based AuboCap
319 * program node outside of an {@link UndoableChanges} scope (see also {@link
320 * UndoRedoManager}).
321 */
322 void set(const std::string &key, const std::vector<long> &value);
323 void set(const std::string &key, const std::vector<uint64_t> &value);
324
325 /**
326 * Get the <code>long[]</code> as value assigned to the specified key.
327 *
328 * @param key key in the data model.
329 * @param default_value value to be returned, if key does not exist.
330 * @return the value assigned to the key. If not exist, default_value is
331 * returned.
332 */
333 std::vector<long> get(const std::string &key,
334 const std::vector<long> &default_value) const;
335 std::vector<uint64_t> get(const std::string &key,
336 const std::vector<uint64_t> &default_value) const;
337
338 /**
339 * Assign a <code>float[]</code> as value to the specified key.
340 *
341 * @param key key in the data model (not <code>null</code> and not an empty
342 * <code>std::string</code>).
343 * @param value value assigned to key.
344 *
345 * @throws IllegalArgumentException if the key is <code>null</code> or an
346 * empty <code>std::string</code>.
347 * @throws IllegalStateException if called from a Swing-based AuboCap
348 * program node outside of an {@link UndoableChanges} scope (see also {@link
349 * UndoRedoManager}).
350 */
351 void set(const std::string &key, const std::vector<float> &value);
352
353 /**
354 * Get the <code>float[]</code> as value assigned to the specified key.
355 *
356 * @param key key in the data model.
357 * @param default_value value to be returned, if key does not exist.
358 * @return the value assigned to the key. If not exist, default_value is
359 * returned.
360 */
361 std::vector<float> get(const std::string &key,
362 const std::vector<float> &default_value) const;
363
364 /**
365 * Assign a <code>double[]</code> as value to the specified key.
366 *
367 * @param key key in the data model (not <code>null</code> and not an empty
368 * <code>std::string</code>).
369 * @param value value assigned to key.
370 *
371 * @throws IllegalArgumentException if the key is <code>null</code> or an
372 * empty <code>std::string</code>.
373 * @throws IllegalStateException if called from a Swing-based AuboCap
374 * program node outside of an {@link UndoableChanges} scope (see also {@link
375 * UndoRedoManager}).
376 */
377 void set(const std::string &key, const std::vector<double> &value);
378
379 /**
380 * Get the <code>double[]</code> as value assigned to the specified key.
381 *
382 * @param key key in the data model.
383 * @param default_value value to be returned, if key does not exist.
384 * @return the value assigned to the key. If not exist, default_value is
385 * returned.
386 */
387 std::vector<double> get(const std::string &key,
388 const std::vector<double> &default_value) const;
389
390 /**
391 * Assign a <code>std::string[]</code> as value to the specified key.
392 *
393 * @param key key in the data model (not <code>null</code> and not an empty
394 * <code>std::string</code>).
395 * @param value value assigned to key.
396 *
397 * @throws IllegalArgumentException if the key is <code>null</code> or an
398 * empty <code>std::string</code>.
399 * @throws IllegalStateException if called from a Swing-based AuboCap
400 * program node outside of an {@link UndoableChanges} scope (see also {@link
401 * UndoRedoManager}).
402 */
403 void set(const std::string &key, const std::vector<std::string> &value);
404
405 /**
406 * Get the <code>std::string[]</code> as value assigned to the specified
407 * key.
408 *
409 * @param key key in the data model.
410 * @param default_value value to be returned, if key does not exist.
411 * @return the value assigned to the key. If not exist, default_value is
412 * returned.
413 */
414 std::vector<std::string> get(
415 const std::string &key,
416 const std::vector<std::string> &default_value) const;
417
418 /**
419 * Assign a <code>TCP</code> value to the specified key.
420 *
421 * @param key key in the data model (not <code>null</code> and not an empty
422 * <code>std::string</code>).
423 * @param value value assigned to key.
424 *
425 * @throws IllegalArgumentException if the key is <code>null</code> or an
426 * empty <code>std::string</code>.
427 * @throws IllegalStateException if called from a Swing-based AuboCap
428 * program node outside of an {@link UndoableChanges} scope (see also {@link
429 * UndoRedoManager}).
430 */
431 void set(const std::string &key, TCPPtr value);
432
433 /**
434 * Get the <code>TCP value assigned to the specified key.
435 *
436 * @param key key in the data model.
437 * @param default_value value to be returned, if key does not exist.
438 * @return the value assigned to the key. If not exist, default_value is
439 * returned.
440 */
441 TCPPtr get(const std::string &key, TCPPtr default_value) const;
442
443 /**
444 * Assign a <code>Feature</code> value to the specified key.
445 *
446 * @param key key in the data model (not <code>null</code> and not an empty
447 * <code>std::string</code>).
448 * @param value value assigned to key.
449 *
450 * @throws IllegalArgumentException if the key is <code>null</code> or an
451 * empty <code>std::string</code>.
452 * @throws IllegalStateException if called from a Swing-based AuboCap
453 * program node outside of an {@link UndoableChanges} scope (see also {@link
454 * UndoRedoManager}).
455 */
456 void set(const std::string &key, FeaturePtr value);
457
458 /**
459 * Get the <code>Feature</code> value assigned to the specified key.
460 *
461 * @param key key in the data model.
462 * @param default_value value to be returned, if key does not exist.
463 * @return the value assigned to the key. If not exist, default_value is
464 * returned.
465 */
466 FeaturePtr get(const std::string &key, FeaturePtr default_value) const;
467
468 /**
469 * Get a set of all the keys in the data model.
470 *
471 * @return A Set of keys.
472 */
473 std::set<std::string> getKeys() const;
474
475 /**
476 * Check if a key is present in the data model.
477 *
478 * @param key key in the data model (not <code>null</code> and not an empty
479 * <code>std::string</code>).
480 * @return <code>true</code>, if key exist, otherwise <code>false</code>.
481 */
482 bool isSet(const std::string &key) const;
483
484 /**
485 * Remove a key-value pair from the data model.
486 *
487 * @param key key in the data model (not <code>null</code> and not an empty
488 * <code>std::string</code>).
489 * @return <code>true</code>, if succeed, otherwise <code>false</code>.
490 * @throws IllegalStateException if called from a Swing-based AuboCap
491 * program node outside of an {@link UndoableChanges} scope (see also {@link
492 * UndoRedoManager}).
493 */
494 bool remove(const std::string &key);
495
496 private:
497 friend class DataSwitch;
498 DataModel();
499 void *d_{ nullptr };
500 };
501
502 } // namespace aubo_scope
503 } // namespace arcs
504
505 #endif
ARCS_ABI_EXPORT
#define ARCS_ABI_EXPORT
Definition: class_forward.h:16
arcs::aubo_scope::DataModel
Definition: data_model.h:66
arcs::aubo_scope::DataModel::DataModel
DataModel(DataModel &f)
arcs::aubo_scope::DataModel::isSet
bool isSet(const std::string &key) const
Check if a key is present in the data model.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, FeaturePtr value)
Assign a Feature value to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::string &value)
Assign a std::string value to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, WaypointPtr value)
arcs::aubo_scope::DataModel::set
void set(const std::string &key, ExpressionPtr value)
arcs::aubo_scope::DataModel::get
WaypointPtr get(const std::string &key, WaypointPtr default_value) const
arcs::aubo_scope::DataModel::get
std::vector< std::string > get(const std::string &key, const std::vector< std::string > &default_value) const
Get the std::string[] as value assigned to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, IoPtr value)
arcs::aubo_scope::DataModel::get
TCPPtr get(const std::string &key, TCPPtr default_value) const
Get the TCP value assigned to the specified key.
arcs::aubo_scope::DataModel::DataModel
DataModel(DataModel &&f)
arcs::aubo_scope::DataModel::~DataModel
~DataModel()
arcs::aubo_scope::DataModel::get
std::vector< bool > get(const std::string &key, const std::vector< bool > &default_value) const
Get the bool[] as value assigned to the specified key.
arcs::aubo_scope::DataModel::get
int get(const std::string &key, int default_value) const
Get the int value assigned to the specified key.
arcs::aubo_scope::DataModel::getKeys
std::set< std::string > getKeys() const
Get a set of all the keys in the data model.
arcs::aubo_scope::DataModel::get
ExpressionPtr get(const std::string &key, ExpressionPtr default_value) const
arcs::aubo_scope::DataModel::remove
bool remove(const std::string &key)
Remove a key-value pair from the data model.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::vector< double > &value)
Assign a double[] as value to the specified key.
arcs::aubo_scope::DataModel::get
IoPtr get(const std::string &key, IoPtr default_value) const
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::vector< long > &value)
Assign a long[] as value to the specified key.
arcs::aubo_scope::DataModel::get
std::string get(const std::string &key, const std::string &default_value) const
Get the std::string value assigned to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, uint64_t value)
arcs::aubo_scope::DataModel::get
float get(const std::string &key, float default_value) const
Get the float value assigned to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, bool value)
Assign a bool value to the specified key.
arcs::aubo_scope::DataModel::get
long get(const std::string &key, long default_value) const
Get the long value assigned to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, double value)
Assign a double value to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::vector< std::string > &value)
Assign a std::string[] as value to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, VariablePtr value)
Assign a Variable value to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::vector< uint64_t > &value)
arcs::aubo_scope::DataModel::get
std::vector< float > get(const std::string &key, const std::vector< float > &default_value) const
Get the float[] as value assigned to the specified key.
arcs::aubo_scope::DataModel::get
std::vector< double > get(const std::string &key, const std::vector< double > &default_value) const
Get the double[] as value assigned to the specified key.
arcs::aubo_scope::DataModel::get
std::vector< int > get(const std::string &key, const std::vector< int > &default_value) const
Get the int[] as value assigned to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::vector< float > &value)
Assign a float[] as value to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::vector< bool > &value)
Assign a bool[] as value to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, float value)
Assign a float value to the specified key.
arcs::aubo_scope::DataModel::get
VariablePtr get(const std::string &key, VariablePtr default_value) const
Get the Variable value assigned to the specified key.
arcs::aubo_scope::DataModel::get
uint64_t get(const std::string &key, uint64_t default_value) const
arcs::aubo_scope::DataModel::get
PayloadPtr get(const std::string &key, PayloadPtr default_value) const
arcs::aubo_scope::DataModel::get
double get(const std::string &key, double default_value) const
Get the double value assigned to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, TCPPtr value)
Assign a TCP value to the specified key.
arcs::aubo_scope::DataModel::get
bool get(const std::string &key, bool default_value) const
Get the bool value assigned to the specified key.
arcs::aubo_scope::DataModel::get
std::vector< uint64_t > get(const std::string &key, const std::vector< uint64_t > &default_value) const
arcs::aubo_scope::DataModel::set
void set(const std::string &key, PayloadPtr value)
arcs::aubo_scope::DataModel::set
void set(const std::string &key, int value)
Assign an int value to the specified key.
arcs::aubo_scope::DataModel::DataModel
DataModel()
arcs::aubo_scope::DataModel::set
void set(const std::string &key, const std::vector< int > &value)
Assign a int[] as value to the specified key.
arcs::aubo_scope::DataModel::get
FeaturePtr get(const std::string &key, FeaturePtr default_value) const
Get the Feature value assigned to the specified key.
arcs::aubo_scope::DataModel::set
void set(const std::string &key, long value)
Assign a long value to the specified key.
arcs::aubo_scope::DataModel::get
std::vector< long > get(const std::string &key, const std::vector< long > &default_value) const
Get the long[] as value assigned to the specified key.
expression.h
feature.h
io.h
arcs::aubo_scope::ARCS_CLASS_FORWARD
ARCS_CLASS_FORWARD(GripForceCapability)
arcs
Definition: contribution_provider.h:7
payload.h
tcp.h
variable.h
waypoint.h