OnixS C++ FIX Engine  4.10.1
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 namespace Core {
27 namespace Messaging {
28 namespace Extras {
29 class FlatMessage;
30 }
31 }
32 }
33 
34 struct KnownFlatFieldKeys;
35 
36 /// Represents a temporary reference to a field in an editable serialized message.
37 ///
38 /// @note Reference remains valid since the moment it is obtained till the moment any other field of the same Serialized message is modified.
40 {
41 public:
42  /// Initializes as a references to nothing.
44  : valueOffset_(0),
45  valueSize_(0) {
46  }
47 
48  /// Message only should use this constructor to initialize a valid reference.
49  FlatFieldRef(size_t valueOffset, size_t valueSize)
50  : valueOffset_(valueOffset), valueSize_(valueSize) {
51  }
52 
53  /// Gets value offset.
54  size_t valueOffset() const {
55  return valueOffset_;
56  }
57 
58  /// Gets value size.
59  size_t valueSize() const {
60  return valueSize_;
61  }
62 
63  /// Indicates whether the instance refers to the field or not.
64  operator bool() const {
65  return (0 != valueOffset_);
66  }
67 
68  /// Compares the instance with the given one.
69  bool
71  const FlatFieldRef & other) const {
72  return (
73  valueOffset_ == other.valueOffset_ &&
74  valueSize_ == other.valueSize_);
75  }
76 
77  /// Compares the instance with the given one.
78  bool
80  const FlatFieldRef & other) const {
81  return (
82  valueOffset_ != other.valueOffset_ ||
83  valueSize_ != other.valueSize_);
84  }
85 
86 private:
87  friend
88  class
89  OnixS::FIX::Core::Messaging::Extras::
90  FlatMessage;
91 
92  size_t valueOffset_;
93  size_t valueSize_;
94 };
95 
97 
98 /// Key to a serialized field - represents another way of accessing fields in an editable serialized message.
99 ///
100 /// In contrast to FlatFieldRef, FlatFieldKey remains constant and valid during all the life of serialized message object.
101 /// So they are suitable in case of multiple modifications of the same field.
103 {
104 public:
105  /// Initializes as a non-valid key.
107  : key_(static_cast<size_t>(-1)) {
108  }
109 
110  // Initializes valid key.
111  explicit FlatFieldKey(size_t key)
112  : key_(key) {
113  }
114 
115  /// Implicit conversion to the index value.
116  operator size_t() const {
117  return key_;
118  }
119 
120  /// Compares to the given instance.
121  bool
123  const FlatFieldKey & other) const {
124  return (key_ == other.key_);
125  }
126 
127  /// Compares to the given instance.
128  bool
130  const FlatFieldKey & other) const {
131  return (key_ != other.key_);
132  }
133 
134 private:
135 
136  friend
137  class
138  OnixS::FIX::Core::Messaging::Extras::
139  FlatMessage;
140 
141  friend
142  struct
144 
145  // Numeric value of the key.
146  size_t key_;
147 };
148 
150 
151 /// Keys are constant during the serialized message lifetime.
152 /// However, keys are allocated privately by each particular
153 /// message instance and thus may differ for same fields in
154 /// different instances. For commonly used fields, there are
155 /// pre-allocated keys which are same for all messages.
157  /// Key to access the BodyLength field.
158  static
161  return FlatFieldKey(0);
162  }
163 
164  /// Key to access the MsgType field.
165  static
168  return FlatFieldKey(1);
169  }
170 
171  /// Key to access the MsgSeqNum field.
172  static
175  return FlatFieldKey(2);
176  }
177 
178  /// Key to access the SendingTime field.
179  static
182  return FlatFieldKey(3);
183  }
184 
185  /// Value of the first key to be allocated dynamically.
186  static
189  return FlatFieldKey(4);
190  }
191 };
192 
194 
195 }
196 }
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.
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.
Provides an access to FIX fields from a flat (tag=value) message.
Definition: FlatMessage.h:88
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
bool operator==(const FieldValueRef &ref, const std::string &str)
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 FieldValueRef &ref, const std::string &str)