OnixS C++ Eurex T7 Market and Reference Data (EMDI, MDI, RDI, EOBI) Handlers  17.0.1
API documentation
FieldSet.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 
26 
27 #include <vector>
28 
29 namespace OnixS
30 {
31  namespace Eurex
32  {
33  namespace MarketData
34  {
35 
36  ONIXS_EUREX_EMDI_API_DECL (class, Group);
37  ONIXS_EUREX_EMDI_API_DECL (class, Message);
38 
39  /// Field primary attributes (tag and a reference to a value).
40  struct ONIXS_EUREX_EMDI_API Field
41  {
42  /// Field tag.
44 
45  /// Field value reference.
47 
48  /// Initializes field which refers to nothing.
50  : tag (0)
51  {
52  }
53 
54  /// Initializes all members.
55  Field (Tag fieldTag, const FieldValueRef& fieldValue)
56  : tag (fieldTag), value (fieldValue)
57  {
58  }
59  };
60 
61  /// Ordered collection of fields.
62  typedef std::vector<Field> Fields;
63 
64  /// Encapsulates primary operations over collection of FIX
65  /// fields like FIX message and repeating group instance are.
66  class ONIXS_EUREX_EMDI_API FieldSet
67  {
68  public:
69  /// Indicates whether instance refers to a valid set of fields.
70  ///
71  /// If given instance doesn't refer to a valid fields set,
72  /// none of other members must be used.
73  operator bool() const;
74 
75  /// Returns reference to a given field value.
76  ///
77  /// @warning Due to performance considerations, doesn't
78  /// check whether instance refers to a valid set of fields.
79  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
80  /// instance is in valid state.
81  FieldValueRef get (Tag tag) const;
82 
83  /// Returns field value as an OnixS::FIX::Int32 value.
84  ///
85  /// @throw std::exception if conversion is impossible.
86  ///
87  /// @warning Due to performance considerations, doesn't
88  /// check whether instance refers to a valid set of fields.
89  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
90  /// instance is in valid state.
91  Int32 getInt32 (Tag tag) const;
92 
93  /// Returns field value as an OnixS::FIX::UInt32 value.
94  ///
95  /// @throw std::exception if conversion is impossible.
96  ///
97  /// @warning Due to performance considerations, doesn't
98  /// check whether instance refers to a valid set of fields.
99  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
100  /// instance is in valid state.
101  UInt32 getUInt32 (Tag tag) const;
102 
103  /// Returns field value as an OnixS::FIX::Int64 value.
104  ///
105  /// @throw std::exception if conversion is impossible.
106  ///
107  /// @warning Due to performance considerations, doesn't
108  /// check whether instance refers to a valid set of fields.
109  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
110  /// instance is in valid state.
111  Int64 getInt64 (Tag tag) const;
112 
113  /// Returns field value as an OnixS::FIX::UInt64 value.
114  ///
115  /// @throw std::exception if conversion is impossible.
116  ///
117  /// @warning Due to performance considerations, doesn't
118  /// check whether instance refers to a valid set of fields.
119  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
120  /// instance is in valid state.
121  UInt64 getUInt64 (Tag tag) const;
122 
123  /// Returns the field value as a decimal number.
124  ///
125  /// @throw std::exception if conversion is impossible.
126  ///
127  /// @warning Due to performance considerations, doesn't
128  /// check whether instance refers to a valid set of fields.
129  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
130  /// instance is in valid state.
131  Decimal getDecimal (Tag tag) const;
132 
133  /// Returns reference to a read-only text chain.
134  ///
135  /// @throw std::exception if conversion is impossible.
136  ///
137  /// @warning Due to performance considerations, doesn't
138  /// check whether instance refers to a valid set of fields.
139  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
140  /// instance is in valid state.
141  StringRef getStringRef (Tag tag) const;
142 
143  /// Returns the field value as timestamp of requested format.
144  ///
145  /// @throw std::exception if conversion is impossible.
146  ///
147  /// @warning Due to performance considerations, doesn't
148  /// check whether instance refers to a valid set of fields.
149  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
150  /// instance is in valid state.
151  Timestamp
152  getTimestamp (
153  Tag tag,
156 
157  /// Returns reference to a repeating group if underlying
158  /// field defines length of repeating group.
159  ///
160  /// @param numberOfInstancesTag Tag number of
161  /// the field that defines the number of instances
162  /// in this repeating group (the NoXXX field).
163  ///
164  /// @throw std::exception if no repeating group
165  /// is associated with given field (tag).
166  ///
167  /// @warning Returned instance remains valid until field is
168  /// modified via any of OnixS::FIX::FieldSet::set members.
169  Group getGroup (Tag numberOfInstancesTag) const;
170 
171  /// Returns reference to a repeating group if underlying
172  /// field defines length of repeating group.
173  ///
174  /// @param numberOfInstancesTag Tag number of
175  /// the field that defines the number of instances
176  /// in this repeating group (the NoXXX field).
177  ///
178  /// @warning Returned instance remains valid until field is
179  /// modified via any of OnixS::FIX::FieldSet::set members.
180  Group getOptionalGroup (Tag numberOfInstancesTag) const;
181 
182  /// Returns true if the given flag is present
183  /// and it equals to "Y", otherwise false.
184  ///
185  /// @warning Due to performance considerations, doesn't
186  /// check whether instance refers to a valid set of fields.
187  /// Use OnixS::FIX::FieldSet::operator bool() to check whether
188  /// instance is in valid state.
189  bool hasFlag (Tag tag) const;
190 
191  /// Retrieve tags and values of all non-empty fields belonged to the given @c FieldSet instance.
192  /// @param fields Object to receive the @c FieldSet content.
193  /// @return Number of fields placed to the @c fields vector.
194  size_t fields (Fields& fields) const;
195 
196  ///
197  void swap(FieldSet&) throw();
198 
199  protected:
200  // Message to which given set belongs to.
202 
203  // Underlying implementation.
204  void* impl_;
205 
206  // Uninitialized set.
207  FieldSet();
208 
209  // Uninitialized set.
210  FieldSet (const Message*, void*);
211 
212  // Clone construction.
213  FieldSet (const FieldSet&);
214 
215  // Destruction available via descendants.
216  ~FieldSet();
217 
218  FieldSet& operator = (const FieldSet&);
219 
220  private:
221  friend class Message;
222  friend class GroupInstance;
223  friend class MessageOperator;
224  };
225 
226 
227  template<typename Enumeration>
228  inline typename Enumeration::Enum getIntEnumFieldValue (const FieldSet& fieldSet, Tag tag)
229  {
230  UInt32 value;
231  return (fieldSet.get (tag).toNumber (value) ? static_cast<typename Enumeration::Enum> (value) : Enumeration::Undefined);
232  }
233 
234  template<typename Enumeration>
235  inline typename Enumeration::Enum getNonZeroIntEnumFieldValue (const FieldSet& fieldSet, Tag tag)
236  {
237  UInt32 value;
238  return (fieldSet.get (tag).toNumber (value) ? static_cast<typename Enumeration::Enum> (value + 1) : Enumeration::Undefined);
239  }
240  }
241  }
242 }
FieldValueRef value
Field value reference.
Definition: FieldSet.h:46
Enumeration::Enum getIntEnumFieldValue(const FieldSet &fieldSet, Tag tag)
Definition: FieldSet.h:228
Field()
Initializes field which refers to nothing.
Definition: FieldSet.h:49
Enumeration::Enum getNonZeroIntEnumFieldValue(const FieldSet &fieldSet, Tag tag)
Definition: FieldSet.h:235
unsigned Tag
Alias for tag numbers.
Definition: Tag.h:29
Field(Tag fieldTag, const FieldValueRef &fieldValue)
Initializes all members.
Definition: FieldSet.h:55
unsigned int UInt32
Definition: Numeric.h:41
Definition: Defines.h:30
Decimal type for better precision.
Definition: Numeric.h:63
FieldValueRef get(Tag tag) const
Field primary attributes (tag and a reference to a value).
Definition: FieldSet.h:40
Represents timestamp without time-zone information.
Definition: Timestamp.h:87
ONIXS_EUREX_EMDI_API_DECL(class, Message)
std::vector< Field > Fields
Ordered collection of fields.
Definition: FieldSet.h:62
Indicates timestamp in "YYYYMMDD-HH:MM:SS.sssssssss" format.
Definition: Timestamp.h:79