Implementation of JNI for subscribe device presence to RD
[platform/upstream/iotivity.git] / resource / include / AttributeValue.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
21 /**
22  * @file
23  *
24  * This file contains the definition of the internally used type
25  * AttributeValue.
26  */
27
28 #ifndef OC_ATTRIBUTEVALUE_H_
29 #define OC_ATTRIBUTEVALUE_H_
30
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>
37 #include <iosfwd>
38 #include <OCUtilities.h>
39 namespace OC
40 {
41     class OCRepresentation;
42
43     struct NullType{};
44
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
52         int,
53         double,
54         bool,
55         std::string,
56         OC::OCRepresentation,
57
58         // Sequences:
59         std::vector<int>,
60         std::vector<double>,
61         std::vector<bool>,
62         std::vector<std::string>,
63         std::vector<OC::OCRepresentation>,
64
65         // Nested sequences:
66         std::vector<std::vector<int>>,
67         std::vector<std::vector<std::vector<int>>>,
68
69         std::vector<std::vector<double>>,
70         std::vector<std::vector<std::vector<double>>>,
71
72         std::vector<std::vector<bool>>,
73         std::vector<std::vector<std::vector<bool>>>,
74
75         std::vector<std::vector<std::string>>,
76         std::vector<std::vector<std::vector<std::string>>>,
77
78         std::vector<std::vector<OC::OCRepresentation>>,
79         std::vector<std::vector<std::vector<OC::OCRepresentation>>>,
80
81         // used for binary data type
82         std::vector<uint8_t>
83     > AttributeValue;
84
85     enum class AttributeType
86     {
87         Null,
88         Integer,
89         Double,
90         Boolean,
91         String,
92         OCRepresentation,
93         Vector,
94         Binary
95     };
96
97     template<typename T>
98     struct AttributeTypeConvert{};
99
100     template<>
101     struct AttributeTypeConvert<NullType>
102     {
103         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Null;
104     };
105
106     template<>
107     struct AttributeTypeConvert<int>
108     {
109         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Integer;
110     };
111
112     template<>
113     struct AttributeTypeConvert<double>
114     {
115         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Double;
116     };
117
118     template<>
119     struct AttributeTypeConvert<bool>
120     {
121         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Boolean;
122     };
123
124     template<>
125     struct AttributeTypeConvert<std::string>
126     {
127         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::String;
128     };
129
130     template<>
131     struct AttributeTypeConvert<OCRepresentation>
132     {
133         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::OCRepresentation;
134     };
135
136     template<>
137     struct AttributeTypeConvert<std::vector<uint8_t>>
138     {
139         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Binary;
140     };
141
142     std::ostream& operator << (std::ostream& os, const AttributeType at);
143 }
144 #endif // OC_ATTRIBUTEVALUE_H_