Updated Doxygen @param for OCResourceResponse::setResourceRepresentation
[platform/upstream/iotivity.git] / resource / include / AttributeValue.h
1
2 //******************************************************************
3 //
4 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //
6 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 //      http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
20 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21
22 /// @file AttributeValue.h
23
24 /// @brief  This file contains the definition of the internally used
25 // type AttributeValue
26
27 #ifndef __ATTRIBUTEVALUE_H
28 #define __ATTRIBUTEVALUE_H
29
30 // These defines are required to get the boost::variant to hold more than 20 items.
31 // documentation requires that you use a power of 10
32 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
33 #define BOOST_MPL_LIMIT_LIST_SIZE 30
34 #define BOOST_MPL_LIMIT_VECTOR_SIZE 30
35 #include <boost/variant.hpp>
36 #include <iosfwd>
37 #include <OCUtilities.h>
38 namespace OC
39 {
40     class OCRepresentation;
41
42     struct NullType{};
43
44     // Since null needs to be encoded in a special fashion in JSON, the encoder
45     // needs to know the index of the NullType Sentinel  Any time the code does a special
46     // case for the NullType, we use the AttributeValueNullIndex.  This MUST be kept up to date
47     // with the variant's which() for NullType.
48     static const int AttributeValueNullIndex = 0;
49     typedef boost::variant<
50         NullType, // Note: this handles the null-type and must match the above static const
51         int,
52         double,
53         bool,
54         std::string,
55         OC::OCRepresentation,
56
57         // Sequences:
58         std::vector<int>,
59         std::vector<double>,
60         std::vector<bool>,
61         std::vector<std::string>,
62         std::vector<OC::OCRepresentation>,
63
64         // Nested sequences:
65         std::vector<std::vector<int>>,
66         std::vector<std::vector<std::vector<int>>>,
67
68         std::vector<std::vector<double>>,
69         std::vector<std::vector<std::vector<double>>>,
70
71         std::vector<std::vector<bool>>,
72         std::vector<std::vector<std::vector<bool>>>,
73
74         std::vector<std::vector<std::string>>,
75         std::vector<std::vector<std::vector<std::string>>>,
76
77         std::vector<std::vector<OC::OCRepresentation>>,
78         std::vector<std::vector<std::vector<OC::OCRepresentation>>>
79     > AttributeValue;
80
81     enum class AttributeType
82     {
83         Null,
84         Integer,
85         Double,
86         Boolean,
87         String,
88         OCRepresentation,
89         Vector
90     };
91
92     template<typename T>
93     struct AttributeTypeConvert{};
94
95     template<>
96     struct AttributeTypeConvert<NullType>
97     {
98         constexpr static AttributeType type = AttributeType::Null;
99     };
100
101     template<>
102     struct AttributeTypeConvert<int>
103     {
104         constexpr static AttributeType type = AttributeType::Integer;
105     };
106
107     template<>
108     struct AttributeTypeConvert<double>
109     {
110         constexpr static AttributeType type = AttributeType::Double;
111     };
112
113     template<>
114     struct AttributeTypeConvert<bool>
115     {
116         constexpr static AttributeType type = AttributeType::Boolean;
117     };
118
119     template<>
120     struct AttributeTypeConvert<std::string>
121     {
122         constexpr static AttributeType type = AttributeType::String;
123     };
124
125     template<>
126     struct AttributeTypeConvert<OCRepresentation>
127     {
128         constexpr static AttributeType type = AttributeType::OCRepresentation;
129     };
130
131     std::ostream& operator << (std::ostream& os, const AttributeType at);
132 }
133 #endif // __ATTRIBUTEVALUE_H