OnixS C++ CME iLink 3 Binary Order Entry Handler  1.9.0
API Documentation
ValueContainer.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <OnixS/CME/iLink3/ABI.h>
25 
26 #include <new>
27 
29 
30 /// Container for a value.
33 {
34  enum
35  {
36  /// Capacity of the storage.
37  ///
38  /// The storage must be spacious enough
39  /// to store all integer types, string refs,
40  /// time-related typed and the Decimal.
41  Capacity = 16
42  };
43 
44  Byte bytes_[Capacity];
45 
46  /// This method is used to make g++ happy with the
47  /// concept of storing a value in an array.
48  void* place() ONIXS_ILINK3_NOEXCEPT
49  {
50  return static_cast<void*>(bytes_);
51  }
52 
53  /// This method is used to make g++ happy with the
54  /// concept of storing a value in an array.
55  const void* place() const ONIXS_ILINK3_NOEXCEPT
56  {
57  return static_cast<const void*>(bytes_);
58  }
59 
60 public:
61  /// Initializes the container.
62  ValueContainer() ONIXS_ILINK3_DEFAULT;
63 
64  /// \return the stored value.
65  template <typename Value>
67  {
68  ONIXS_ILINK3_STATIC_ASSERT_MSG
69  (
70  (sizeof(Value) <= static_cast<size_t>(Capacity)), "Capacity is not sufficient for storing values of the given type."
71  );
72 
73  return * static_cast<Value*> (place());
74  }
75 
76  /// \return the stored value.
77  template <typename Value>
78  ONIXS_ILINK3_NODISCARD const Value& get() const
79  {
80  ONIXS_ILINK3_STATIC_ASSERT_MSG
81  (
82  (sizeof(Value) <= static_cast<size_t>(Capacity)), "Capacity of the storage is not sufficient to store values of the specified type."
83  );
84 
85  return * static_cast<const Value*>(place());
86  }
87 
88  /// Stores the given value.
89  template<class Value>
90  ValueContainer& assign(const Value& value)
91  {
92  ONIXS_ILINK3_STATIC_ASSERT_MSG
93  (
94  (sizeof(Value) <= static_cast<size_t>(Capacity)), "Capacity of the storage is not sufficient to store values of the specified type."
95  );
96 
97  new (place()) Value(value);
98 
99  return *this;
100  }
101 };
102 
UInt8 Byte
Alias for Byte.
Definition: Memory.h:34
ValueContainer & assign(const Value &value)
Stores the given value.
#define ONIXS_ILINK3_MESSAGING_TAGBASED_NAMESPACE_END
Definition: ABI.h:153
#define ONIXS_ILINK3_LTWT_CLASS
Definition: ABI.h:84
#define ONIXS_ILINK3_MESSAGING_TAGBASED_NAMESPACE_BEGIN
Definition: ABI.h:149
#define ONIXS_ILINK3_NODISCARD
Definition: Compiler.h:173