Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ValueContainers.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2006-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_VALUE_CONTAINERS_H__
26 #define __DOTS_VALUE_CONTAINERS_H__
27 
29 #include <vector>
30 
37 #include <typeinfo>
38 
39 namespace Safir
40 {
41 namespace Dob
42 {
43 namespace Typesystem
44 {
59  template <class T>
61  {
62  public:
63  typedef T ContainedType;
64 
70  ValueContainer():ContainerBase(),m_bIsNull(true), m_Value() {}
71 
79  void SetVal(const T value) {m_Value = value; m_bIsNull = false; m_bIsChanged = true;}
80 
87  T GetVal() const {if (m_bIsNull) throw NullException(L"value is null",__WFILE__,__LINE__); return m_Value;}
88 
89  //implementation of pure virtual in ContainerBase.
90  virtual bool IsNull() const {return m_bIsNull;}
91 
92  //implementation of pure virtual in ContainerBase.
93  virtual void SetNull()
94  {
95  m_bIsNull = true;
96  m_bIsChanged = true;
97  }
98 
99  //implementation of pure virtual in ContainerBase.
100  virtual void Copy(const ContainerBase & that)
101  {
102  if (this != &that)
103  {
104  if (typeid(*this) != typeid(that))
105  {
106  throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
107  }
108  *this = static_cast<const ValueContainer<T> &>(that);
109  }
110  }
111 
112  private:
115  friend class BlobOperations;
116 
117  bool m_bIsNull;
118  T m_Value;
119  };
120 
129  {
130  public:
131  typedef std::wstring ContainedType;
132 
138  StringContainer():ContainerBase(),m_bIsNull(true), m_Value(),m_CachedUtf8String() {}
139 
147  void SetVal(const std::wstring & value) {m_Value = value; m_CachedUtf8String.clear(); m_bIsNull = false; m_bIsChanged = true;}
148 
155  const std::wstring & GetVal() const {if (m_bIsNull) throw NullException(L"value is null",__WFILE__,__LINE__); return m_Value;}
156 
157  //implementation of pure virtual in ContainerBase.
158  virtual bool IsNull() const {return m_bIsNull;}
159 
160  //implementation of pure virtual in ContainerBase.
161  virtual void SetNull()
162  {
163  m_bIsNull = true;
164  m_bIsChanged = true;
165  m_CachedUtf8String.clear();
166  }
167 
168  //implementation of pure virtual in ContainerBase.
169  virtual void Copy(const ContainerBase & that)
170  {
171  if (this != &that)
172  {
173  if (typeid(*this) != typeid(that))
174  {
175  throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
176  }
177  *this = static_cast<const StringContainer &>(that);
178  }
179  }
180 
200  {
201  if (IsNull())
202  {
203  return 0;
204  }
205 
206  if (m_Value.empty())
207  {
208  return 1;
209  }
210 
211  if (m_CachedUtf8String.empty())
212  {
213  m_CachedUtf8String = Utilities::ToUtf8(m_Value);
214  }
215 
216  return static_cast<Int32>(m_CachedUtf8String.length() + 1);
217  }
218 
228  const std::string & Utf8String() const
229  {
230  if (IsNull())
231  {
232  throw NullException(L"The string is null, cannot convert!",__WFILE__,__LINE__);
233  }
234  if (!m_Value.empty() && m_CachedUtf8String.empty())
235  {
236  m_CachedUtf8String = Utilities::ToUtf8(m_Value);
237  }
238  return m_CachedUtf8String;
239  }
240 
243  private:
246  friend class BlobOperations;
247 
248  bool m_bIsNull;
249  std::wstring m_Value;
250  mutable std::string m_CachedUtf8String;
251  };
252 
261  {
262  public:
269  BinaryContainer():ContainerBase(),m_bIsNull(true), m_Value() {}
270 
277  const Binary& GetVal() const {if (m_bIsNull) throw NullException(L"value is null",__WFILE__,__LINE__); return m_Value;}
278 
286  void SetVal(const Binary & value) {m_Value = value; m_bIsNull = false; m_bIsChanged = true;}
287 
288 
289  //implementation of pure virtual in ContainerBase.
290  virtual bool IsNull() const {return m_bIsNull;}
291 
292  //implementation of pure virtual in ContainerBase.
293  virtual void SetNull()
294  {
295  m_bIsNull = true;
296  m_bIsChanged = true;
297  }
298 
299  //implementation of pure virtual in ContainerBase.
300  virtual void Copy(const ContainerBase & that)
301  {
302  if (this != &that)
303  {
304  if (typeid(*this) != typeid(that))
305  {
306  throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
307  }
308  *this = static_cast<const BinaryContainer &>(that);
309  }
310  }
311 
312  private:
315  friend class BlobOperations;
316 
317  bool m_bIsNull;
318  Binary m_Value;
319  };
320 
328 
331 
334 
337 
340 
343 
346 
349 
352 
355 
356 
359  //--------------------------------------------------
360  // SI-types (32-bits)
361  //--------------------------------------------------
362  namespace Si32
363  {
366 
369 
372 
375 
378 
381 
384 
387 
390 
393 
396 
399 
402 
405 
408 
411 
414 
417 
420  }
421 
422  //--------------------------------------------------
423  // SI-types (64-bits)
424  //--------------------------------------------------
425  namespace Si64
426  {
429 
432 
435 
438 
441 
444 
447 
450 
453 
456 
459 
462 
465 
468 
471 
474 
477 
480 
483  }
484 
485 
486 }
487 }
488 }
489 #endif
490 
ValueContainer< Int32 > Int32Container
A container containing 32 bit integer values.
Definition: ValueContainers.h:330
ValueContainer< SquareMeter > SquareMeterContainer
A container containing 64 bit SquareMeter values.
Definition: ValueContainers.h:473
BinaryContainer()
Default constructor.
Definition: ValueContainers.h:269
ValueContainer< CubicMeter > CubicMeterContainer
A container containing 32 bit CubicMeter values.
Definition: ValueContainers.h:368
ValueContainer< Steradian > SteradianContainer
A container containing 64 bit Steradian values.
Definition: ValueContainers.h:476
Container for base types.
Definition: ValueContainers.h:60
void SetVal(const Binary &value)
Set the value of the container.
Definition: ValueContainers.h:286
virtual void Copy(const ContainerBase &that)
Virtual assignment.
Definition: ValueContainers.h:300
Operations on blobs.
Definition: BlobOperations.h:53
ValueContainer< EntityId > EntityIdContainer
A container containing EntityId values.
Definition: ValueContainers.h:348
ValueContainer< Joule > JouleContainer
A container containing 64 bit Joule values.
Definition: ValueContainers.h:437
virtual void SetNull()
Set the container to null.
Definition: ValueContainers.h:293
virtual void Copy(const ContainerBase &that)
Virtual assignment.
Definition: ValueContainers.h:169
ValueContainer< MeterPerSecondSquared > MeterPerSecondSquaredContainer
A container containing 32 bit MeterPerSecondSquared values.
Definition: ValueContainers.h:389
ValueContainer()
Default constructor.
Definition: ValueContainers.h:70
ValueContainer< Steradian > SteradianContainer
A container containing 32 bit Steradian values.
Definition: ValueContainers.h:413
ValueContainer< Kilogram > KilogramContainer
A container containing 64 bit Kilogram values.
Definition: ValueContainers.h:443
virtual void SetNull()
Set the container to null.
Definition: ValueContainers.h:161
ValueContainer< Volt > VoltContainer
A container containing 32 bit Volt values.
Definition: ValueContainers.h:416
ValueContainer< Meter > MeterContainer
A container containing 64 bit Meter values.
Definition: ValueContainers.h:446
Binary ContainedType
Definition: ValueContainers.h:263
const Binary & GetVal() const
Get the value of the container.
Definition: ValueContainers.h:277
ValueContainer< TypeId > TypeIdContainer
A container containing TypeId values.
Definition: ValueContainers.h:342
Container for Binary.
Definition: ValueContainers.h:260
std::wstring ContainedType
Definition: ValueContainers.h:131
ValueContainer< RadianPerSecondSquared > RadianPerSecondSquaredContainer
A container containing 64 bit RadianPerSecondSquared values.
Definition: ValueContainers.h:467
ValueContainer< Float32 > Float32Container
A container containing 32 bit floating point values.
Definition: ValueContainers.h:336
Meant to be used when something goes very wrong.
Definition: Exceptions.h:360
const std::string & Utf8String() const
Convert the string to a UTF8 encoded std::string.
Definition: ValueContainers.h:228
ValueContainer< Newton > NewtonContainer
A container containing 32 bit Newton values.
Definition: ValueContainers.h:392
ValueContainer< InstanceId > InstanceIdContainer
A container containing InstanceId values.
Definition: ValueContainers.h:345
ValueContainer< RadianPerSecondSquared > RadianPerSecondSquaredContainer
A container containing 32 bit RadianPerSecondSquared values.
Definition: ValueContainers.h:404
virtual bool IsNull() const
Is the container set to null?
Definition: ValueContainers.h:90
ValueContainer< Hertz > HertzContainer
A container containing 64 bit Hertz values.
Definition: ValueContainers.h:434
ValueContainer< Second > SecondContainer
A container containing 32 bit Second values.
Definition: ValueContainers.h:407
ValueContainer< Pascal > PascalContainer
A container containing 64 bit Pascal values.
Definition: ValueContainers.h:458
Int32 Utf8StringLength() const
Calculate the length needed for this string in UTF8 encoding.
Definition: ValueContainers.h:199
ValueContainer< ChannelId > ChannelIdContainer
A container containing ChannelId values.
Definition: ValueContainers.h:351
void SetVal(const std::wstring &value)
Set the value of the container.
Definition: ValueContainers.h:147
ValueContainer< Hertz > HertzContainer
A container containing 32 bit Hertz values.
Definition: ValueContainers.h:371
ValueContainer< MeterPerSecond > MeterPerSecondContainer
A container containing 32 bit MeterPerSecond values.
Definition: ValueContainers.h:386
ValueContainer< Watt > WattContainer
A container containing 64 bit Watt values.
Definition: ValueContainers.h:482
T GetVal() const
Get the value of the container.
Definition: ValueContainers.h:87
Container for strings (std::wstring).
Definition: ValueContainers.h:128
void SetVal(const T value)
Set the value of the container.
Definition: ValueContainers.h:79
#define __WFILE__
Definition: Exceptions.h:31
ValueContainer< Float64 > Float64Container
A container containing 64 bit floating point values.
Definition: ValueContainers.h:339
ValueContainer< bool > BooleanContainer
A container containing boolean values.
Definition: ValueContainers.h:327
ValueContainer< Volt > VoltContainer
A container containing 64 bit Volt values.
Definition: ValueContainers.h:479
ValueContainer< Second > SecondContainer
A container containing 64 bit Second values.
Definition: ValueContainers.h:470
virtual void SetNull()
Set the container to null.
Definition: ValueContainers.h:93
ValueContainer< Kelvin > KelvinContainer
A container containing 64 bit Kelvin values.
Definition: ValueContainers.h:440
ValueContainer< Ampere > AmpereContainer
A container containing 32 bit Ampere values.
Definition: ValueContainers.h:365
ValueContainer< Newton > NewtonContainer
A container containing 64 bit Newton values.
Definition: ValueContainers.h:455
ValueContainer< CubicMeter > CubicMeterContainer
A container containing 64 bit CubicMeter values.
Definition: ValueContainers.h:431
T ContainedType
Definition: ValueContainers.h:63
virtual bool IsNull() const
Is the container set to null?
Definition: ValueContainers.h:290
Base class for all Containers.
Definition: ContainerBase.h:41
ValueContainer< Watt > WattContainer
A container containing 32 bit Watt values.
Definition: ValueContainers.h:419
ValueContainer< SquareMeter > SquareMeterContainer
A container containing 32 bit SquareMeter values.
Definition: ValueContainers.h:410
ValueContainer< HandlerId > HandlerIdContainer
A container containing HandlerId values.
Definition: ValueContainers.h:354
Thrown when an application attempts to get the value of a member that is null.
Definition: Exceptions.h:394
const std::wstring & GetVal() const
Get the value of the container.
Definition: ValueContainers.h:155
ValueContainer< Kelvin > KelvinContainer
A container containing 32 bit Kelvin values.
Definition: ValueContainers.h:377
ValueContainer< Int64 > Int64Container
A container containing 64 bit integer values.
Definition: ValueContainers.h:333
StringContainer()
Default constructor.
Definition: ValueContainers.h:138
ValueContainer< MeterPerSecond > MeterPerSecondContainer
A container containing 64 bit MeterPerSecond values.
Definition: ValueContainers.h:449
ValueContainer< RadianPerSecond > RadianPerSecondContainer
A container containing 32 bit RadianPerSecond values.
Definition: ValueContainers.h:401
bool m_bIsChanged
The variable containing the change flag.
Definition: ContainerBase.h:123
ValueContainer< Ampere > AmpereContainer
A container containing 64 bit Ampere values.
Definition: ValueContainers.h:428
ValueContainer< MeterPerSecondSquared > MeterPerSecondSquaredContainer
A container containing 64 bit MeterPerSecondSquared values.
Definition: ValueContainers.h:452
ValueContainer< Meter > MeterContainer
A container containing 32 bit Meter values.
Definition: ValueContainers.h:383
ValueContainer< Kilogram > KilogramContainer
A container containing 32 bit Kilogram values.
Definition: ValueContainers.h:380
virtual void Copy(const ContainerBase &that)
Virtual assignment.
Definition: ValueContainers.h:100
ValueContainer< Joule > JouleContainer
A container containing 32 bit Joule values.
Definition: ValueContainers.h:374
DotsC_Int32 Int32
32 bit integer type.
Definition: Defs.h:67
virtual bool IsNull() const
Is the container set to null?
Definition: ValueContainers.h:158
ValueContainer< Radian > RadianContainer
A container containing 64 bit Radian values.
Definition: ValueContainers.h:461
ValueContainer< Pascal > PascalContainer
A container containing 32 bit Pascal values.
Definition: ValueContainers.h:395
DOTS_CPP_API const std::string ToUtf8(const std::wstring &wstr)
Convert a std::wstring to UTF8-encoded std::string.
ValueContainer< RadianPerSecond > RadianPerSecondContainer
A container containing 64 bit RadianPerSecond values.
Definition: ValueContainers.h:464
ValueContainer< Radian > RadianContainer
A container containing 32 bit Radian values.
Definition: ValueContainers.h:398
std::vector< char > Binary
A type to contain binary data.
Definition: Defs.h:294