Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ContainerProxies.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2008-2013 (http://safir.sourceforge.net)
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 
31 namespace Safir
32 {
33 namespace Dob
34 {
35 namespace 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 
46  {
47  if (other.IsNull())
48  {
49  m_container.SetNull();
50  }
51  else
52  {
53  m_container.SetVal(other.GetVal());
54  }
55  return *this;
56  }
57 
58  ContainerProxy& operator=(const ContainedType other) {m_container.SetVal(other);return *this;}
59 
60  operator const ContainedType() const {return m_container.GetVal();}
61 
62  bool IsNull() const {return m_container.IsNull();}
63  void SetNull() {m_container.SetNull();}
64  bool IsChanged() const {return m_container.IsChanged();}
65  void SetChanged(const bool changed) {m_container.SetChanged(changed);}
66 
67 
68  void SetVal(const ContainedType value) {m_container.SetVal(value);}
69 
70  const ContainedType GetVal() const {return m_container.GetVal();}
71 
72  void SetOrdinal(const EnumerationValue value){m_container.SetOrdinal(value);}
73  EnumerationValue GetOrdinal() const {return m_container.GetOrdinal();}
74 
75  void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
76 
77  ContainerProxy& operator++ () // prefix ++
78  {
79  ContainedType val = GetVal();
80  ++val;
81  SetVal(val);
82  return *this;
83  }
84 
85  //Does not return anything since I'm not sure what it should return.
86  void operator++ (int) // postfix ++
87  {
88  ++(*this);
89  }
90 
91  ContainerProxy& operator-- () // prefix --
92  {
93  ContainedType val = GetVal();
94  --val;
95  SetVal(val);
96  return *this;
97  }
98 
99  //Does not return anything since I'm not sure what it should return.
100  void operator-- (int) // postfix --
101  {
102  --(*this);
103  }
104 
105 
107  {
108  SetVal(GetVal() + val);
109  return *this;
110  }
111 
113  {
114  SetVal(GetVal() - val);
115  return *this;
116  }
117 
119  {
120  SetVal(GetVal() * val);
121  return *this;
122  }
123 
125  {
126  SetVal(GetVal() / val);
127  return *this;
128  }
129 
130  const T& GetContainer() const {return m_container;}
131  T& GetContainer() {return m_container;}
132  private:
133  T& m_container;
134  };
135 
136  static inline bool operator==(const ContainerProxy<ChannelIdContainer>& first, const ChannelId& second)
137  {return second == first;}
138  static inline bool operator!=(const ContainerProxy<ChannelIdContainer>& first, const ChannelId& second)
139  {return second != first;}
140 
141  static inline bool operator==(const ContainerProxy<HandlerIdContainer>& first, const HandlerId& second)
142  {return second == first;}
143  static inline bool operator!=(const ContainerProxy<HandlerIdContainer>& first, const HandlerId& second)
144  {return second != first;}
145 
146  static inline bool operator==(const ContainerProxy<InstanceIdContainer>& first, const InstanceId& second)
147  {return second == first;}
148  static inline bool operator!=(const ContainerProxy<InstanceIdContainer>& first, const InstanceId& second)
149  {return second != first;}
150 
151  static inline bool operator==(const ContainerProxy<EntityIdContainer>& first, const EntityId& second)
152  {return second == first;}
153  static inline bool operator!=(const ContainerProxy<EntityIdContainer>& first, const EntityId& second)
154  {return second != first;}
155 
156 
157  template <>
159  {
160  public:
162 
163  explicit ContainerProxy(StringContainer& container):m_container(container){}
164 
166  {
167  if (other.IsNull())
168  {
169  m_container.SetNull();
170  }
171  else
172  {
173  m_container.SetVal(other.GetVal());
174  }
175  return *this;
176  }
177 
178  ContainerProxy& operator=(const ContainedType& other) {m_container.SetVal(other);return *this;}
179 
180  operator const ContainedType& () const {return m_container.GetVal();}
181 
182  bool IsNull() const {return m_container.IsNull();}
183  void SetNull() {m_container.SetNull();}
184  bool IsChanged() const {return m_container.IsChanged();}
185  void SetChanged(const bool changed) {m_container.SetChanged(changed);}
186 
187 
188  void SetVal(const ContainedType& value) {m_container.SetVal(value);}
189 
190  const ContainedType& GetVal() const {return m_container.GetVal();}
191 
192  Int32 Utf8StringLength() const {return m_container.Utf8StringLength();}
193  const std::string & Utf8String() const {return m_container.Utf8String();}
194 
195  void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
196 
198  {
199  SetVal(GetVal() + val);
200  return *this;
201  }
202 
203  bool operator== (const ContainedType& val) const
204  {
205  return m_container.GetVal() == val;
206  }
207 
208  bool operator!= (const ContainedType& val) const
209  {
210  return m_container.GetVal() != val;
211  }
212 
213  const StringContainer& GetContainer() const {return m_container;}
214  StringContainer& GetContainer() {return m_container;}
215  private:
216  StringContainer& m_container;
217  };
218 
219 
220  static inline bool operator==(const std::wstring& first, const ContainerProxy<StringContainer>& second)
221  {return second == first;}
222  static inline bool operator!=(const std::wstring& first, const ContainerProxy<StringContainer>& second)
223  {return second != first;}
224 
225 
226  template <>
228  {
229  public:
231 
232  explicit ContainerProxy(BinaryContainer& container):m_container(container){}
233 
235  {
236  if (other.IsNull())
237  {
238  m_container.SetNull();
239  }
240  else
241  {
242  m_container.SetVal(other.GetVal());
243  }
244  return *this;
245  }
246 
247  ContainerProxy& operator=(const ContainedType& other) {m_container.SetVal(other);return *this;}
248 
249  operator const ContainedType& () const {return m_container.GetVal();}
250 
251  bool IsNull() const {return m_container.IsNull();}
252  void SetNull() {m_container.SetNull();}
253  bool IsChanged() const {return m_container.IsChanged();}
254  void SetChanged(const bool changed) {m_container.SetChanged(changed);}
255 
256 
257  void SetVal(const ContainedType& value) {m_container.SetVal(value);}
258 
259  const ContainedType& GetVal() const {return m_container.GetVal();}
260  void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
261 
262  bool operator== (const ContainedType& val) const
263  {
264  return m_container.GetVal() == val;
265  }
266 
267  bool operator!= (const ContainedType& val) const
268  {
269  return m_container.GetVal() != val;
270  }
271 
272  const BinaryContainer& GetContainer() const {return m_container;}
273  BinaryContainer& GetContainer() {return m_container;}
274  private:
275  BinaryContainer& m_container;
276  };
277 
278  static inline bool operator==(const Binary& first, const ContainerProxy<BinaryContainer>& second)
279  {return second == first;}
280  static inline bool operator!=(const Binary& first, const ContainerProxy<BinaryContainer>& second)
281  {return second != first;}
282 
283 
284  template <class U>
286  {
287  public:
289 
290  explicit ContainerProxy(ObjectContainerImpl<U>& container):m_container(container){}
291 
293  {
294  if (other.IsNull())
295  {
296  m_container.SetNull();
297  }
298  else
299  {
300  m_container.SetPtr(other);
301  }
302  return *this;
303  }
304 
305  ContainerProxy& operator=(const ContainedType& other) {m_container.SetPtr(other);return *this;}
306 
307  operator const ContainedType () const {return m_container.GetPtr();}
308 
309  U* const operator->() const
310  { return m_container.operator->(); }
311 
312  bool IsNull() const {return m_container.IsNull();}
313  void SetNull() {m_container.SetNull();}
314  bool IsChanged() const {return m_container.IsChanged();}
315  void SetChanged(const bool changed) {m_container.SetChanged(changed);}
316 
317  void SetChangedHere(const bool changed) {m_container.SetChangedHere(changed);}
318  bool IsChangedHere() const {return m_container.IsChangedHere();}
319 
320  void SetPtr(const ContainedType& ptr) {m_container.SetPtr(ptr);}
321  void SetPtr(const ObjectPtr& ptr) {m_container.SetPtr(ptr);}
322 
323  const ContainedType& GetPtr() const {return m_container.GetPtr();}
324  void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
325 
326  const ObjectContainerImpl<U>& GetContainer() const {return m_container;}
327  ObjectContainerImpl<U>& GetContainer() {return m_container;}
328  private:
329  ObjectContainerImpl<U>& m_container;
330  };
331 
332 
333  template <>
335  {
336  public:
338 
339  explicit ContainerProxy(ObjectContainerImpl<Object>& container):m_container(container){}
340 
342  {
343  if (other.IsNull())
344  {
345  m_container.SetNull();
346  }
347  else
348  {
349  m_container.SetPtr(other);
350  }
351  return *this;
352  }
353 
354  ContainerProxy& operator=(const ContainedType& other) {m_container.SetPtr(other);return *this;}
355 
356  operator const ContainedType () const {return m_container.GetPtr();}
357 
358  Object* const operator->() const
359  { return m_container.operator->(); }
360 
361  bool IsNull() const {return m_container.IsNull();}
362  void SetNull() {m_container.SetNull();}
363  bool IsChanged() const {return m_container.IsChanged();}
364  void SetChanged(const bool changed) {m_container.SetChanged(changed);}
365 
366  void SetChangedHere(const bool changed) {m_container.SetChangedHere(changed);}
367  bool IsChangedHere() const {return m_container.IsChangedHere();}
368 
369  void SetPtr(const ObjectPtr& ptr) {m_container.SetPtr(ptr);}
370 
371  const ContainedType& GetPtr() const {return m_container.GetPtr();}
372 
373  void Copy (const ContainerProxy& that) {m_container.Copy(that.m_container);}
374 
375  const ObjectContainerImpl<Object>& GetContainer() const {return m_container;}
376  ObjectContainerImpl<Object>& GetContainer() {return m_container;}
377  private:
378  ObjectContainerImpl<Object>& m_container;
379  };
380 
381 }
382 }
383 }
384 
385 #endif
386 
ContainerProxy & operator=(const ContainerProxy &other)
Definition: ContainerProxies.h:234
bool IsNull() const
Definition: ContainerProxies.h:182
Class containing the identity of a channel.
Definition: ChannelId.h:44
static bool operator!=(const ContainerProxy< ChannelIdContainer > &first, const ChannelId &second)
Definition: ContainerProxies.h:138
void Copy(const ContainerProxy &that)
Definition: ContainerProxies.h:324
The base class for all DOB objects.
Definition: Object.h:54
EnumerationValue GetOrdinal() const
Definition: ContainerProxies.h:73
Class containing the identity of an entity.
Definition: EntityId.h:41
Object *const operator->() const
Definition: ContainerProxies.h:358
ContainerProxy & operator--()
Definition: ContainerProxies.h:91
ContainerProxy & operator=(const ContainedType &other)
Definition: ContainerProxies.h:305
Class containing the identity of a handler.
Definition: HandlerId.h:44
void SetPtr(const ContainedType &ptr)
Definition: ContainerProxies.h:320
void Copy(const ContainerProxy &that)
Definition: ContainerProxies.h:195
This is a specialization of the ObjectContainerImpl template for the case where the template argument...
Definition: ObjectContainer.h:381
BinaryContainer & GetContainer()
Definition: ContainerProxies.h:273
boost::shared_ptr< T > T_Ptr
Typedef for the contained smart pointer.
Definition: ObjectContainer.h:189
Binary ContainedType
Definition: ValueContainers.h:263
void SetChanged(const bool changed)
Definition: ContainerProxies.h:364
ContainerProxy(ObjectContainerImpl< U > &container)
Definition: ContainerProxies.h:290
void SetChangedHere(const bool changed)
Definition: ContainerProxies.h:366
const ObjectContainerImpl< Object > & GetContainer() const
Definition: ContainerProxies.h:375
StringContainer::ContainedType ContainedType
Definition: ContainerProxies.h:161
Container for Binary.
Definition: ValueContainers.h:260
std::wstring ContainedType
Definition: ValueContainers.h:131
ContainerProxy & operator*=(const ContainedType &val)
Definition: ContainerProxies.h:118
bool IsChangedHere() const
Definition: ContainerProxies.h:367
Definition: ContainerProxies.h:38
ContainerProxy(BinaryContainer &container)
Definition: ContainerProxies.h:232
const ContainedType & GetVal() const
Definition: ContainerProxies.h:259
void SetChanged(const bool changed)
Definition: ContainerProxies.h:254
Class containing the identity of an instance.
Definition: InstanceId.h:47
bool IsChanged() const
Definition: ContainerProxies.h:253
const std::string & Utf8String() const
Definition: ContainerProxies.h:193
ContainerProxy & operator=(const ContainerProxy &other)
Definition: ContainerProxies.h:45
const StringContainer & GetContainer() const
Definition: ContainerProxies.h:213
void SetPtr(const ObjectPtr &ptr)
Definition: ContainerProxies.h:321
bool IsChanged() const
Definition: ContainerProxies.h:363
bool IsChanged() const
Definition: ContainerProxies.h:314
const ContainedType & GetVal() const
Definition: ContainerProxies.h:190
bool IsNull() const
Definition: ContainerProxies.h:62
static bool operator==(const ContainerProxy< ChannelIdContainer > &first, const ChannelId &second)
Definition: ContainerProxies.h:136
ContainerProxy & operator=(const ContainedType other)
Definition: ContainerProxies.h:58
const T & GetContainer() const
Definition: ContainerProxies.h:130
void Copy(const ContainerProxy &that)
Definition: ContainerProxies.h:373
bool IsNull() const
Definition: ContainerProxies.h:361
ObjectContainerImpl< Object >::T_Ptr ContainedType
Definition: ContainerProxies.h:337
ContainerProxy & operator=(const ContainedType &other)
Definition: ContainerProxies.h:354
Template class for all containers of automatically generated DOB objects.
Definition: ObjectContainer.h:185
void SetVal(const ContainedType value)
Definition: ContainerProxies.h:68
ContainerProxy & operator=(const ContainedType &other)
Definition: ContainerProxies.h:178
Container for strings (std::wstring).
Definition: ValueContainers.h:128
void SetChanged(const bool changed)
Definition: ContainerProxies.h:315
ContainerProxy & operator=(const ContainedType &other)
Definition: ContainerProxies.h:247
void SetNull()
Definition: ContainerProxies.h:252
T::ContainedType ContainedType
Definition: ContainerProxies.h:41
Int32 Utf8StringLength() const
Definition: ContainerProxies.h:192
T & GetContainer()
Definition: ContainerProxies.h:131
const ContainedType & GetPtr() const
Definition: ContainerProxies.h:323
void Copy(const ContainerProxy &that)
Definition: ContainerProxies.h:260
boost::shared_ptr< Object > ObjectPtr
A smart pointer to an Object.
Definition: Object.h:41
const ObjectContainerImpl< U > & GetContainer() const
Definition: ContainerProxies.h:326
ContainerProxy(ObjectContainerImpl< Object > &container)
Definition: ContainerProxies.h:339
ObjectContainerImpl< Object > & GetContainer()
Definition: ContainerProxies.h:376
ObjectContainerImpl< U > & GetContainer()
Definition: ContainerProxies.h:327
const ContainedType & GetPtr() const
Definition: ContainerProxies.h:371
ContainerProxy(StringContainer &container)
Definition: ContainerProxies.h:163
void SetOrdinal(const EnumerationValue value)
Definition: ContainerProxies.h:72
ContainerProxy & operator=(const ContainerProxy &other)
Definition: ContainerProxies.h:341
bool IsChanged() const
Definition: ContainerProxies.h:184
bool IsChanged() const
Definition: ContainerProxies.h:64
ContainerProxy(T &container)
Definition: ContainerProxies.h:43
bool IsNull() const
Definition: ContainerProxies.h:251
bool IsChangedHere() const
Definition: ContainerProxies.h:318
bool IsNull() const
Definition: ContainerProxies.h:312
void SetVal(const ContainedType &value)
Definition: ContainerProxies.h:257
ContainerProxy & operator++()
Definition: ContainerProxies.h:77
ContainerProxy & operator/=(const ContainedType &val)
Definition: ContainerProxies.h:124
DotsC_EnumerationValue EnumerationValue
The ordinal value of an enumeration.
Definition: Defs.h:271
ContainerProxy & operator-=(const ContainedType &val)
Definition: ContainerProxies.h:112
void Copy(const ContainerProxy &that)
Definition: ContainerProxies.h:75
ContainerProxy & operator=(const ContainerProxy &other)
Definition: ContainerProxies.h:292
BinaryContainer::ContainedType ContainedType
Definition: ContainerProxies.h:230
void SetChanged(const bool changed)
Definition: ContainerProxies.h:185
const ContainedType GetVal() const
Definition: ContainerProxies.h:70
ContainerProxy & operator+=(const ContainedType &val)
Definition: ContainerProxies.h:106
void SetNull()
Definition: ContainerProxies.h:183
U *const operator->() const
Definition: ContainerProxies.h:309
DotsC_Int32 Int32
32 bit integer type.
Definition: Defs.h:67
ObjectContainerImpl< U >::T_Ptr ContainedType
Definition: ContainerProxies.h:288
void SetChangedHere(const bool changed)
Definition: ContainerProxies.h:317
ContainerProxy & operator=(const ContainerProxy &other)
Definition: ContainerProxies.h:165
void SetVal(const ContainedType &value)
Definition: ContainerProxies.h:188
void SetPtr(const ObjectPtr &ptr)
Definition: ContainerProxies.h:369
void SetChanged(const bool changed)
Definition: ContainerProxies.h:65
const BinaryContainer & GetContainer() const
Definition: ContainerProxies.h:272
StringContainer & GetContainer()
Definition: ContainerProxies.h:214
void SetNull()
Definition: ContainerProxies.h:63
std::vector< char > Binary
A type to contain binary data.
Definition: Defs.h:294