OnixS C++ FIX Engine  4.10.1
API Documentation
FieldValueRef.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 
24 
25 namespace OnixS {
26 namespace FIX {
27 ONIXS_FIXENGINE_API_DECL(class, Message);
28 ONIXS_FIXENGINE_API_DECL(class, Group);
29 
30 /// Implements a concept of a read-only
31 /// reference to a FIX field value.
32 class
35 {
36 public:
37  /// The uninitialized value.
38  FieldValueRef();
39 
40  /// The shallow copy from another one.
41  FieldValueRef(const FieldValueRef & other);
42 
43  /// Indicated whether the instance
44  /// refers to a valid value.
45  bool valid() const;
46 
47  /// Return the string presentation
48  /// of the value being referenced.
49  operator std::string() const;
50 
51  /// Compares with another instance for equality.
52  bool operator == (const FieldValueRef &) const;
53 
54  /// Compares with another instance for inequality.
55  bool operator != (const FieldValueRef &) const;
56 
57  /// Compares the string presentation for
58  /// equality with given text reference.
59  bool operator == (const StringRef &) const;
60 
61  /// Compares the string presentation for
62  /// equality with the given text reference.
63  bool operator != (const StringRef &) const;
64 
65  /// Converts the field value into the whole number.
66  ///
67  /// @return false if the conversion fails.
68  ///
69  /// @warning Due to performance considerations
70  /// doesn't check whether an instance refers to a valid
71  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
72  /// member to check an instance for a validness.
73  bool toNumber(Int32 &) const;
74 
75  /// Converts the field value into the whole number.
76  ///
77  /// @return false if the conversion fails.
78  ///
79  /// @warning Due to performance considerations
80  /// doesn't check whether an instance refers to a valid
81  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
82  /// member to check an instance for a validness.
83  bool toNumber(UInt32 &) const;
84 
85  /// Converts the field value into the whole number.
86  ///
87  /// @return false if the conversion fails.
88  ///
89  /// @warning Due to performance considerations
90  /// doesn't check whether an instance refers to a valid
91  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
92  /// member to check an instance for a validness.
93  bool toNumber(Int64 &) const;
94 
95  /// Converts the field value into the whole number.
96  ///
97  /// @return false if the conversion fails.
98  ///
99  /// @warning Due to performance considerations
100  /// doesn't check whether an instance refers to a valid
101  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
102  /// member to check an instance for a validness.
103  bool toNumber(UInt64 &) const;
104 
105  /// Converts the field value into the floating point value.
106  ///
107  /// @return false if the conversion fails.
108  ///
109  /// @warning Due to performance considerations
110  /// doesn't check whether an instance refers to a valid
111  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
112  /// member to check an instance for a validness.
113  bool toNumber(Double &) const;
114 
115  /// Converts the field value into the floating point value.
116  ///
117  /// @return false if the conversion fails.
118  ///
119  /// @warning Due to performance considerations
120  /// doesn't check whether an instance refers to a valid
121  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
122  /// member to check an instance for a validness.
123  bool toNumber(Decimal &) const;
124 
125  /// Converts the field value into the timestamp of the requested format.
126  ///
127  /// @return false if the conversion fails.
128  ///
129  /// @warning Due to performance considerations
130  /// doesn't check whether an instance refers to a valid
131  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
132  /// member to check an instance for a validness.
133  bool
134  toTimestamp(
135  Timestamp &,
138 
139 
140  /// Converts the field value into the timespan
141  ///
142  /// @return false if the conversion fails.
143  ///
144  /// @warning Due to performance considerations
145  /// doesn't check whether an instance refers to a valid
146  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
147  /// member to check an instance for a validness.
148  bool
149  toTimeSpan(
151 
152  /// If the value represents a text, returns a reference to it.
153  ///
154  /// @return false if the conversion fails (for example,
155  /// the stored value is the whole number assigned to a field
156  /// using the OnixS::FIX::FieldSet::setV member), otherwise - true.
157  ///
158  /// @warning Due to performance considerations
159  /// doesn't check whether an instance refers to a valid
160  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
161  /// member to check an instance for a validness.
162  bool toStringRef(StringRef &) const;
163 
164  /// If the value represents a text, returns a reference to it.
165  ///
166  /// @return An empty StringRef if the conversion fails (for example,
167  /// the stored value is the whole number assigned to a field
168  /// using the OnixS::FIX::FieldSet::setV member), otherwise - valid StringRef.
169  ///
170  /// @warning Due to performance considerations
171  /// doesn't check whether an instance refers to a valid
172  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
173  /// member to check an instance for a validness.
174  StringRef toStringRef() const;
175 
176  /// If the value represent a one-char text,
177  /// copies it into the given variable.
178  ///
179  /// @return false if the conversion fails (for example,
180  /// the stored value is the whole number assigned to a field
181  /// using the OnixS::FIX::FieldSet::setV member).
182  ///
183  /// @warning Due to performance considerations
184  /// doesn't check whether an instance refers to a valid
185  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
186  /// member to check an instance for a validness.
187  bool toChar(char &) const;
188 
189  /// If a repeating group is associated with
190  /// the field, allows to get an instance of it.
191  ///
192  /// @return false if no group is associated with the field.
193  ///
194  /// @warning Due to performance considerations
195  /// doesn't check whether an instance refers to a valid
196  /// value. Use the OnixS::FIX::FieldValueRef::operator bool()
197  /// member to check an instance for a validness.
198  bool toGroup(Group &) const;
199 
200  /// Appends a copy of a text presentation to the std::string.
201  void toString(std::string &) const;
202 
203  /// Return the string presentation of the field value.
204  std::string toString() const;
205 
206  /// Updates an instance to refer to another field value.
207  /// @warning Does NOT perform a deep copy of field values.
208  /// Just updates a reference to point to the value of other field.
209  FieldValueRef & operator = (const FieldValueRef &);
210 
211  /// Swaps two references.
212  void swap(FieldValueRef & other);
213 
214 private:
215  friend class MessageOperator;
216 
217  const void * impl_;
218 
219  const Message * container_;
220 
222  const Message *,
223  const void *);
224 };
225 
227 {
228  StringRef result;
229 
230  if(toStringRef(result))
231  return result;
232  else
233  return StringRef();
234 }
235 
236 inline
237 FieldValueRef::
238 operator std::string() const
239 {
240  std::string str;
241 
242  toString(str);
243 
244  return str;
245 }
246 
247 inline
248 std::string
250 {
251  std::string str;
252 
253  toString(str);
254 
255  return str;
256 }
257 
258 // More comparison operators.
259 
260 inline
261 bool
263  const FieldValueRef & ref,
264  const std::string & str)
265 {
266  return ref == StringRef(str);
267 }
268 
269 inline
270 bool
272  const FieldValueRef & ref,
273  const std::string & str)
274 {
275  return ref != StringRef(str);
276 }
277 
278 inline
279 bool
281  const std::string & str,
282  const FieldValueRef & ref)
283 {
284  return ref == StringRef(str);
285 }
286 
287 inline
288 bool
290  const std::string & str,
291  const FieldValueRef & ref)
292 {
293  return ref != StringRef(str);
294 }
295 
296 // More comparison operators.
297 
298 inline
299 bool
301  const FieldValueRef & ref,
302  const char * str)
303 {
304  return ref == StringRef(str);
305 }
306 
307 inline
308 bool
310  const FieldValueRef & ref,
311  const char * str)
312 {
313  return ref != StringRef(str);
314 }
315 
316 inline
317 bool
319  const char * str,
320  const FieldValueRef & ref)
321 {
322  return ref == StringRef(str);
323 }
324 
325 inline
326 bool
328  const char * str,
329  const FieldValueRef & ref)
330 {
331  return ref != StringRef(str);
332 }
333 }
334 }
Indicates the timestamp in the "YYYYMMDD-HH:MM:SS.sssssssss" format.
Definition: Timestamp.h:83
unsigned int UInt32
Definition: Numeric.h:36
long long Int64
Definition: Numeric.h:38
Encapsulates operations over the FIX Repeating Group.
Definition: Group.h:107
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
bool operator!=(const FieldValueRef &) const
Compares with another instance for inequality.
bool operator==(const FieldValueRef &) const
Compares with another instance for equality.
Implements a concept of a read-only reference to a FIX field value.
Definition: FieldValueRef.h:32
std::string toString() const
Return the string presentation of the field value.
Provides an efficient way of accessing text-based FIX field values.
Definition: StringRef.h:59
int Int32
Definition: Numeric.h:35
unsigned long long UInt64
Definition: Numeric.h:39
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
The time span related functionality.
Definition: TimeSpan.h:93
bool operator==(const FieldValueRef &ref, const std::string &str)
The Decimal type for a better precision.
Definition: Numeric.h:47
Encapsulates operations over a FIX Message.
Definition: Message.h:49
StringRef toStringRef() const
If the value represents a text, returns a reference to it.
Indicates the time span in the "HH:MM:SS.sss" format.
Definition: TimeSpan.h:79
The timestamps related functionality.
Definition: Timestamp.h:91
double Double
Definition: Numeric.h:41
bool operator!=(const FieldValueRef &ref, const std::string &str)