1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the definition of the internally used type
28 #ifndef OC_ATTRIBUTEVALUE_H_
29 #define OC_ATTRIBUTEVALUE_H_
31 // These defines are required to get the boost::variant to hold more than 20 items.
32 // documentation requires that you use a power of 10
33 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
34 #define BOOST_MPL_LIMIT_LIST_SIZE 30
35 #define BOOST_MPL_LIMIT_VECTOR_SIZE 30
36 #include <boost/variant.hpp>
38 #include <OCUtilities.h>
41 class OCRepresentation;
45 // Since null needs to be encoded in a special fashion in JSON, the encoder
46 // needs to know the index of the NullType Sentinel Any time the code does a special
47 // case for the NullType, we use the AttributeValueNullIndex. This MUST be kept up to date
48 // with the variant's which() for NullType.
49 static const int AttributeValueNullIndex = 0;
50 typedef boost::variant<
51 NullType, // Note: this handles the null-type and must match the above static const
63 std::vector<std::string>,
64 std::vector<OC::OCRepresentation>,
65 std::vector<OCByteString>,
68 std::vector<std::vector<int>>,
69 std::vector<std::vector<std::vector<int>>>,
71 std::vector<std::vector<double>>,
72 std::vector<std::vector<std::vector<double>>>,
74 std::vector<std::vector<bool>>,
75 std::vector<std::vector<std::vector<bool>>>,
77 std::vector<std::vector<std::string>>,
78 std::vector<std::vector<std::vector<std::string>>>,
80 std::vector<std::vector<OC::OCRepresentation>>,
81 std::vector<std::vector<std::vector<OC::OCRepresentation>>>,
83 std::vector<std::vector<OCByteString>>,
84 std::vector<std::vector<std::vector<OCByteString>>>,
86 // used for binary data type
90 enum class AttributeType
104 struct AttributeTypeConvert{};
107 struct AttributeTypeConvert<NullType>
109 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Null;
113 struct AttributeTypeConvert<int>
115 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Integer;
119 struct AttributeTypeConvert<double>
121 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Double;
125 struct AttributeTypeConvert<bool>
127 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Boolean;
131 struct AttributeTypeConvert<std::string>
133 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::String;
137 struct AttributeTypeConvert<OCRepresentation>
139 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::OCRepresentation;
143 struct AttributeTypeConvert<OCByteString>
145 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::OCByteString;
149 struct AttributeTypeConvert<std::vector<uint8_t>>
151 BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Binary;
154 std::ostream& operator << (std::ostream& os, const AttributeType at);
156 #endif // OC_ATTRIBUTEVALUE_H_