| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef GUARD_TLATE_DATA_MODEL_HH |
|---|
| 21 | #define GUARD_TLATE_DATA_MODEL_HH |
|---|
| 22 | |
|---|
| 23 | #include "empty_value.hh" |
|---|
| 24 | #include "string_value.hh" |
|---|
| 25 | #include "structured_value.hh" |
|---|
| 26 | |
|---|
| 27 | #include "../myassert.hh" |
|---|
| 28 | |
|---|
| 29 | #include <map> |
|---|
| 30 | |
|---|
| 31 | namespace tlate |
|---|
| 32 | { |
|---|
| 33 | class data_model : public structured_value |
|---|
| 34 | { |
|---|
| 35 | std::map<std::string,value::const_ptr> m; |
|---|
| 36 | public: |
|---|
| 37 | typedef boost::shared_ptr<data_model> ptr; |
|---|
| 38 | typedef boost::shared_ptr<const data_model> const_ptr; |
|---|
| 39 | |
|---|
| 40 | void insert(std::string var) { |
|---|
| 41 | insert(var, new empty_value); |
|---|
| 42 | } |
|---|
| 43 | void insert(std::string var, std::string val) { |
|---|
| 44 | insert(var, new string_value(val)); |
|---|
| 45 | } |
|---|
| 46 | void insert(std::string var, int val, unsigned md = 1) { |
|---|
| 47 | insert(var, new string_value(val, md)); |
|---|
| 48 | } |
|---|
| 49 | void insert(std::string var, value::const_ptr val) { |
|---|
| 50 | myassert(var.find('.') == std::string::npos); |
|---|
| 51 | m[var] = val; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void insert(std::string var, value *val) { |
|---|
| 55 | value::ptr vp(val); |
|---|
| 56 | insert(var, vp); |
|---|
| 57 | } |
|---|
| 58 | value::const_ptr get(std::string var) const { |
|---|
| 59 | std::map<std::string,value::const_ptr>::const_iterator |
|---|
| 60 | it = m.find(var); |
|---|
| 61 | if (it != m.end()) |
|---|
| 62 | return it->second; |
|---|
| 63 | else |
|---|
| 64 | return value::ptr(); |
|---|
| 65 | } |
|---|
| 66 | }; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | #endif |
|---|