Imported Upstream version 1.1.0
[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(std::string uri)
73         {
74             m_uri = std::move(uri);
75         }
76
77         const std::vector< std::string >& RCSRepresentation::getInterfaces() const
78         {
79             return m_interfaces;
80         }
81
82         void RCSRepresentation::addInterface(std::string interface)
83         {
84             m_interfaces.push_back(std::move(interface));
85         }
86
87         void RCSRepresentation::clearInterfaces()
88         {
89             m_interfaces.clear();
90         }
91
92         const std::vector< std::string >& RCSRepresentation::getResourceTypes() const
93         {
94             return m_resourceTypes;
95         }
96
97         void RCSRepresentation::addResourceType(std::string resourceType)
98         {
99             m_resourceTypes.push_back(std::move(resourceType));
100         }
101
102         void RCSRepresentation::clearResourceTypes()
103         {
104             m_resourceTypes.clear();
105         }
106
107         const RCSResourceAttributes& RCSRepresentation::getAttributes() const
108         {
109             return m_attributes;
110         }
111
112         RCSResourceAttributes& RCSRepresentation::getAttributes()
113         {
114             return m_attributes;
115         }
116
117         void RCSRepresentation::setAttributes(const RCSResourceAttributes& attrs)
118         {
119             m_attributes = attrs;
120         }
121
122         void RCSRepresentation::setAttributes(RCSResourceAttributes&& attrs)
123         {
124             m_attributes = std::move(attrs);
125         }
126
127         void RCSRepresentation::addChild(RCSRepresentation child)
128         {
129             m_children.push_back(std::move(child));
130         }
131
132         void RCSRepresentation::setChildren(std::vector< RCSRepresentation > children)
133         {
134             m_children = std::move(children);
135         }
136
137         const std::vector< RCSRepresentation >& RCSRepresentation::getChildren() const
138         {
139             return m_children;
140         }
141
142         void RCSRepresentation::clearChildren()
143         {
144             m_children.clear();
145         }
146
147
148         RCSRepresentation RCSRepresentation::fromOCRepresentation(const OC::OCRepresentation& ocRep)
149         {
150             return RCSRepresentation(ocRep.getUri(), ocRep.getResourceInterfaces(),
151                     ocRep.getResourceTypes(),
152                     ResourceAttributesConverter::fromOCRepresentation(ocRep));
153         }
154
155         OC::OCRepresentation RCSRepresentation::toOCRepresentation(const RCSRepresentation& rcsRep)
156         {
157             return toOCRepresentation(RCSRepresentation{ rcsRep });
158         }
159
160         OC::OCRepresentation RCSRepresentation::toOCRepresentation(RCSRepresentation&& rcsRep)
161         {
162             auto ocRep =
163                     ResourceAttributesConverter::toOCRepresentation(std::move(rcsRep.m_attributes));
164
165             ocRep.setUri(std::move(rcsRep.m_uri));
166             ocRep.setResourceInterfaces(std::move(rcsRep.m_interfaces));
167             ocRep.setResourceTypes(std::move(rcsRep.m_resourceTypes));
168
169             for (auto& child : rcsRep.m_children)
170             {
171                 ocRep.addChild(toOCRepresentation(std::move(child)));
172             }
173
174             return ocRep;
175         }
176     }
177 }