| 41 | }; |
| 42 | |
| 43 | class Dynamic_Object |
| 44 | { |
| 45 | public: |
| 46 | explicit Dynamic_Object(std::string t_type_name) |
| 47 | : m_type_name(std::move(t_type_name)), m_option_explicit(false) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | Dynamic_Object() = default; |
| 52 | |
| 53 | bool is_explicit() const |
| 54 | { |
| 55 | return m_option_explicit; |
| 56 | } |
| 57 | |
| 58 | void set_explicit(const bool t_explicit) |
| 59 | { |
| 60 | m_option_explicit = t_explicit; |
| 61 | } |
| 62 | |
| 63 | std::string get_type_name() const |
| 64 | { |
| 65 | return m_type_name; |
| 66 | } |
| 67 | |
| 68 | const Boxed_Value &operator[](const std::string &t_attr_name) const |
| 69 | { |
| 70 | return get_attr(t_attr_name); |
| 71 | } |
| 72 | |
| 73 | Boxed_Value &operator[](const std::string &t_attr_name) |
| 74 | { |
| 75 | return get_attr(t_attr_name); |
| 76 | } |
| 77 | |
| 78 | const Boxed_Value &get_attr(const std::string &t_attr_name) const |
| 79 | { |
| 80 | auto a = m_attrs.find(t_attr_name); |
| 81 | |
| 82 | if (a != m_attrs.end()) { |
| 83 | return a->second; |
| 84 | } else { |
| 85 | throw std::range_error("Attr not found '" + t_attr_name + "' and cannot be added to const obj"); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | bool has_attr(const std::string &t_attr_name) const { |
| 90 | return m_attrs.find(t_attr_name) != m_attrs.end(); |
| 91 | } |
| 92 | |
| 93 | Boxed_Value &get_attr(const std::string &t_attr_name) |
| 94 | { |
| 95 | return m_attrs[t_attr_name]; |
| 96 | } |
| 97 | |
| 98 | Boxed_Value &method_missing(const std::string &t_method_name) |
| 99 | { |
| 100 | if (m_option_explicit && m_attrs.find(t_method_name) == m_attrs.end()) { |
no test coverage detected