| 919 | }; |
| 920 | |
| 921 | class structure final { |
| 922 | bool m_shadow = false; |
| 923 | std::string m_name; |
| 924 | domain_t m_data; |
| 925 | type_id m_id; |
| 926 | |
| 927 | public: |
| 928 | structure() = delete; |
| 929 | |
| 930 | structure(const type_id &id, std::string name, const domain_type &data) : m_id(id), |
| 931 | m_name(std::move(name)), |
| 932 | m_data(std::make_shared<domain_type>(data)) |
| 933 | { |
| 934 | if (m_data->exist("initialize")) |
| 935 | invoke(m_data->get_var("initialize"), var::make<structure>(this)); |
| 936 | } |
| 937 | |
| 938 | structure(structure &&s) noexcept : m_shadow(s.m_shadow), m_data(nullptr), m_id(typeid(void)) |
| 939 | { |
| 940 | s.m_shadow = true; |
| 941 | std::swap(m_name, s.m_name); |
| 942 | std::swap(m_data, s.m_data); |
| 943 | std::swap(m_id, s.m_id); |
| 944 | } |
| 945 | |
| 946 | structure(const structure &s) : m_id(s.m_id), m_name(s.m_name), m_data(std::make_shared<domain_type>()) |
| 947 | { |
| 948 | if (s.m_data->exist("parent")) { |
| 949 | var &_p = s.m_data->get_var("parent"); |
| 950 | auto &_parent = _p.val<structure>(); |
| 951 | var p = copy(_p); |
| 952 | auto &parent = p.val<structure>(); |
| 953 | m_data->add_var("parent", p); |
| 954 | for (auto &it : *parent.m_data) { |
| 955 | // Handle overriding |
| 956 | const var &v = s.m_data->get_var(it.first); |
| 957 | if (!_parent.m_data->get_var(it.first).is_same(v)) |
| 958 | m_data->add_var(it.first.data(), copy(v)); |
| 959 | else |
| 960 | m_data->add_var(it.first.data(), parent.m_data->get_var_by_id(it.second)); |
| 961 | } |
| 962 | } |
| 963 | for (auto &it : *s.m_data) |
| 964 | if (!m_data->exist(it.first)) |
| 965 | m_data->add_var(it.first.data(), copy(s.m_data->get_var_by_id(it.second))); |
| 966 | if (m_data->exist("duplicate")) |
| 967 | invoke(m_data->get_var("duplicate"), var::make<structure>(this), var::make<structure>(&s)); |
| 968 | } |
| 969 | |
| 970 | explicit structure(const structure *s) : m_shadow(true), m_id(s->m_id), m_name(s->m_name), m_data(s->m_data) {} |
| 971 | |
| 972 | ~structure() |
| 973 | { |
| 974 | if (!m_shadow && m_data->exist("finalize")) |
| 975 | invoke(m_data->get_var("finalize"), var::make<structure>(this)); |
| 976 | } |
| 977 | |
| 978 | structure &operator=(structure &&s) noexcept |
nothing calls this directly
no test coverage detected