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
95 const T GetValOrDefault(const T& defaultVal) const {return m_bIsNull ? defaultVal : m_Value;}
96
97 //implementation of pure virtual in ContainerBase.
98 bool IsNull() const override {return m_bIsNull;}
99
100 //implementation of pure virtual in ContainerBase.
101 bool HasVal() const override {return !m_bIsNull;}
102
103 //implementation of pure virtual in ContainerBase.
104 void SetNull() override
105 {
106 m_bIsNull = true;
107 m_bIsChanged = true;
108 }
109
110 //implementation of pure virtual in ContainerBase.
111 void Copy(const ContainerBase & that) override
112 {
113 if (this != &that)
114 {
115 if (typeid(*this) != typeid(that))
116 {
117 throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
118 }
119 *this = static_cast<const ValueContainer<T> &>(that);
120 }
121 }
122
123 private:
124 bool m_bIsNull;
125 T m_Value;
126
127 friend class Safir::Dob::Typesystem::Internal::BlobOperations;
128 };
129
138 {
139 public:
140 typedef std::wstring ContainedType;
141
147 StringContainer():ContainerBase(),m_bIsNull(true), m_Value(),m_CachedUtf8String() {}
148
156 void SetVal(const std::wstring & value) {m_Value = value; m_CachedUtf8String.clear(); m_bIsNull = false; m_bIsChanged = true;}
157
164 const std::wstring & GetVal() const {if (m_bIsNull) throw NullException(L"value is null",__WFILE__,__LINE__); return m_Value;}
165
172 const std::wstring GetValOrDefault(const std::wstring& defaultVal = L"") const {if (m_bIsNull) return defaultVal; return m_Value;}
173
174 bool IsNull() const override {return m_bIsNull;}
175
176 //implementation of pure virtual in ContainerBase.
177 bool HasVal() const override {return !m_bIsNull;}
178
179 //implementation of pure virtual in ContainerBase.
180 void SetNull() override
181 {
182 m_bIsNull = true;
183 m_bIsChanged = true;
184 m_CachedUtf8String.clear();
185 }
186
187 //implementation of pure virtual in ContainerBase.
188 void Copy(const ContainerBase & that) override
189 {
190 if (this != &that)
191 {
192 if (typeid(*this) != typeid(that))
193 {
194 throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
195 }
196 *this = static_cast<const StringContainer &>(that);
197 }
198 }
199
205
207
219 {
220 if (IsNull())
221 {
222 return 0;
223 }
224
225 if (m_Value.empty())
226 {
227 return 1;
228 }
229
230 if (m_CachedUtf8String.empty())
231 {
232 m_CachedUtf8String = Utilities::ToUtf8(m_Value);
233 }
234
235 return static_cast<Int32>(m_CachedUtf8String.length() + 1);
236 }
237
247 const std::string & Utf8String() const
248 {
249 if (IsNull())
250 {
251 throw NullException(L"The string is null, cannot convert!",__WFILE__,__LINE__);
252 }
253 if (!m_Value.empty() && m_CachedUtf8String.empty())
254 {
255 m_CachedUtf8String = Utilities::ToUtf8(m_Value);
256 }
257 return m_CachedUtf8String;
258 }
259
261
262 private:
264
265 bool m_bIsNull;
266 std::wstring m_Value;
267 mutable std::string m_CachedUtf8String;
268 };
269
278 {
279 public:
286 BinaryContainer():ContainerBase(),m_bIsNull(true), m_Value() {}
287
294 const Binary& GetVal() const {if (m_bIsNull) throw NullException(L"value is null",__WFILE__,__LINE__); return m_Value;}
295
303 void SetVal(const Binary & value) {m_Value = value; m_bIsNull = false; m_bIsChanged = true;}
304
305
306 //implementation of pure virtual in ContainerBase.
307 bool IsNull() const override {return m_bIsNull;}
308
309 //implementation of pure virtual in ContainerBase.
310 bool HasVal() const override {return !m_bIsNull;}
311
312 //implementation of pure virtual in ContainerBase.
313 void SetNull() override
314 {
315 m_bIsNull = true;
316 m_bIsChanged = true;
317 }
318
319 //implementation of pure virtual in ContainerBase.
320 void Copy(const ContainerBase & that) override
321 {
322 if (this != &that)
323 {
324 if (typeid(*this) != typeid(that))
325 {
326 throw SoftwareViolationException(L"Invalid call to Copy, containers are not of same type",__WFILE__,__LINE__);
327 }
328 *this = static_cast<const BinaryContainer &>(that);
329 }
330 }
331
332 private:
334
335 bool m_bIsNull;
336 Binary m_Value;
337 };
338
343
346
349
352
355
358
361
364
367
370
373
374
376
377 //--------------------------------------------------
378 // SI-types (32-bits)
379 //--------------------------------------------------
380 namespace Si32
381 {
384
387
390
393
396
399
402
405
408
411
414
417
420
423
426
429
432
435
438 }
439
440 //--------------------------------------------------
441 // SI-types (64-bits)
442 //--------------------------------------------------
443 namespace Si64
444 {
447
450
453
456
459
462
465
468
471
474
477
480
483
486
489
492
495
498
501 }
502
503
504}
505}
506}
507#endif
#define __WFILE__
Definition Exceptions.h:31
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
ValueContainer< Int32 > Int32Container
A container containing 32 bit integer values.
Definition ValueContainers.h:348
ValueContainer< bool > BooleanContainer
A container containing boolean values.
Definition ValueContainers.h:345
ValueContainer< Float32 > Float32Container
A container containing 32 bit floating point values.
Definition ValueContainers.h:354
ValueContainer< EntityId > EntityIdContainer
A container containing EntityId values.
Definition ValueContainers.h:366
ValueContainer< HandlerId > HandlerIdContainer
A container containing HandlerId values.
Definition ValueContainers.h:372
ValueContainer< InstanceId > InstanceIdContainer
A container containing InstanceId values.
Definition ValueContainers.h:363
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:369
DotsC_Int32 Int32
32 bit integer type.
Definition Defs.h:66
ValueContainer< TypeId > TypeIdContainer
A container containing TypeId values.
Definition ValueContainers.h:360
ValueContainer< Int64 > Int64Container
A container containing 64 bit integer values.
Definition ValueContainers.h:351
ValueContainer< Float64 > Float64Container
A container containing 64 bit floating point values.
Definition ValueContainers.h:357
32 bit SI-types.
Definition ArrayContainer.h:256
ValueContainer< Volt > VoltContainer
A container containing 32 bit Volt values.
Definition ValueContainers.h:434
ValueContainer< Radian > RadianContainer
A container containing 32 bit Radian values.
Definition ValueContainers.h:416
ValueContainer< Kelvin > KelvinContainer
A container containing 32 bit Kelvin values.
Definition ValueContainers.h:395
ValueContainer< Newton > NewtonContainer
A container containing 32 bit Newton values.
Definition ValueContainers.h:410
ValueContainer< Pascal > PascalContainer
A container containing 32 bit Pascal values.
Definition ValueContainers.h:413
ValueContainer< Watt > WattContainer
A container containing 32 bit Watt values.
Definition ValueContainers.h:437
ValueContainer< SquareMeter > SquareMeterContainer
A container containing 32 bit SquareMeter values.
Definition ValueContainers.h:428
ValueContainer< Meter > MeterContainer
A container containing 32 bit Meter values.
Definition ValueContainers.h:401
ValueContainer< Kilogram > KilogramContainer
A container containing 32 bit Kilogram values.
Definition ValueContainers.h:398
ValueContainer< RadianPerSecondSquared > RadianPerSecondSquaredContainer
A container containing 32 bit RadianPerSecondSquared values.
Definition ValueContainers.h:422
ValueContainer< MeterPerSecond > MeterPerSecondContainer
A container containing 32 bit MeterPerSecond values.
Definition ValueContainers.h:404
ValueContainer< Ampere > AmpereContainer
A container containing 32 bit Ampere values.
Definition ValueContainers.h:383
ValueContainer< Second > SecondContainer
A container containing 32 bit Second values.
Definition ValueContainers.h:425
ValueContainer< RadianPerSecond > RadianPerSecondContainer
A container containing 32 bit RadianPerSecond values.
Definition ValueContainers.h:419
ValueContainer< Steradian > SteradianContainer
A container containing 32 bit Steradian values.
Definition ValueContainers.h:431
ValueContainer< Hertz > HertzContainer
A container containing 32 bit Hertz values.
Definition ValueContainers.h:389
ValueContainer< CubicMeter > CubicMeterContainer
A container containing 32 bit CubicMeter values.
Definition ValueContainers.h:386
ValueContainer< Joule > JouleContainer
A container containing 32 bit Joule values.
Definition ValueContainers.h:392
ValueContainer< MeterPerSecondSquared > MeterPerSecondSquaredContainer
A container containing 32 bit MeterPerSecondSquared values.
Definition ValueContainers.h:407
64 bit SI-types.
Definition ArrayContainer.h:319
ValueContainer< Kelvin > KelvinContainer
A container containing 64 bit Kelvin values.
Definition ValueContainers.h:458
ValueContainer< Meter > MeterContainer
A container containing 64 bit Meter values.
Definition ValueContainers.h:464
ValueContainer< RadianPerSecondSquared > RadianPerSecondSquaredContainer
A container containing 64 bit RadianPerSecondSquared values.
Definition ValueContainers.h:485
ValueContainer< MeterPerSecond > MeterPerSecondContainer
A container containing 64 bit MeterPerSecond values.
Definition ValueContainers.h:467
ValueContainer< RadianPerSecond > RadianPerSecondContainer
A container containing 64 bit RadianPerSecond values.
Definition ValueContainers.h:482
ValueContainer< Newton > NewtonContainer
A container containing 64 bit Newton values.
Definition ValueContainers.h:473
ValueContainer< Joule > JouleContainer
A container containing 64 bit Joule values.
Definition ValueContainers.h:455
ValueContainer< CubicMeter > CubicMeterContainer
A container containing 64 bit CubicMeter values.
Definition ValueContainers.h:449
ValueContainer< SquareMeter > SquareMeterContainer
A container containing 64 bit SquareMeter values.
Definition ValueContainers.h:491
ValueContainer< MeterPerSecondSquared > MeterPerSecondSquaredContainer
A container containing 64 bit MeterPerSecondSquared values.
Definition ValueContainers.h:470
ValueContainer< Second > SecondContainer
A container containing 64 bit Second values.
Definition ValueContainers.h:488
ValueContainer< Hertz > HertzContainer
A container containing 64 bit Hertz values.
Definition ValueContainers.h:452
ValueContainer< Kilogram > KilogramContainer
A container containing 64 bit Kilogram values.
Definition ValueContainers.h:461
ValueContainer< Watt > WattContainer
A container containing 64 bit Watt values.
Definition ValueContainers.h:500
ValueContainer< Radian > RadianContainer
A container containing 64 bit Radian values.
Definition ValueContainers.h:479
ValueContainer< Steradian > SteradianContainer
A container containing 64 bit Steradian values.
Definition ValueContainers.h:494
ValueContainer< Pascal > PascalContainer
A container containing 64 bit Pascal values.
Definition ValueContainers.h:476
ValueContainer< Volt > VoltContainer
A container containing 64 bit Volt values.
Definition ValueContainers.h:497
ValueContainer< Ampere > AmpereContainer
A container containing 64 bit Ampere values.
Definition ValueContainers.h:446
DOTS_CPP_API const std::string ToUtf8(const std::wstring &wstr)
Convert a std::wstring to UTF8-encoded std::string.
bool m_bIsChanged
The variable containing the change flag.
Definition ContainerBase.h:134
constexpr ContainerBase()
Default Constructor.
Definition ContainerBase.h:51
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
bool HasVal() const override
Does the container have a value?
Definition ValueContainers.h:101
constexpr ValueContainer()
Default constructor.
Definition ValueContainers.h:70
bool IsNull() const override
Is the container set to null?
Definition ValueContainers.h:98
T GetVal() const
Get the value of the container.
Definition ValueContainers.h:87
const T GetValOrDefault(const T &defaultVal) const
Get the value of the container if the container has a value.
Definition ValueContainers.h:95
T ContainedType
Definition ValueContainers.h:63
void Copy(const ContainerBase &that) override
Virtual assignment.
Definition ValueContainers.h:111
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:104
void SetVal(const std::wstring &value)
Set the value of the container.
Definition ValueContainers.h:156
void SetNull() override
Set the container to null.
Definition ValueContainers.h:180
const std::wstring & GetVal() const
Get the value of the container.
Definition ValueContainers.h:164
void Copy(const ContainerBase &that) override
Virtual assignment.
Definition ValueContainers.h:188
bool IsNull() const override
Is the container set to null?
Definition ValueContainers.h:174
const std::string & Utf8String() const
Convert the string to a UTF8 encoded std::string.
Definition ValueContainers.h:247
friend class Safir::Dob::Typesystem::Internal::BlobOperations
Definition ValueContainers.h:263
Int32 Utf8StringLength() const
Calculate the length needed for this string in UTF8 encoding.
Definition ValueContainers.h:218
const std::wstring GetValOrDefault(const std::wstring &defaultVal=L"") const
Get the value of the container if the container has a value.
Definition ValueContainers.h:172
StringContainer()
Default constructor.
Definition ValueContainers.h:147
bool HasVal() const override
Does the container have a value?
Definition ValueContainers.h:177
std::wstring ContainedType
Definition ValueContainers.h:140
BinaryContainer()
Default constructor.
Definition ValueContainers.h:286
void Copy(const ContainerBase &that) override
Virtual assignment.
Definition ValueContainers.h:320
bool IsNull() const override
Is the container set to null?
Definition ValueContainers.h:307
void SetVal(const Binary &value)
Set the value of the container.
Definition ValueContainers.h:303
const Binary & GetVal() const
Get the value of the container.
Definition ValueContainers.h:294
bool HasVal() const override
Does the container have a value?
Definition ValueContainers.h:310
friend class Safir::Dob::Typesystem::Internal::BlobOperations
Definition ValueContainers.h:333
Binary ContainedType
Definition ValueContainers.h:280
void SetNull() override
Set the container to null.
Definition ValueContainers.h:313