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 bool HasVal() const {return m_container.HasVal();}
66 void SetNull() {m_container.SetNull();}
67 bool IsChanged() const {return m_container.IsChanged();}
68 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
69
70
71 void SetVal(const ContainedType value) {m_container.SetVal(value);}
72
73 const ContainedType GetVal() const {return m_container.GetVal();}
74
75 const ContainedType GetValOrDefault(const ContainedType defaultVal) const {return m_container.GetValOrDefault(defaultVal);}
76
77 void SetOrdinal(const EnumerationValue value){m_container.SetOrdinal(value);}
78 EnumerationValue GetOrdinal() const {return m_container.GetOrdinal();}
79
80 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
81
83 {
84 ContainedType val = GetVal();
85 ++val;
86 SetVal(val);
87 return *this;
88 }
89
90 //Does not return anything since I'm not sure what it should return.
91 void operator++ (int) // postfix ++
92 {
93 ++(*this);
94 }
95
97 {
98 ContainedType val = GetVal();
99 --val;
100 SetVal(val);
101 return *this;
102 }
103
104 //Does not return anything since I'm not sure what it should return.
105 void operator-- (int) // postfix --
106 {
107 --(*this);
108 }
109
110
112 {
113 SetVal(GetVal() + val);
114 return *this;
115 }
116
118 {
119 SetVal(GetVal() - val);
120 return *this;
121 }
122
124 {
125 SetVal(GetVal() * val);
126 return *this;
127 }
128
130 {
131 SetVal(GetVal() / val);
132 return *this;
133 }
134
135 const T& GetContainer() const {return m_container;}
136 T& GetContainer() {return m_container;}
137 private:
138 T& m_container;
139 };
140
141 static inline bool operator==(const ContainerProxy<ChannelIdContainer>& first, const ChannelId& second)
142 {return second == first.GetVal();}
143 static inline bool operator!=(const ContainerProxy<ChannelIdContainer>& first, const ChannelId& second)
144 {return second != first.GetVal();}
145
146 static inline bool operator==(const ContainerProxy<HandlerIdContainer>& first, const HandlerId& second)
147 {return second == first.GetVal();}
148 static inline bool operator!=(const ContainerProxy<HandlerIdContainer>& first, const HandlerId& second)
149 {return second != first.GetVal();}
150
151 static inline bool operator==(const ContainerProxy<InstanceIdContainer>& first, const InstanceId& second)
152 {return second == first.GetVal();}
153 static inline bool operator!=(const ContainerProxy<InstanceIdContainer>& first, const InstanceId& second)
154 {return second != first.GetVal();}
155
156 static inline bool operator==(const ContainerProxy<EntityIdContainer>& first, const EntityId& second)
157 {return second == first.GetVal();}
158 static inline bool operator!=(const ContainerProxy<EntityIdContainer>& first, const EntityId& second)
159 {return second != first.GetVal();}
160
161 template <>
163 {
164 public:
166
167 explicit ContainerProxy(StringContainer& container):m_container(container){}
168
170 {
171 if (other.IsNull())
172 {
173 m_container.SetNull();
174 }
175 else
176 {
177 m_container.SetVal(other.GetVal());
178 }
179 return *this;
180 }
181
182 ContainerProxy& operator=(const ContainedType& other) {m_container.SetVal(other);return *this;}
183
184 operator const ContainedType& () const {return m_container.GetVal();}
185
186 bool IsNull() const {return m_container.IsNull();}
187 bool HasVal() const {return m_container.HasVal();}
188 void SetNull() {m_container.SetNull();}
189 bool IsChanged() const {return m_container.IsChanged();}
190 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
191
192
193 void SetVal(const ContainedType& value) {m_container.SetVal(value);}
194
195 const ContainedType& GetVal() const {return m_container.GetVal();}
196 const ContainedType GetValOrDefault(const ContainedType& defaultVal) const {return m_container.GetValOrDefault(defaultVal);}
197
198 Int32 Utf8StringLength() const {return m_container.Utf8StringLength();}
199 const std::string & Utf8String() const {return m_container.Utf8String();}
200
201 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
202
204 {
205 SetVal(GetVal() + val);
206 return *this;
207 }
208
209 bool operator== (const ContainedType& val) const
210 {
211 return m_container.GetVal() == val;
212 }
213
214 bool operator!= (const ContainedType& val) const
215 {
216 return m_container.GetVal() != val;
217 }
218
219 const StringContainer& GetContainer() const {return m_container;}
220 StringContainer& GetContainer() {return m_container;}
221 private:
222 StringContainer& m_container;
223 };
224
225 static inline bool operator==(const std::wstring& first, const ContainerProxy<StringContainer>& second)
226 {return second.GetVal() == first;}
227 static inline bool operator!=(const std::wstring& first, const ContainerProxy<StringContainer>& second)
228 {return second.GetVal() != first;}
229
230 template <>
232 {
233 public:
235
236 explicit ContainerProxy(BinaryContainer& container):m_container(container){}
237
239 {
240 if (other.IsNull())
241 {
242 m_container.SetNull();
243 }
244 else
245 {
246 m_container.SetVal(other.GetVal());
247 }
248 return *this;
249 }
250
251 ContainerProxy& operator=(const ContainedType& other) {m_container.SetVal(other);return *this;}
252
253 operator const ContainedType& () const {return m_container.GetVal();}
254
255 bool IsNull() const {return m_container.IsNull();}
256 bool HasVal() const {return m_container.HasVal();}
257 void SetNull() {m_container.SetNull();}
258 bool IsChanged() const {return m_container.IsChanged();}
259 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
260
261
262 void SetVal(const ContainedType& value) {m_container.SetVal(value);}
263
264 const ContainedType& GetVal() const {return m_container.GetVal();}
265
266 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
267
268 bool operator== (const ContainedType& val) const
269 {
270 return m_container.GetVal() == val;
271 }
272
273 bool operator!= (const ContainedType& val) const
274 {
275 return m_container.GetVal() != val;
276 }
277
278 const BinaryContainer& GetContainer() const {return m_container;}
279 BinaryContainer& GetContainer() {return m_container;}
280 private:
281 BinaryContainer& m_container;
282 };
283
284 static inline bool operator==(const Binary& first, const ContainerProxy<BinaryContainer>& second)
285 {return second.GetVal() == first;}
286 static inline bool operator!=(const Binary& first, const ContainerProxy<BinaryContainer>& second)
287 {return second.GetVal() != first;}
288
289 template <class U>
291 {
292 public:
294
295 explicit ContainerProxy(ObjectContainerImpl<U>& container):m_container(container){}
296
298 {
299 if (other.IsNull())
300 {
301 m_container.SetNull();
302 }
303 else
304 {
305 m_container.SetPtr(other);
306 }
307 return *this;
308 }
309
310 ContainerProxy& operator=(const ContainedType& other) {m_container.SetPtr(other);return *this;}
311
312 operator const ContainedType () const {return m_container.GetPtr();}
313
314 U* operator->() const
315 { return m_container.operator->(); }
316
317 bool IsNull() const {return m_container.IsNull();}
318 bool HasVal() const {return m_container.HasVal();}
319 void SetNull() {m_container.SetNull();}
320 bool IsChanged() const {return m_container.IsChanged();}
321 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
322
323 void SetChangedHere(const bool changed) {m_container.SetChangedHere(changed);}
324 bool IsChangedHere() const {return m_container.IsChangedHere();}
325
326 void SetPtr(const ContainedType& ptr) {m_container.SetPtr(ptr);}
327 void SetPtr(const ObjectPtr& ptr) {m_container.SetPtr(ptr);}
328
329 const ContainedType& GetPtr() const {return m_container.GetPtr();}
330 const ContainedType GetPtrOrNull() const {return m_container.GetPtrOrNull();}
331
332 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
333
334 const ObjectContainerImpl<U>& GetContainer() const {return m_container;}
335 ObjectContainerImpl<U>& GetContainer() {return m_container;}
336 private:
337 ObjectContainerImpl<U>& m_container;
338 };
339
340
341 template <>
343 {
344 public:
346
347 explicit ContainerProxy(ObjectContainerImpl<Object>& container):m_container(container){}
348
350 {
351 if (other.IsNull())
352 {
353 m_container.SetNull();
354 }
355 else
356 {
357 m_container.SetPtr(other);
358 }
359 return *this;
360 }
361
362 ContainerProxy& operator=(const ContainedType& other) {m_container.SetPtr(other);return *this;}
363
364 operator const ContainedType () const {return m_container.GetPtr();}
365
367 { return m_container.operator->(); }
368
369 bool IsNull() const {return m_container.IsNull();}
370 bool HasVal() const {return m_container.HasVal();}
371 void SetNull() {m_container.SetNull();}
372 bool IsChanged() const {return m_container.IsChanged();}
373 void SetChanged(const bool changed) {m_container.SetChanged(changed);}
374
375 void SetChangedHere(const bool changed) {m_container.SetChangedHere(changed);}
376 bool IsChangedHere() const {return m_container.IsChangedHere();}
377
378 void SetPtr(const ObjectPtr& ptr) {m_container.SetPtr(ptr);}
379
380 const ContainedType& GetPtr() const {return m_container.GetPtr();}
381 const ContainedType GetPtrOrNull() const {return m_container.GetPtrOrNull();}
382
383 void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
384
385 const ObjectContainerImpl<Object>& GetContainer() const {return m_container;}
387 private:
388 ObjectContainerImpl<Object>& m_container;
389 };
390
391}
392}
393}
394
395#endif
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
This namespace contains all functionality of the DOB (Components DOSE and DOTS).
Definition Connection.h:38
This namespace contains the DOB Typesystem functionality and definitions.
Definition ArrayContainer.h:37
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:143
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:141
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:82
void SetChanged(const bool changed)
Definition ContainerProxies.h:68
ContainerProxy & operator--()
Definition ContainerProxies.h:96
bool IsChanged() const
Definition ContainerProxies.h:67
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:47
EnumerationValue GetOrdinal() const
Definition ContainerProxies.h:78
const T & GetContainer() const
Definition ContainerProxies.h:135
void SetOrdinal(const EnumerationValue value)
Definition ContainerProxies.h:77
const ContainedType GetVal() const
Definition ContainerProxies.h:73
ContainerProxy & operator/=(const ContainedType &val)
Definition ContainerProxies.h:129
ContainerProxy & operator*=(const ContainedType &val)
Definition ContainerProxies.h:123
void SetVal(const ContainedType value)
Definition ContainerProxies.h:71
ContainerProxy & operator=(const ContainedType other)
Definition ContainerProxies.h:60
ContainerProxy & operator-=(const ContainedType &val)
Definition ContainerProxies.h:117
ContainerProxy & operator+=(const ContainedType &val)
Definition ContainerProxies.h:111
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:80
void SetNull()
Definition ContainerProxies.h:66
T::ContainedType ContainedType
Definition ContainerProxies.h:41
T & GetContainer()
Definition ContainerProxies.h:136
ContainerProxy(T &container)
Definition ContainerProxies.h:43
ContainerProxy(const ContainerProxy &other)=default
const ContainedType GetValOrDefault(const ContainedType defaultVal) const
Definition ContainerProxies.h:75
bool HasVal() const
Definition ContainerProxies.h:65
const ContainedType & GetVal() const
Definition ContainerProxies.h:195
void SetChanged(const bool changed)
Definition ContainerProxies.h:190
ContainerProxy(StringContainer &container)
Definition ContainerProxies.h:167
bool HasVal() const
Definition ContainerProxies.h:187
const StringContainer & GetContainer() const
Definition ContainerProxies.h:219
void SetNull()
Definition ContainerProxies.h:188
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:201
bool IsChanged() const
Definition ContainerProxies.h:189
const std::string & Utf8String() const
Definition ContainerProxies.h:199
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:182
const ContainedType GetValOrDefault(const ContainedType &defaultVal) const
Definition ContainerProxies.h:196
StringContainer::ContainedType ContainedType
Definition ContainerProxies.h:165
StringContainer & GetContainer()
Definition ContainerProxies.h:220
void SetVal(const ContainedType &value)
Definition ContainerProxies.h:193
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:169
bool IsNull() const
Definition ContainerProxies.h:186
Int32 Utf8StringLength() const
Definition ContainerProxies.h:198
void SetVal(const ContainedType &value)
Definition ContainerProxies.h:262
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:238
bool IsNull() const
Definition ContainerProxies.h:255
void SetNull()
Definition ContainerProxies.h:257
const BinaryContainer & GetContainer() const
Definition ContainerProxies.h:278
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:266
void SetChanged(const bool changed)
Definition ContainerProxies.h:259
bool IsChanged() const
Definition ContainerProxies.h:258
BinaryContainer::ContainedType ContainedType
Definition ContainerProxies.h:234
BinaryContainer & GetContainer()
Definition ContainerProxies.h:279
bool HasVal() const
Definition ContainerProxies.h:256
const ContainedType & GetVal() const
Definition ContainerProxies.h:264
ContainerProxy(BinaryContainer &container)
Definition ContainerProxies.h:236
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:251
void SetChangedHere(const bool changed)
Definition ContainerProxies.h:323
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:297
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:310
bool IsChanged() const
Definition ContainerProxies.h:320
bool IsChangedHere() const
Definition ContainerProxies.h:324
void SetPtr(const ContainedType &ptr)
Definition ContainerProxies.h:326
const ContainedType & GetPtr() const
Definition ContainerProxies.h:329
const ContainedType GetPtrOrNull() const
Definition ContainerProxies.h:330
ObjectContainerImpl< U > & GetContainer()
Definition ContainerProxies.h:335
bool HasVal() const
Definition ContainerProxies.h:318
ContainerProxy(ObjectContainerImpl< U > &container)
Definition ContainerProxies.h:295
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:332
const ObjectContainerImpl< U > & GetContainer() const
Definition ContainerProxies.h:334
void SetPtr(const ObjectPtr &ptr)
Definition ContainerProxies.h:327
ObjectContainerImpl< U >::T_Ptr ContainedType
Definition ContainerProxies.h:293
bool IsNull() const
Definition ContainerProxies.h:317
U * operator->() const
Definition ContainerProxies.h:314
void SetChanged(const bool changed)
Definition ContainerProxies.h:321
ContainerProxy(ObjectContainerImpl< Object > &container)
Definition ContainerProxies.h:347
const ObjectContainerImpl< Object > & GetContainer() const
Definition ContainerProxies.h:385
void SetChanged(const bool changed)
Definition ContainerProxies.h:373
const ContainedType & GetPtr() const
Definition ContainerProxies.h:380
Object * operator->() const
Definition ContainerProxies.h:366
ObjectContainerImpl< Object > & GetContainer()
Definition ContainerProxies.h:386
bool IsChangedHere() const
Definition ContainerProxies.h:376
ContainerProxy & operator=(const ContainedType &other)
Definition ContainerProxies.h:362
void SetChangedHere(const bool changed)
Definition ContainerProxies.h:375
const ContainedType GetPtrOrNull() const
Definition ContainerProxies.h:381
ContainerProxy & operator=(const ContainerProxy &other)
Definition ContainerProxies.h:349
bool IsChanged() const
Definition ContainerProxies.h:372
ObjectContainerImpl< Object >::T_Ptr ContainedType
Definition ContainerProxies.h:345
void SetPtr(const ObjectPtr &ptr)
Definition ContainerProxies.h:378
void Copy(const ContainerProxy &that)
Definition ContainerProxies.h:383
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:138
std::wstring ContainedType
Definition ValueContainers.h:140
Container for Binary.
Definition ValueContainers.h:278
Binary ContainedType
Definition ValueContainers.h:280