OnixS C++ FIX Engine  4.6.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  bool valid() 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 
140  /// Converts field value into the timespan
141  ///
142  /// @return false if conversion fails.
143  ///
144  /// @warning Due to performance considerations
145  /// doesn't check whether instance refers to a valid
146  /// value. Use OnixS::FIX::FieldValueRef::operator bool()
147  /// member to check instance for a validness.
148  bool
149  toTimeSpan(
151 
152  /// If value represents text, returns reference to it.
153  ///
154  /// @return false if conversion fails (for example,
155  /// stored value is whole number assigned to a field
156  /// using OnixS::FIX::FieldSet::setV member), otherwise - true.
157  ///
158  /// @warning Due to performance considerations
159  /// doesn't check whether instance refers to a valid
160  /// value. Use OnixS::FIX::FieldValueRef::operator bool()
161  /// member to check instance for a validness.
162  bool toStringRef(StringRef &) const;
163 
164  /// If value represents text, returns reference to it.
165  ///
166  /// @return An empty StringRef if conversion fails (for example,
167  /// stored value is whole number assigned to a field
168  /// using OnixS::FIX::FieldSet::setV member), otherwise - valid StringRef.
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  StringRef toStringRef() const;
175 
176  /// If value represent one-char text,
177  /// copies it into given variable.
178  ///
179  /// @return false if conversion fails (for example,
180  /// stored value is whole number assigned to a field
181  /// using OnixS::FIX::FieldSet::setV member).
182  ///
183  /// @warning Due to performance considerations
184  /// doesn't check whether instance refers to a valid
185  /// value. Use OnixS::FIX::FieldValueRef::operator bool()
186  /// member to check instance for a validness.
187  bool toChar(char &) const;
188 
189  /// If repeating group is associated with
190  /// field, allows to get instance of it.
191  ///
192  /// @return false if no group is associated with field.
193  ///
194  /// @warning Due to performance considerations
195  /// doesn't check whether instance refers to a valid
196  /// value. Use OnixS::FIX::FieldValueRef::operator bool()
197  /// member to check instance for a validness.
198  bool toGroup(Group &) const;
199 
200  /// Appends copy of text presentation to the std::string.
201  void toString(std::string &) const;
202 
203  /// Return string presentation of field value.
204  std::string toString() const;
205 
206  /// Updates instance to refer to another field value.
207  /// @warning Does NOT perform deep copy of field values.
208  /// Just updates reference to point to 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 timestamp in "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 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 concept of a read-only reference to a FIX field value.
Definition: FieldValueRef.h:32
std::string toString() const
Return string presentation of field value.
Provides efficient way of accessing text-based FIX field values.
Definition: StringRef.h:45
int Int32
Definition: Numeric.h:35
unsigned long long UInt64
Definition: Numeric.h:39
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
Time span related functionality.
Definition: TimeSpan.h:93
bool operator==(const FieldValueRef &ref, const std::string &str)
Decimal type for better precision.
Definition: Numeric.h:47
Encapsulates operations over a FIX Message.
Definition: Message.h:49
StringRef toStringRef() const
If value represents text, returns reference to it.
Indicates time span in "HH:MM:SS.sss" format.
Definition: TimeSpan.h:79
Timestamps related functionality.
Definition: Timestamp.h:91
double Double
Definition: Numeric.h:41
bool operator!=(const FieldValueRef &ref, const std::string &str)