Safir SDK Core
Loading...
Searching...
No Matches
ContainerProxies.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2008-2013 (http://safirsdkcore.com)
4*
5* Created by: Lars Hagström / stlrha
6*
7*******************************************************************************
8*
9* This file is part of Safir SDK Core.
10*
11* Safir SDK Core is free software: you can redistribute it and/or modify
12* it under the terms of version 3 of the GNU General Public License as
13* published by the Free Software Foundation.
14*
15* Safir SDK Core is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22*
23******************************************************************************/
24
25#ifndef __DOTS_CONTAINER_PROXIES_H__
26#define __DOTS_CONTAINER_PROXIES_H__
27
30
31namespace Safir
32{
33namespace Dob
34{
35namespace Typesystem
36{
37 template <class T>
39 {
40 public:
41 typedef typename T::ContainedType ContainedType;
42
43 explicit ContainerProxy(T& container):m_container(container){}
44
45 ContainerProxy(const ContainerProxy& other) = default;
46
48 {
49 if (other.IsNull())
50 {
51 m_container.SetNull();
52 }
53 else
54 {
55 m_container.SetVal(other.GetVal());
56 }
57 return *this;
58 }
59
60 ContainerProxy& operator=(const ContainedType other) {m_container.SetVal(other);return *this;}
61
62 operator const ContainedType() const {return m_container.GetVal();}
63
64 bool IsNull() const {return m_container.IsNull();}
65 void SetNull() {m_container.SetNull();}
66 bool IsChanged() const {return m_container.IsChanged();}
67 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
68
69
70 void SetVal(const ContainedType value) {m_container.SetVal(value);}
71
72 const ContainedType GetVal() const {return m_container.GetVal();}
73
74 void SetOrdinal(const EnumerationValue value){m_container.SetOrdinal(value);}
75 EnumerationValue GetOrdinal() const {return m_container.GetOrdinal();}
76
77 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
78
80 {
81 ContainedType val = GetVal();
82 ++val;
83 SetVal(val);
84 return *this;
85 }
86
87 //Does not return anything since I'm not sure what it should return.
88 void operator++ (int) // postfix ++
89 {
90 ++(*this);
91 }
92
94 {
95 ContainedType val = GetVal();
96 --val;
97 SetVal(val);
98 return *this;
99 }
100
101 //Does not return anything since I'm not sure what it should return.
102 void operator-- (int) // postfix --
103 {
104 --(*this);
105 }
106
107
109 {
110 SetVal(GetVal() + val);
111 return *this;
112 }
113
115 {
116 SetVal(GetVal() - val);
117 return *this;
118 }
119
121 {
122 SetVal(GetVal() * val);
123 return *this;
124 }
125
127 {
128 SetVal(GetVal() / val);
129 return *this;
130 }
131
132 const T& GetContainer() const {return m_container;}
133 T& GetContainer() {return m_container;}
134 private:
135 T& m_container;
136 };
137
138 static inline bool operator==(const ContainerProxy<ChannelIdContainer>& first, const ChannelId& second)
139 {return second == first.GetVal();}
140 static inline bool operator!=(const ContainerProxy<ChannelIdContainer>& first, const ChannelId& second)
141 {return second != first.GetVal();}
142
143 static inline bool operator==(const ContainerProxy<HandlerIdContainer>& first, const HandlerId& second)
144 {return second == first.GetVal();}
145 static inline bool operator!=(const ContainerProxy<HandlerIdContainer>& first, const HandlerId& second)
146 {return second != first.GetVal();}
147
148 static inline bool operator==(const ContainerProxy<InstanceIdContainer>& first, const InstanceId& second)
149 {return second == first.GetVal();}
150 static inline bool operator!=(const ContainerProxy<InstanceIdContainer>& first, const InstanceId& second)
151 {return second != first.GetVal();}
152
153 static inline bool operator==(const ContainerProxy<EntityIdContainer>& first, const EntityId& second)
154 {return second == first.GetVal();}
155 static inline bool operator!=(const ContainerProxy<EntityIdContainer>& first, const EntityId& second)
156 {return second != first.GetVal();}
157
158 template <>
160 {
161 public:
163
164 explicit ContainerProxy(StringContainer& container):m_container(container){}
165
167 {
168 if (other.IsNull())
169 {
170 m_container.SetNull();
171 }
172 else
173 {
174 m_container.SetVal(other.GetVal());
175 }
176 return *this;
177 }
178
179 ContainerProxy& operator=(const ContainedType& other) {m_container.SetVal(other);return *this;}
180
181 operator const ContainedType& () const {return m_container.GetVal();}
182
183 bool IsNull() const {return m_container.IsNull();}
184 void SetNull() {m_container.SetNull();}
185 bool IsChanged() const {return m_container.IsChanged();}
186 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
187
188
189 void SetVal(const ContainedType& value) {m_container.SetVal(value);}
190
191 const ContainedType& GetVal() const {return m_container.GetVal();}
192
193 Int32 Utf8StringLength() const {return m_container.Utf8StringLength();}
194 const std::string & Utf8String() const {return m_container.Utf8String();}
195
196 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
197
199 {
200 SetVal(GetVal() + val);
201 return *this;
202 }
203
204 bool operator== (const ContainedType& val) const
205 {
206 return m_container.GetVal() == val;
207 }
208
209 bool operator!= (const ContainedType& val) const
210 {
211 return m_container.GetVal() != val;
212 }
213
214 const StringContainer& GetContainer() const {return m_container;}
215 StringContainer& GetContainer() {return m_container;}
216 private:
217 StringContainer& m_container;
218 };
219
220 static inline bool operator==(const std::wstring& first, const ContainerProxy<StringContainer>& second)
221 {return second.GetVal() == first;}
222 static inline bool operator!=(const std::wstring& first, const ContainerProxy<StringContainer>& second)
223 {return second.GetVal() != first;}
224
225 template <>
227 {
228 public:
230
231 explicit ContainerProxy(BinaryContainer& container):m_container(container){}
232
234 {
235 if (other.IsNull())
236 {
237 m_container.SetNull();
238 }
239 else
240 {
241 m_container.SetVal(other.GetVal());
242 }
243 return *this;
244 }
245
246 ContainerProxy& operator=(const ContainedType& other) {m_container.SetVal(other);return *this;}
247
248 operator const ContainedType& () const {return m_container.GetVal();}
249
250 bool IsNull() const {return m_container.IsNull();}
251 void SetNull() {m_container.SetNull();}
252 bool IsChanged() const {return m_container.IsChanged();}
253 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
254
255
256 void SetVal(const ContainedType& value) {m_container.SetVal(value);}
257
258 const ContainedType& GetVal() const {return m_container.GetVal();}
259 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
260
261 bool operator== (const ContainedType& val) const
262 {
263 return m_container.GetVal() == val;
264 }
265
266 bool operator!= (const ContainedType& val) const
267 {
268 return m_container.GetVal() != val;
269 }
270
271 const BinaryContainer& GetContainer() const {return m_container;}
272 BinaryContainer& GetContainer() {return m_container;}
273 private:
274 BinaryContainer& m_container;
275 };
276
277 static inline bool operator==(const Binary& first, const ContainerProxy<BinaryContainer>& second)
278 {return second.GetVal() == first;}
279 static inline bool operator!=(const Binary& first, const ContainerProxy<BinaryContainer>& second)
280 {return second.GetVal() != first;}
281
282 template <class U>
284 {
285 public:
287
288 explicit ContainerProxy(ObjectContainerImpl<U>& container):m_container(container){}
289
291 {
292 if (other.IsNull())
293 {
294 m_container.SetNull();
295 }
296 else
297 {
298 m_container.SetPtr(other);
299 }
300 return *this;
301 }
302
303 ContainerProxy& operator=(const ContainedType& other) {m_container.SetPtr(other);return *this;}
304
305 operator const ContainedType () const {return m_container.GetPtr();}
306
307 U* operator->() const
308 { return m_container.operator->(); }
309
310 bool IsNull() const {return m_container.IsNull();}
311 void SetNull() {m_container.SetNull();}
312 bool IsChanged() const {return m_container.IsChanged();}
313 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
314
315 void SetChangedHere(const bool changed) {m_container.SetChangedHere(changed);}
316 bool IsChangedHere() const {return m_container.IsChangedHere();}
317
318 void SetPtr(const ContainedType& ptr) {m_container.SetPtr(ptr);}
319 void SetPtr(const ObjectPtr& ptr) {m_container.SetPtr(ptr);}
320
321 const ContainedType& GetPtr() const {return m_container.GetPtr();}
322 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
323
324 const ObjectContainerImpl<U>& GetContainer() const {return m_container;}
325 ObjectContainerImpl<U>& GetContainer() {return m_container;}
326 private:
327 ObjectContainerImpl<U>& m_container;
328 };
329
330
331 template <>
333 {
334 public:
336
337 explicit ContainerProxy(ObjectContainerImpl<Object>& container):m_container(container){}
338
340 {
341 if (other.IsNull())
342 {
343 m_container.SetNull();
344 }
345 else
346 {
347 m_container.SetPtr(other);
348 }
349 return *this;
350 }
351
352 ContainerProxy& operator=(const ContainedType& other) {m_container.SetPtr(other);return *this;}
353
354 operator const ContainedType () const {return m_container.GetPtr();}
355
357 { return m_container.operator->(); }
358
359 bool IsNull() const {return m_container.IsNull();}
360 void SetNull() {m_container.SetNull();}
361 bool IsChanged() const {return m_container.IsChanged();}
362 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
363
364 void SetChangedHere(const bool changed) {m_container.SetChangedHere(changed);}
365 bool IsChangedHere() const {return m_container.IsChangedHere();}
366
367 void SetPtr(const ObjectPtr& ptr) {m_container.SetPtr(ptr);}
368
369 const ContainedType& GetPtr() const {return m_container.GetPtr();}
370
371 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
372
373 const ObjectContainerImpl<Object>& GetContainer() const {return m_container;}
375 private:
376 ObjectContainerImpl<Object>& m_container;
377 };
378
379}
380}
381}
382
383#endif
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
DotsC_EnumerationValue EnumerationValue
The ordinal value of an enumeration.
Definition Defs.h:270
static bool operator!=(const ContainerProxy< ChannelIdContainer > &first, const ChannelId &second)
Definition ContainerProxies.h:140
std::vector< char > Binary
A type to contain binary data.
Definition Defs.h:306
DotsC_Int32 Int32
32 bit integer type.
Definition Defs.h:66
std::shared_ptr< Object > ObjectPtr
A smart pointer to an Object.
Definition Object.h:44
static bool operator==(const ContainerProxy< ChannelIdContainer > &first, const ChannelId &second)
Definition ContainerProxies.h:138
Class containing the identity of a channel.
Definition ChannelId.h:46
Definition ContainerProxies.h:39
bool IsNull() const
Definition ContainerProxies.h:64
ContainerProxy & operator++()
Definition ContainerProxies.h:79
void SetChanged(const bool changed)
Definition ContainerProxies.h:67
ContainerProxy & operator--()
Definition ContainerProxies.h:93
bool IsChanged() const
Definition ContainerProxies.h:66
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:47
EnumerationValue GetOrdinal() const
Definition ContainerProxies.h:75
const T & GetContainer() const
Definition ContainerProxies.h:132
void SetOrdinal(const EnumerationValue value)
Definition ContainerProxies.h:74
const ContainedType GetVal() const
Definition ContainerProxies.h:72
ContainerProxy & operator/=(const ContainedType &val)
Definition ContainerProxies.h:126
ContainerProxy & operator*=(const ContainedType &val)
Definition ContainerProxies.h:120
void SetVal(const ContainedType value)
Definition ContainerProxies.h:70
ContainerProxy & operator=(const ContainedType other)
Definition ContainerProxies.h:60
ContainerProxy & operator-=(const ContainedType &val)
Definition ContainerProxies.h:114
ContainerProxy & operator+=(const ContainedType &val)
Definition ContainerProxies.h:108
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:77
void SetNull()
Definition ContainerProxies.h:65
T::ContainedType ContainedType
Definition ContainerProxies.h:41
T & GetContainer()
Definition ContainerProxies.h:133
ContainerProxy(T &container)
Definition ContainerProxies.h:43
ContainerProxy(const ContainerProxy &other)=default
const ContainedType & GetVal() const
Definition ContainerProxies.h:191
void SetChanged(const bool changed)
Definition ContainerProxies.h:186
ContainerProxy(StringContainer &container)
Definition ContainerProxies.h:164
const StringContainer & GetContainer() const
Definition ContainerProxies.h:214
void SetNull()
Definition ContainerProxies.h:184
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:196
bool IsChanged() const
Definition ContainerProxies.h:185
const std::string & Utf8String() const
Definition ContainerProxies.h:194
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:179
StringContainer::ContainedType ContainedType
Definition ContainerProxies.h:162
StringContainer & GetContainer()
Definition ContainerProxies.h:215
void SetVal(const ContainedType &value)
Definition ContainerProxies.h:189
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:166
bool IsNull() const
Definition ContainerProxies.h:183
Int32 Utf8StringLength() const
Definition ContainerProxies.h:193
void SetVal(const ContainedType &value)
Definition ContainerProxies.h:256
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:233
bool IsNull() const
Definition ContainerProxies.h:250
void SetNull()
Definition ContainerProxies.h:251
const BinaryContainer & GetContainer() const
Definition ContainerProxies.h:271
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:259
void SetChanged(const bool changed)
Definition ContainerProxies.h:253
bool IsChanged() const
Definition ContainerProxies.h:252
BinaryContainer::ContainedType ContainedType
Definition ContainerProxies.h:229
BinaryContainer & GetContainer()
Definition ContainerProxies.h:272
const ContainedType & GetVal() const
Definition ContainerProxies.h:258
ContainerProxy(BinaryContainer &container)
Definition ContainerProxies.h:231
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:246
void SetChangedHere(const bool changed)
Definition ContainerProxies.h:315
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:290
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:303
bool IsChanged() const
Definition ContainerProxies.h:312
bool IsChangedHere() const
Definition ContainerProxies.h:316
void SetPtr(const ContainedType &ptr)
Definition ContainerProxies.h:318
const ContainedType & GetPtr() const
Definition ContainerProxies.h:321
ObjectContainerImpl< U > & GetContainer()
Definition ContainerProxies.h:325
ContainerProxy(ObjectContainerImpl< U > &container)
Definition ContainerProxies.h:288
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:322
const ObjectContainerImpl< U > & GetContainer() const
Definition ContainerProxies.h:324
void SetPtr(const ObjectPtr &ptr)
Definition ContainerProxies.h:319
ObjectContainerImpl< U >::T_Ptr ContainedType
Definition ContainerProxies.h:286
bool IsNull() const
Definition ContainerProxies.h:310
U * operator->() const
Definition ContainerProxies.h:307
void SetChanged(const bool changed)
Definition ContainerProxies.h:313
ContainerProxy(ObjectContainerImpl< Object > &container)
Definition ContainerProxies.h:337
const ObjectContainerImpl< Object > & GetContainer() const
Definition ContainerProxies.h:373
void SetChanged(const bool changed)
Definition ContainerProxies.h:362
const ContainedType & GetPtr() const
Definition ContainerProxies.h:369
Object * operator->() const
Definition ContainerProxies.h:356
ObjectContainerImpl< Object > & GetContainer()
Definition ContainerProxies.h:374
bool IsChangedHere() const
Definition ContainerProxies.h:365
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:352
void SetChangedHere(const bool changed)
Definition ContainerProxies.h:364
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:339
bool IsChanged() const
Definition ContainerProxies.h:361
ObjectContainerImpl< Object >::T_Ptr ContainedType
Definition ContainerProxies.h:335
void SetPtr(const ObjectPtr &ptr)
Definition ContainerProxies.h:367
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:371
Class containing the identity of an entity.
Definition EntityId.h:43
Class containing the identity of a handler.
Definition HandlerId.h:46
Class containing the identity of an instance.
Definition InstanceId.h:49
The base class for all DOB objects.
Definition Object.h:55
Template class for all containers of automatically generated DOB objects.
Definition ObjectContainer.h:190
std::shared_ptr< T > T_Ptr
Typedef for the contained smart pointer.
Definition ObjectContainer.h:193
Container for strings (std::wstring).
Definition ValueContainers.h:127
std::wstring ContainedType
Definition ValueContainers.h:129
Container for Binary.
Definition ValueContainers.h:256
Binary ContainedType
Definition ValueContainers.h:258