1 /******************************************************************
\r
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
19 ******************************************************************/
\r
21 #ifndef RESOURCE_PROPERTIES_H_
\r
22 #define RESOURCE_PROPERTIES_H_
\r
28 #include <boost/variant.hpp>
\r
29 #include <boost/lexical_cast.hpp>
\r
34 class ResourceProperties
\r
37 ResourceProperties() {}
\r
38 ResourceProperties(cJSON *cjson) : m_cjson(cjson) { readJson();}
\r
43 typedef boost::variant <
\r
49 Attribute() = default;
\r
50 Attribute(const std::string &attrName) : m_name(attrName) {}
\r
52 inline std::string getName(void) const { return m_name; }
\r
53 inline void setName(const std::string &name) { m_name = name;}
\r
55 template <typename T>
\r
59 return boost::get<T>(m_value);
\r
62 ValueVariant &getValue()
\r
67 int getValueType() const
\r
69 return m_value.which();
\r
73 return boost::lexical_cast<int> (m_value);
\r
75 std::string getValueString()
\r
77 return boost::lexical_cast<std::string> (m_value);
\r
80 template <typename T>
\r
81 void setValue(const T &value)
\r
86 inline void getRange(int &min, int &max) const
\r
92 inline void setRange(const int &min, const int &max)
\r
98 template <typename T>
\r
99 bool setAllowedValues(const std::vector<T> &values)
\r
101 ValueVariant temp = values.at(0);
\r
102 if (temp.which() != m_value.which())
\r
107 m_allowedValues.addValues(values);
\r
110 inline int getAllowedValuesSize() const
\r
112 return m_allowedValues.size();
\r
115 inline std::vector<ValueVariant> getAllowedValues()
\r
117 return m_allowedValues.getValues();
\r
120 int getUpdateFrequencyTime() {return m_updateInterval;}
\r
121 void setUpdateFrequencyTime(int interval) {m_updateInterval = interval;}
\r
124 class AllowedValues
\r
127 template <typename T>
\r
128 void addValue(const T &value)
\r
130 ValueVariant temp = value;
\r
131 m_values.push_back(temp);
\r
134 template <typename T>
\r
135 void addValues(const std::vector<T> &values)
\r
137 for (auto value : values)
\r
139 ValueVariant vValue = value;
\r
140 m_values.push_back(vValue);
\r
144 inline ValueVariant &at(int index)
\r
146 return m_values.at(index);
\r
148 inline int size() const
\r
150 return m_values.size();
\r
153 inline std::vector<ValueVariant> getValues()
\r
159 std::vector<ValueVariant> m_values;
\r
162 std::string m_name;
\r
163 ValueVariant m_value;
\r
166 AllowedValues m_allowedValues;
\r
167 int m_updateInterval;
\r
169 int size() const { return m_attributes.size(); }
\r
170 inline bool getAttribute(const std::string &attrName, Attribute &value)
\r
172 if (m_attributes.end() != m_attributes.find(attrName))
\r
174 value = m_attributes[attrName];
\r
181 inline std::map<std::string, Attribute> getAttributes() const
\r
183 return m_attributes;
\r
187 template <typename T>
\r
188 void addAttribute(const std::string &attrName, const T &attrValue)
\r
190 if (m_attributes.end() == m_attributes.find(attrName))
\r
192 m_attributes[attrName] = Attribute(attrName);
\r
193 m_attributes[attrName].setValue(attrValue);
\r
198 inline void setRange(const std::string &attrName, const int min, const int max)
\r
200 if (m_attributes.end() != m_attributes.find(attrName))
\r
201 m_attributes[attrName].setRange(min, max);
\r
205 template <typename T>
\r
206 void setAllowedValues(const std::string &attrName, const std::vector<T> &values)
\r
208 if (m_attributes.end() != m_attributes.find(attrName))
\r
209 m_attributes[attrName].setAllowedValues(values);
\r
212 inline void setUpdateInterval(const std::string &attrName, int interval)
\r
214 if (m_attributes.end() != m_attributes.find(attrName))
\r
215 m_attributes[attrName].setUpdateFrequencyTime(interval);
\r
219 inline void removeAttribute(const std::string &attrName)
\r
221 m_attributes.erase(attrName);
\r
227 std::string getResoureType() const {return m_rt; }
\r
228 std::string getInterface() const {return m_if; }
\r
231 std::map<std::string, Attribute> m_attributes;
\r