OnixS C++ FIX Engine  4.12.0
API Documentation
FlatFieldRefAndKey.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
22 #include <cstdlib>
23 
24 namespace OnixS {
25 namespace FIX {
26 
27 struct KnownFlatFieldKeys;
28 
29 /// Represents a temporary reference to a field in an editable serialized message.
30 ///
31 /// @note Reference remains valid since the moment it is obtained till the moment any other field of the same Serialized message is modified.
33 {
34 public:
35  /// Initializes as a references to nothing.
37  : valueOffset_(0),
38  valueSize_(0) {
39  }
40 
41  /// Message only should use this constructor to initialize a valid reference.
43  : valueOffset_(valueOffset), valueSize_(valueSize) {
44  }
45 
46  /// Gets value offset.
47  size_t valueOffset() const {
48  return valueOffset_;
49  }
50 
51  /// Gets value size.
52  size_t valueSize() const {
53  return valueSize_;
54  }
55 
56  /// Indicates whether the instance refers to the field or not.
57  operator bool() const {
58  return (0 != valueOffset_);
59  }
60 
61  /// Compares the instance with the given one.
62  bool
64  const FlatFieldRef & other) const {
65  return (
66  valueOffset_ == other.valueOffset_ &&
67  valueSize_ == other.valueSize_);
68  }
69 
70  /// Compares the instance with the given one.
71  bool
73  const FlatFieldRef & other) const {
74  return (
75  valueOffset_ != other.valueOffset_ ||
76  valueSize_ != other.valueSize_);
77  }
78 
79 private:
80 
81  size_t valueOffset_;
82  size_t valueSize_;
83 };
84 
86 
87 /// Key to a serialized field - represents another way of accessing fields in an editable serialized message.
88 ///
89 /// In contrast to FlatFieldRef, FlatFieldKey remains constant and valid during all the life of serialized message object.
90 /// So they are suitable in case of multiple modifications of the same field.
92 {
93 public:
94  /// Initializes as a non-valid key.
96  : key_(static_cast<size_t>(-1)) {
97  }
98 
99  // Initializes valid key.
100  explicit FlatFieldKey(size_t key)
101  : key_(key) {
102  }
103 
104  /// Implicit conversion to the index value.
105  operator size_t() const {
106  return key_;
107  }
108 
109  /// Compares to the given instance.
110  bool
112  const FlatFieldKey & other) const {
113  return (key_ == other.key_);
114  }
115 
116  /// Compares to the given instance.
117  bool
119  const FlatFieldKey & other) const {
120  return (key_ != other.key_);
121  }
122 
123 private:
124 
125  friend
126  struct
128 
129  // Numeric value of the key.
130  size_t key_;
131 };
132 
134 
135 /// Keys are constant during the serialized message lifetime.
136 /// However, keys are allocated privately by each particular
137 /// message instance and thus may differ for same fields in
138 /// different instances. For commonly used fields, there are
139 /// pre-allocated keys which are same for all messages.
141  /// Key to access the BodyLength field.
142  static
145  return FlatFieldKey(0);
146  }
147 
148  /// Key to access the MsgType field.
149  static
152  return FlatFieldKey(1);
153  }
154 
155  /// Key to access the MsgSeqNum field.
156  static
159  return FlatFieldKey(2);
160  }
161 
162  /// Key to access the SendingTime field.
163  static
166  return FlatFieldKey(3);
167  }
168 
169  /// Value of the first key to be allocated dynamically.
170  static
173  return FlatFieldKey(4);
174  }
175 };
176 
178 
179 }
180 }
FlatFieldKey()
Initializes as a non-valid key.
FlatFieldRef()
Initializes as a references to nothing.
size_t valueOffset() const
Gets value offset.
FlatFieldRef SerializedFieldRef
size_t valueSize() const
Gets value size.
bool operator==(const FlatFieldRef &other) const
Compares the instance with the given one.
static FlatFieldKey sendingTime()
Key to access the SendingTime field.
Represents a temporary reference to a field in an editable serialized message.
static FlatFieldKey bodyLength()
Key to access the BodyLength field.
KnownFlatFieldKeys KnownSerializedFieldKeys
static FlatFieldKey msgType()
Key to access the MsgType field.
Key to a serialized field - represents another way of accessing fields in an editable serialized mess...
static FlatFieldKey seqNumber()
Key to access the MsgSeqNum field.
Keys are constant during the serialized message lifetime.
FlatFieldKey SerializedFieldKey
static FlatFieldKey dynamic()
Value of the first key to be allocated dynamically.
FlatFieldRef(size_t valueOffset, size_t valueSize)
Message only should use this constructor to initialize a valid reference.
bool operator!=(const FlatFieldRef &other) const
Compares the instance with the given one.