Safir SDK Core
Loading...
Searching...
No Matches
ValueContainers.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2006-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_VALUE_CONTAINERS_H__
26#define __DOTS_VALUE_CONTAINERS_H__
27
29#include <vector>
30
37#include <typeinfo>
38
39namespace Safir
40{
41namespace Dob
42{
43namespace Typesystem
44{
59 template <class T>
61 {
62 public:
63 typedef T ContainedType;
64
70 constexpr 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 bool IsNull() const override {return m_bIsNull;}
91
92 //implementation of pure virtual in ContainerBase.
93 void SetNull() override
94 {
95 m_bIsNull = true;
96 m_bIsChanged = true;
97 }
98
99 //implementation of pure virtual in ContainerBase.
100 void Copy(const ContainerBase & that) override
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:
113 bool m_bIsNull;
114 T m_Value;
115
117 };
118
127 {
128 public:
129 typedef std::wstring ContainedType;
130
136 StringContainer():ContainerBase(),m_bIsNull(true), m_Value(),m_CachedUtf8String() {}
137
145 void SetVal(const std::wstring & value) {m_Value = value; m_CachedUtf8String.clear(); m_bIsNull = false; m_bIsChanged = true;}
146
153 const std::wstring & GetVal() const {if (m_bIsNull) throw NullException(L"value is null",__WFILE__,__LINE__); return m_Value;}
154
155 bool IsNull() const override {return m_bIsNull;}
156
157 //implementation of pure virtual in ContainerBase.
158 void SetNull() override
159 {
160 m_bIsNull = true;
161 m_bIsChanged = true;
162 m_CachedUtf8String.clear();
163 }
164
165 //implementation of pure virtual in ContainerBase.
166 void Copy(const ContainerBase & that) override
167 {
168 if (this != &that)
169 {
170 if (typeid(*this) != typeid(that))
171 {
172 throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
173 }
174 *this = static_cast<const StringContainer &>(that);
175 }
176 }
177
197 {
198 if (IsNull())
199 {
200 return 0;
201 }
202
203 if (m_Value.empty())
204 {
205 return 1;
206 }
207
208 if (m_CachedUtf8String.empty())
209 {
210 m_CachedUtf8String = Utilities::ToUtf8(m_Value);
211 }
212
213 return static_cast<Int32>(m_CachedUtf8String.length() + 1);
214 }
215
225 const std::string & Utf8String() const
226 {
227 if (IsNull())
228 {
229 throw NullException(L"The string is null, cannot convert!",__WFILE__,__LINE__);
230 }
231 if (!m_Value.empty() && m_CachedUtf8String.empty())
232 {
233 m_CachedUtf8String = Utilities::ToUtf8(m_Value);
234 }
235 return m_CachedUtf8String;
236 }
237
240 private:
242
243 bool m_bIsNull;
244 std::wstring m_Value;
245 mutable std::string m_CachedUtf8String;
246 };
247
256 {
257 public:
264 BinaryContainer():ContainerBase(),m_bIsNull(true), m_Value() {}
265
272 const Binary& GetVal() const {if (m_bIsNull) throw NullException(L"value is null",__WFILE__,__LINE__); return m_Value;}
273
281 void SetVal(const Binary & value) {m_Value = value; m_bIsNull = false; m_bIsChanged = true;}
282
283
284 //implementation of pure virtual in ContainerBase.
285 bool IsNull() const override {return m_bIsNull;}
286
287 //implementation of pure virtual in ContainerBase.
288 void SetNull() override
289 {
290 m_bIsNull = true;
291 m_bIsChanged = true;
292 }
293
294 //implementation of pure virtual in ContainerBase.
295 void Copy(const ContainerBase & that) override
296 {
297 if (this != &that)
298 {
299 if (typeid(*this) != typeid(that))
300 {
301 throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
302 }
303 *this = static_cast<const BinaryContainer &>(that);
304 }
305 }
306
307 private:
309
310 bool m_bIsNull;
311 Binary m_Value;
312 };
313
321
324
327
330
333
336
339
342
345
348
349
352 //--------------------------------------------------
353 // SI-types (32-bits)
354 //--------------------------------------------------
355 namespace Si32
356 {
359
362
365
368
371
374
377
380
383
386
389
392
395
398
401
404
407
410
413 }
414
415 //--------------------------------------------------
416 // SI-types (64-bits)
417 //--------------------------------------------------
418 namespace Si64
419 {
422
425
428
431
434
437
440
443
446
449
452
455
458
461
464
467
470
473
476 }
477
478
479}
480}
481}
482#endif
#define __WFILE__
Definition Exceptions.h:31
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
ValueContainer< Int32 > Int32Container
A container containing 32 bit integer values.
Definition ValueContainers.h:323
ValueContainer< bool > BooleanContainer
A container containing boolean values.
Definition ValueContainers.h:320
ValueContainer< Float32 > Float32Container
A container containing 32 bit floating point values.
Definition ValueContainers.h:329
ValueContainer< EntityId > EntityIdContainer
A container containing EntityId values.
Definition ValueContainers.h:341
ValueContainer< HandlerId > HandlerIdContainer
A container containing HandlerId values.
Definition ValueContainers.h:347
ValueContainer< InstanceId > InstanceIdContainer
A container containing InstanceId values.
Definition ValueContainers.h:338
std::vector< char > Binary
A type to contain binary data.
Definition Defs.h:306
ValueContainer< ChannelId > ChannelIdContainer
A container containing ChannelId values.
Definition ValueContainers.h:344
DotsC_Int32 Int32
32 bit integer type.
Definition Defs.h:66
ValueContainer< TypeId > TypeIdContainer
A container containing TypeId values.
Definition ValueContainers.h:335
ValueContainer< Int64 > Int64Container
A container containing 64 bit integer values.
Definition ValueContainers.h:326
ValueContainer< Float64 > Float64Container
A container containing 64 bit floating point values.
Definition ValueContainers.h:332
ValueContainer< Volt > VoltContainer
A container containing 32 bit Volt values.
Definition ValueContainers.h:409
ValueContainer< Radian > RadianContainer
A container containing 32 bit Radian values.
Definition ValueContainers.h:391
ValueContainer< Kelvin > KelvinContainer
A container containing 32 bit Kelvin values.
Definition ValueContainers.h:370
ValueContainer< Newton > NewtonContainer
A container containing 32 bit Newton values.
Definition ValueContainers.h:385
ValueContainer< Pascal > PascalContainer
A container containing 32 bit Pascal values.
Definition ValueContainers.h:388
ValueContainer< Watt > WattContainer
A container containing 32 bit Watt values.
Definition ValueContainers.h:412
ValueContainer< SquareMeter > SquareMeterContainer
A container containing 32 bit SquareMeter values.
Definition ValueContainers.h:403
ValueContainer< Meter > MeterContainer
A container containing 32 bit Meter values.
Definition ValueContainers.h:376
ValueContainer< Kilogram > KilogramContainer
A container containing 32 bit Kilogram values.
Definition ValueContainers.h:373
ValueContainer< RadianPerSecondSquared > RadianPerSecondSquaredContainer
A container containing 32 bit RadianPerSecondSquared values.
Definition ValueContainers.h:397
ValueContainer< MeterPerSecond > MeterPerSecondContainer
A container containing 32 bit MeterPerSecond values.
Definition ValueContainers.h:379
ValueContainer< Ampere > AmpereContainer
A container containing 32 bit Ampere values.
Definition ValueContainers.h:358
ValueContainer< Second > SecondContainer
A container containing 32 bit Second values.
Definition ValueContainers.h:400
ValueContainer< RadianPerSecond > RadianPerSecondContainer
A container containing 32 bit RadianPerSecond values.
Definition ValueContainers.h:394
ValueContainer< Steradian > SteradianContainer
A container containing 32 bit Steradian values.
Definition ValueContainers.h:406
ValueContainer< Hertz > HertzContainer
A container containing 32 bit Hertz values.
Definition ValueContainers.h:364
ValueContainer< CubicMeter > CubicMeterContainer
A container containing 32 bit CubicMeter values.
Definition ValueContainers.h:361
ValueContainer< Joule > JouleContainer
A container containing 32 bit Joule values.
Definition ValueContainers.h:367
ValueContainer< MeterPerSecondSquared > MeterPerSecondSquaredContainer
A container containing 32 bit MeterPerSecondSquared values.
Definition ValueContainers.h:382
ValueContainer< Kelvin > KelvinContainer
A container containing 64 bit Kelvin values.
Definition ValueContainers.h:433
ValueContainer< Meter > MeterContainer
A container containing 64 bit Meter values.
Definition ValueContainers.h:439
ValueContainer< RadianPerSecondSquared > RadianPerSecondSquaredContainer
A container containing 64 bit RadianPerSecondSquared values.
Definition ValueContainers.h:460
ValueContainer< MeterPerSecond > MeterPerSecondContainer
A container containing 64 bit MeterPerSecond values.
Definition ValueContainers.h:442
ValueContainer< RadianPerSecond > RadianPerSecondContainer
A container containing 64 bit RadianPerSecond values.
Definition ValueContainers.h:457
ValueContainer< Newton > NewtonContainer
A container containing 64 bit Newton values.
Definition ValueContainers.h:448
ValueContainer< Joule > JouleContainer
A container containing 64 bit Joule values.
Definition ValueContainers.h:430
ValueContainer< CubicMeter > CubicMeterContainer
A container containing 64 bit CubicMeter values.
Definition ValueContainers.h:424
ValueContainer< SquareMeter > SquareMeterContainer
A container containing 64 bit SquareMeter values.
Definition ValueContainers.h:466
ValueContainer< MeterPerSecondSquared > MeterPerSecondSquaredContainer
A container containing 64 bit MeterPerSecondSquared values.
Definition ValueContainers.h:445
ValueContainer< Second > SecondContainer
A container containing 64 bit Second values.
Definition ValueContainers.h:463
ValueContainer< Hertz > HertzContainer
A container containing 64 bit Hertz values.
Definition ValueContainers.h:427
ValueContainer< Kilogram > KilogramContainer
A container containing 64 bit Kilogram values.
Definition ValueContainers.h:436
ValueContainer< Watt > WattContainer
A container containing 64 bit Watt values.
Definition ValueContainers.h:475
ValueContainer< Radian > RadianContainer
A container containing 64 bit Radian values.
Definition ValueContainers.h:454
ValueContainer< Steradian > SteradianContainer
A container containing 64 bit Steradian values.
Definition ValueContainers.h:469
ValueContainer< Pascal > PascalContainer
A container containing 64 bit Pascal values.
Definition ValueContainers.h:451
ValueContainer< Volt > VoltContainer
A container containing 64 bit Volt values.
Definition ValueContainers.h:472
ValueContainer< Ampere > AmpereContainer
A container containing 64 bit Ampere values.
Definition ValueContainers.h:421
DOTS_CPP_API const std::string ToUtf8(const std::wstring &wstr)
Convert a std::wstring to UTF8-encoded std::string.
Base class for all Containers.
Definition ContainerBase.h:44
bool m_bIsChanged
The variable containing the change flag.
Definition ContainerBase.h:127
Meant to be used when something goes very wrong.
Definition Exceptions.h:364
Thrown when an application attempts to get the value of a member that is null.
Definition Exceptions.h:396
Container for base types.
Definition ValueContainers.h:61
constexpr ValueContainer()
Default constructor.
Definition ValueContainers.h:70
bool IsNull() const override
Is the container set to null?
Definition ValueContainers.h:90
T GetVal() const
Get the value of the container.
Definition ValueContainers.h:87
T ContainedType
Definition ValueContainers.h:63
friend class Safir::Dob::Typesystem::Internal::BlobOperations
Definition ValueContainers.h:116
void Copy(const ContainerBase &that) override
Virtual assignment.
Definition ValueContainers.h:100
void SetVal(const T value)
Set the value of the container.
Definition ValueContainers.h:79
void SetNull() override
Set the container to null.
Definition ValueContainers.h:93
Container for strings (std::wstring).
Definition ValueContainers.h:127
void SetVal(const std::wstring &value)
Set the value of the container.
Definition ValueContainers.h:145
void SetNull() override
Set the container to null.
Definition ValueContainers.h:158
const std::wstring & GetVal() const
Get the value of the container.
Definition ValueContainers.h:153
void Copy(const ContainerBase &that) override
Virtual assignment.
Definition ValueContainers.h:166
bool IsNull() const override
Is the container set to null?
Definition ValueContainers.h:155
const std::string & Utf8String() const
Convert the string to a UTF8 encoded std::string.
Definition ValueContainers.h:225
friend class Safir::Dob::Typesystem::Internal::BlobOperations
Definition ValueContainers.h:241
Int32 Utf8StringLength() const
Calculate the length needed for this string in UTF8 encoding.
Definition ValueContainers.h:196
StringContainer()
Default constructor.
Definition ValueContainers.h:136
std::wstring ContainedType
Definition ValueContainers.h:129
Container for Binary.
Definition ValueContainers.h:256
BinaryContainer()
Default constructor.
Definition ValueContainers.h:264
void Copy(const ContainerBase &that) override
Virtual assignment.
Definition ValueContainers.h:295
bool IsNull() const override
Is the container set to null?
Definition ValueContainers.h:285
void SetVal(const Binary &value)
Set the value of the container.
Definition ValueContainers.h:281
const Binary & GetVal() const
Get the value of the container.
Definition ValueContainers.h:272
friend class Safir::Dob::Typesystem::Internal::BlobOperations
Definition ValueContainers.h:308
Binary ContainedType
Definition ValueContainers.h:258
void SetNull() override
Set the container to null.
Definition ValueContainers.h:288