eb36858e78e21fd0606d505cbab03cb72ac00505
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / common / primitiveResource / src / RCSRepresentation.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics 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 #include "RCSRepresentation.h"
22
23 #include "ResourceAttributesConverter.h"
24
25 #include "OCRepresentation.h"
26
27 namespace OIC
28 {
29     namespace Service
30     {
31
32         RCSRepresentation::RCSRepresentation() { }
33
34         RCSRepresentation::RCSRepresentation(const std::string& uri) :
35                 m_uri{ uri }
36         {
37         }
38
39         RCSRepresentation::RCSRepresentation(const RCSResourceAttributes& attrs) :
40                 m_uri{ },
41                 m_interfaces{ },
42                 m_resourceTypes{ },
43                 m_attributes{ attrs }
44         {
45         }
46
47         RCSRepresentation::RCSRepresentation(const std::string& uri,
48                 const std::vector< std::string >& interfaces,
49                 const std::vector< std::string >& resourceTypes) :
50                 m_uri{ uri },
51                 m_interfaces{ interfaces },
52                 m_resourceTypes{ resourceTypes }
53         {
54         }
55
56         RCSRepresentation::RCSRepresentation(const std::string& uri,
57                 const std::vector< std::string >& interfaces,
58                 const std::vector< std::string >& resourceTypes,
59                 const RCSResourceAttributes& attrs) :
60                 m_uri{ uri },
61                 m_interfaces{ interfaces },
62                 m_resourceTypes{ resourceTypes },
63                 m_attributes{ attrs }
64         {
65         }
66
67         std::string RCSRepresentation::getUri() const
68         {
69             return m_uri;
70         }
71
72         void RCSRepresentation::setUri(const std::string& uri)
73         {
74             m_uri = uri;
75         }
76
77         void RCSRepresentation::setUri(std::string&& uri)
78         {
79             m_uri = std::move(uri);
80         }
81
82         const std::vector< std::string >& RCSRepresentation::getInterfaces() const
83         {
84             return m_interfaces;
85         }
86
87         void RCSRepresentation::addInterface(const std::string& interface)
88         {
89             m_interfaces.push_back(interface);
90         }
91
92         void RCSRepresentation::addInterface(std::string&& interface)
93         {
94             m_interfaces.push_back(std::move(interface));
95         }
96
97         void RCSRepresentation::clearInterfaces()
98         {
99             m_interfaces.clear();
100         }
101
102         const std::vector< std::string >& RCSRepresentation::getResourceTypes() const
103         {
104             return m_resourceTypes;
105         }
106
107         void RCSRepresentation::addResourceType(const std::string& resourceType)
108         {
109             m_resourceTypes.push_back(resourceType);
110         }
111
112         void RCSRepresentation::addResourceType(std::string&& resourceType)
113         {
114             m_resourceTypes.push_back(std::move(resourceType));
115         }
116
117         void RCSRepresentation::clearResourceTypes()
118         {
119             m_resourceTypes.clear();
120         }
121
122         const RCSResourceAttributes& RCSRepresentation::getAttributes() const
123         {
124             return m_attributes;
125         }
126
127         RCSResourceAttributes& RCSRepresentation::getAttributes()
128         {
129             return m_attributes;
130         }
131
132         void RCSRepresentation::setAttributes(const RCSResourceAttributes& attrs)
133         {
134             m_attributes = attrs;
135         }
136
137         void RCSRepresentation::setAttributes(RCSResourceAttributes&& attrs)
138         {
139             m_attributes = std::move(attrs);
140         }
141
142         void RCSRepresentation::addChild(const RCSRepresentation& child)
143         {
144             m_children.push_back(child);
145         }
146
147         void RCSRepresentation::addChild(RCSRepresentation&& child)
148         {
149             m_children.push_back(std::move(child));
150         }
151
152         void RCSRepresentation::setChildren(const std::vector< RCSRepresentation >& children)
153         {
154             m_children = children;
155         }
156
157         void RCSRepresentation::setChildren(std::vector< RCSRepresentation >&& children)
158         {
159             m_children = std::move(children);
160         }
161
162         const std::vector< RCSRepresentation >& RCSRepresentation::getChildren() const
163         {
164             return m_children;
165         }
166
167         void RCSRepresentation::clearChildren()
168         {
169             m_children.clear();
170         }
171
172
173         RCSRepresentation RCSRepresentation::fromOCRepresentation(const OC::OCRepresentation& ocRep)
174         {
175             return RCSRepresentation(ocRep.getUri(), ocRep.getResourceInterfaces(),
176                     ocRep.getResourceTypes(),
177                     ResourceAttributesConverter::fromOCRepresentation(ocRep));
178         }
179
180         OC::OCRepresentation RCSRepresentation::toOCRepresentation(const RCSRepresentation& rcsRep)
181         {
182             return toOCRepresentation(RCSRepresentation{ rcsRep });
183         }
184
185         OC::OCRepresentation RCSRepresentation::toOCRepresentation(RCSRepresentation&& rcsRep)
186         {
187             auto ocRep =
188                     ResourceAttributesConverter::toOCRepresentation(std::move(rcsRep.m_attributes));
189
190             ocRep.setUri(std::move(rcsRep.m_uri));
191             ocRep.setResourceInterfaces(std::move(rcsRep.m_interfaces));
192             ocRep.setResourceTypes(std::move(rcsRep.m_resourceTypes));
193
194             for (auto& child : rcsRep.m_children)
195             {
196                 ocRep.addChild(toOCRepresentation(std::move(child)));
197             }
198
199             return ocRep;
200         }
201     }
202 }