RDK Documentation (Open Sourced RDK Components)
Accessibility.hpp
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18 */
19 
20 #ifndef __ACCESSIBILITY__
21 #define __ACCESSIBILITY__
22 
23 #include <string>
24 
25 /**
26  * @class Accessibility
27  * @brief Data type to store Accessibility Node data
28  */
30 {
31  std::string strSchemeId;
32  int intValue;
33  std::string strValue;
34  std::string valueType;
35 
36  bool isNumber(const std::string& str)
37  {
38  std::string::const_iterator it = str.begin();
39  while (it != str.end() && std::isdigit(*it)) ++it;
40  return !str.empty() && it == str.end();
41  };
42 
43  public:
44  Accessibility(std::string schemId, std::string val): strSchemeId(schemId), intValue(-1), strValue(""), valueType("")
45  {
46  if (isNumber(val))
47  {
48  valueType = "int_value";
49  intValue = std::stoi(val);
50  strValue = "";
51  }
52  else
53  {
54  valueType = "string_value";
55  intValue = -1;
56  strValue = val;
57  }
58 
59  };
60 
61  Accessibility():strSchemeId(""), intValue(-1), strValue(""), valueType("") {};
62 
63  void setAccessibilityData(std::string schemId, std::string val)
64  {
65  strSchemeId = schemId;
66  if (isNumber(val))
67  {
68  valueType = "int_value";
69  intValue = std::stoi(val);
70  strValue = "";
71  }
72  else
73  {
74  valueType = "string_value";
75  intValue = -1;
76  strValue = val;
77  }
78  };
79 
80  void setAccessibilityData(std::string schemId, int val)
81  {
82  strSchemeId = schemId;
83  valueType = "int_value";
84  intValue = val;
85  strValue = "";
86  };
87 
88  std::string& getTypeName() {return valueType;};
89  std::string& getSchemeId() {return strSchemeId;};
90  int getIntValue() {return intValue;};
91  std::string& getStrValue() {return strValue;};
92  void clear()
93  {
94  strSchemeId = "";
95  intValue = -1;
96  strValue = "";
97  valueType = "";
98  };
99 
100  bool operator == (const Accessibility& track) const
101  {
102  return ((strSchemeId == track.strSchemeId) &&
103  (valueType == "int_value"?(intValue == track.intValue):(strValue == track.strValue)));
104  };
105 
106  bool operator != (const Accessibility& track) const
107  {
108  return ((strSchemeId != track.strSchemeId) ||
109  (valueType == "int_value"?(intValue != track.intValue):(strValue != track.strValue)));
110  };
111 
112  Accessibility& operator = (const Accessibility& track)
113  {
114  strSchemeId = track.strSchemeId;
115  intValue = track.intValue;
116  strValue = track.strValue;
117  valueType = track.valueType;
118 
119  return *this;
120  };
121 
122  std::string print()
123  {
124  char strData [228];
125  std::string retVal = "";
126  if (!strSchemeId.empty())
127  {
128  std::snprintf(strData, sizeof(strData), "{ scheme:%s, %s:", strSchemeId.c_str(), valueType.c_str());
129  retVal += strData;
130  if (valueType == "int_value")
131  {
132  std::snprintf(strData, sizeof(strData), "%d }", intValue);
133  }else
134  {
135  std::snprintf(strData, sizeof(strData), "%s }", strValue.c_str());
136  }
137  retVal += strData;
138  }
139  else
140  {
141  retVal = "NULL";
142  }
143  return retVal;
144  };
145 };
146 
147 #endif // __ACCESSIBILITY__
148 
Accessibility
Data type to store Accessibility Node data.
Definition: Accessibility.hpp:29