1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
22 * @file simulator_resource_model.h
24 * @brief This file contains a class which represents the resource model for simulator
25 * resources and provides a set of functions for updating the model.
28 #ifndef SIMULATOR_RESOURCE_MODEL_H_
29 #define SIMULATOR_RESOURCE_MODEL_H_
34 #include "OCPlatform.h"
36 class SimulatorResourceModel;
37 typedef boost::variant <
42 SimulatorResourceModel,
47 std::vector<std::string>,
48 std::vector<SimulatorResourceModel>,
50 std::vector<std::vector<int>>,
51 std::vector<std::vector<double>>,
52 std::vector<std::vector<bool>>,
53 std::vector<std::vector<std::string>>,
54 std::vector<std::vector<SimulatorResourceModel>>,
56 std::vector<std::vector<std::vector<int>>>,
57 std::vector<std::vector<std::vector<double>>>,
58 std::vector<std::vector<std::vector<bool>>>,
59 std::vector<std::vector<std::vector<std::string>>>,
60 std::vector<std::vector<std::vector<SimulatorResourceModel>>>
61 > AttributeValueVariant;
63 enum class AttributeValueType
74 class OCRepresentationBuilder;
75 class ToStringConverter;
76 class AttributeProperty;
79 * @class SimulatorResourceModel
80 * @brief This class provides a set of functions for accessing and manipulating the resource model.
82 class SimulatorResourceModel
85 friend class OCRepresentationBuilder;
86 friend class ToStringConverter;
91 TypeInfo(AttributeValueType type = AttributeValueType::UNKNOWN,
92 AttributeValueType baseType = AttributeValueType::UNKNOWN, int depth = 0);
93 AttributeValueType type() const;
94 AttributeValueType baseType() const;
96 bool operator ==(const TypeInfo &rhs) const;
99 AttributeValueType m_type;
100 AttributeValueType m_baseType;
104 template <typename T>
105 bool add(const std::string &name, T value)
107 if (!name.empty() && m_attributes.end() == m_attributes.find(name))
109 AttributeValueVariant newValue = value;
110 m_attributes[name] = value;
116 template <typename T>
117 T get(const std::string &name) const
120 auto x = m_attributes.find(name);
121 if (x != m_attributes.end())
125 val = boost::get<T>(x->second);
127 catch (boost::bad_get &e)
135 template <typename T>
136 bool update(const std::string &name, T value)
138 AttributeValueVariant newValue = value;
139 return updateValue(name, newValue);
142 bool remove(const std::string &name);
144 bool contains(const std::string &name) const;
148 TypeInfo getType(const std::string &name) const;
150 std::map<std::string, AttributeValueVariant> getAttributeValues() const;
152 AttributeValueVariant getAttributeValue(const std::string &name) const;
154 std::set<std::string> getAttributeNameSet() const;
156 OC::OCRepresentation asOCRepresentation() const;
158 std::string asString() const;
160 static SimulatorResourceModel build(const OC::OCRepresentation &ocRep);
163 TypeInfo getTypeInfo(const AttributeValueVariant &value) const;
164 bool updateValue(const std::string &name, const AttributeValueVariant &value);
166 std::map<std::string, AttributeValueVariant> m_attributes;
169 class SimulatorResourceAttribute
172 SimulatorResourceAttribute() = default;
173 SimulatorResourceAttribute(const std::string &name);
174 SimulatorResourceAttribute(const std::string &name, const AttributeValueVariant &value);
176 std::string getName() const;
177 const SimulatorResourceModel::TypeInfo getType() const;
178 std::shared_ptr<AttributeProperty> getProperty() const;
179 AttributeValueVariant getValue() const;
181 void setName(const std::string &name);
182 void setProperty(const std::shared_ptr<AttributeProperty> &property);
184 template <typename T>
185 void setValue(const T &value)
187 m_value = std::make_shared<AttributeValueVariant>(value);
190 std::string asString() const;
194 std::shared_ptr<AttributeValueVariant> m_value;
195 std::shared_ptr<AttributeProperty> m_property;
198 typedef std::shared_ptr<SimulatorResourceModel> SimulatorResourceModelSP;