Spec compliance change to move oc/core/d to oic/p.
[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 __ATTRIBUTEVALUE_H
29 #define __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     > AttributeValue;
81
82     enum class AttributeType
83     {
84         Null,
85         Integer,
86         Double,
87         Boolean,
88         String,
89         OCRepresentation,
90         Vector
91     };
92
93     template<typename T>
94     struct AttributeTypeConvert{};
95
96     template<>
97     struct AttributeTypeConvert<NullType>
98     {
99         constexpr static AttributeType type = AttributeType::Null;
100     };
101
102     template<>
103     struct AttributeTypeConvert<int>
104     {
105         constexpr static AttributeType type = AttributeType::Integer;
106     };
107
108     template<>
109     struct AttributeTypeConvert<double>
110     {
111         constexpr static AttributeType type = AttributeType::Double;
112     };
113
114     template<>
115     struct AttributeTypeConvert<bool>
116     {
117         constexpr static AttributeType type = AttributeType::Boolean;
118     };
119
120     template<>
121     struct AttributeTypeConvert<std::string>
122     {
123         constexpr static AttributeType type = AttributeType::String;
124     };
125
126     template<>
127     struct AttributeTypeConvert<OCRepresentation>
128     {
129         constexpr static AttributeType type = AttributeType::OCRepresentation;
130     };
131
132     std::ostream& operator << (std::ostream& os, const AttributeType at);
133 }
134 #endif // __ATTRIBUTEVALUE_H