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