OnixS C++ FIX Engine  4.12.0
API Documentation
Group.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 <iterator>
23 
25 
26 namespace OnixS {
27 namespace FIX {
28 ONIXS_FIXENGINE_API_DECL(class, Message);
29 ONIXS_FIXENGINE_API_DECL(class, Group);
30 
31 /// The single instance of the FIX Repeating Group. Provides an access
32 /// to the fields of a particular repeating group instance.
33 ///
34 /// Class behaves like a pointer/reference to a set of FIX
35 /// fields. Coping and assignment operations just update a reference
36 /// to the field-set being pointed, no deep copying is performed.
37 class
39  GroupInstance : public FieldSet
40 {
41 public:
42  /// The group instance which refers to nothing.
43  GroupInstance();
44 
45  /// Initializes an instance as a reference to the other one.
46  GroupInstance(const GroupInstance & other);
47 
48  /// Reinitializes an instance as reference of other one.
49  GroupInstance & operator = (const GroupInstance &);
50 
51  /// Swaps two instances.
52  void swap(GroupInstance &);
53 
54  /// Returns the string representation of the group instance using
55  /// the given delimiter.
56  ///
57  /// @param delimiter Defines the field delimiter to be used.
58  std::string toString(char delimiter = 0x1) const;
59 
60  /// Appends a string representation of the group instance using
61  /// the given delimiter.
62  ///
63  /// @param str The string to which the presentation is appended.
64  /// @param delimiter Defines the field delimiter to be used.
65  void toString(std::string & str, char delimiter = 0x1) const;
66 
67 private:
68  friend class MessageOperator;
69 
70  GroupInstance(const Message *, void *);
71 };
72 
73 inline
75 {
76  *static_cast<FieldSet *>(this) = static_cast<const FieldSet &>(other);
77  return *this;
78 }
79 
80 inline
82 {
83  FieldSet::swap(static_cast<FieldSet &>(other));
84 }
85 
86 inline
87 std::string GroupInstance::toString(char delimiter) const
88 {
89  std::string str;
90 
91  toString(str, delimiter);
92 
93  return str;
94 }
95 
96 /// Encapsulates operations over the FIX Repeating Group.
97 ///
98 /// The repeating group represents an array of repeating group instances,
99 /// So, the class exposes corresponding services to manipulate an array
100 /// of repeating group instances. Similar to the OnixS::FIX::GroupInstance
101 /// it behaves like a pointer/reference to the underlying data. It's
102 /// a light-weight object which just wraps internal data.
103 ///
104 /// The group remains valid until the corresponding field (which defines
105 /// the size/length of the repeating group) from field-set (a message or an outer
106 /// repeating group instance) is updated.
108 {
109 public:
110  /// The group which refers to nothing.
111  Group();
112 
113  /// Initializes an instance as a reference to the given repeating group.
114  Group(const Group & other);
115 
116  /// Indicated whether the group refers to a valid instance.
117  bool valid() const;
118 
119  /// Return the number of instances in the repeating group.
120  ///
121  /// @warning Due to performance considerations,
122  /// instance is not checked for validness. The member
123  /// must be used only when an instance is in the valid state.
124  size_t size() const;
125 
126  /// Accesses to the repeating group instance.
127  ///
128  /// @throw std::exception If the index exceeds allowed bounds.
129  ///
130  /// @warning Due to performance considerations,
131  /// instance is not checked for validness. The member
132  /// must be used only when an instance is in the valid state.
133  GroupInstance at(size_t index);
134 
135  /// Accesses to the repeating group instance.
136  ///
137  /// @throw std::exception If the index exceeds allowed bounds.
138  ///
139  /// @warning Due to performance considerations,
140  /// instance is not checked for validness. The member
141  /// must be used only when an instance is in the valid state.
142  const GroupInstance at(size_t index) const;
143 
144  /// Accesses to the repeating group instance.
145  ///
146  /// Does NOT check the index validness.
147  ///
148  /// @warning Due to performance considerations,
149  /// instance is not checked for validness. The member
150  /// must be used only when an instance is in the valid state.
151  GroupInstance operator [](size_t index);
152 
153  /// Accesses to the repeating group instance.
154  ///
155  /// Does NOT check the index validness.
156  ///
157  /// @warning Due to performance considerations,
158  /// instance is not checked for validness. The member
159  /// must be used only when an instance is in the valid state.
160  const GroupInstance operator [](size_t index) const;
161 
162  /// Reinitializes the instance as a reference to other one.
163  Group & operator = (const Group & other);
164 
165  /// Swaps two instances.
166  void swap(Group & other);
167 
168  /// Returns the string representation of the group using
169  /// the given delimiter.
170  ///
171  /// @param delimiter Defines the field delimiter to be used.
172  std::string toString(char delimiter = 0x1) const;
173 
174  /// Appends the string representation of the message using
175  /// the given delimiter.
176  ///
177  /// @param str The string to which the presentation is appended.
178  /// @param delimiter Defines the field delimiter to be used.
179  void toString(std::string & str, char delimiter = 0x1) const;
180 
181  /// The mutable iterator to iterate over all group instances in the repeating group.
183  {
184  public:
185 
186  typedef std::forward_iterator_tag iterator_category;
188  typedef std::ptrdiff_t difference_type;
191 
192  /// Initializes the iterator by a first group instance from which you need to iterate.
193  Iterator(Group *, size_t);
194 
195  GroupInstance & operator *() {
196  return currentGroupInstance_;
197  }
198 
199  GroupInstance * operator ->() {
200  return &currentGroupInstance_;
201  }
202 
203  bool operator == (const Iterator &) const;
204  bool operator != (const Iterator &) const;
205 
206  Iterator & operator ++();
207 
208  private:
209  /// The group instance to iterate.
210  Group * container_;
211 
212  /// The current group instance index.
213  size_t currentGroupInstanceIndex_;
214 
215  /// The current group instance.
216  GroupInstance currentGroupInstance_;
217  };
218 
219  /// Returns the iterator to the first group instance in the group.
220  Iterator begin();
221 
222  /// Returns the iterator to the group instance after the last one in the group.
223  Iterator end();
224 
225 private:
226  friend class MessageOperator;
227 
228  void * impl_;
229 
230  const Message * container_;
231 
232  Group(const Message *, void *);
233 };
234 
235 inline
236 std::string Group::toString(char delimiter) const
237 {
238  std::string str;
239 
240  toString(str, delimiter);
241 
242  return str;
243 }
244 
245 /// Stream output.
247 std::ostream & operator << (std::ostream & os, const Group & group);
248 
249 /// Stream output.
251 std::ostream & operator << (std::ostream & os, const GroupInstance & instance);
252 
253 }
254 }
The single instance of the FIX Repeating Group.
Definition: Group.h:37
ONIXS_FIXENGINE_API std::ostream & operator<<(std::ostream &os, const Group &group)
Stream output.
void swap(FieldSet &)
Encapsulates primary operations over the collection of FIX fields like a FIX message and a repeating ...
Definition: FieldSet.h:62
std::ptrdiff_t difference_type
Definition: Group.h:188
Encapsulates operations over the FIX Repeating Group.
Definition: Group.h:107
std::forward_iterator_tag iterator_category
Definition: Group.h:186
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
GroupInstance & operator=(const GroupInstance &)
Reinitializes an instance as reference of other one.
Definition: Group.h:74
const Message * container_
Definition: FieldSet.h:760
friend class MessageOperator
Definition: Group.h:68
The mutable iterator to iterate over all group instances in the repeating group.
Definition: Group.h:182
GroupInstance * pointer
Definition: Group.h:189
GroupInstance value_type
Definition: Group.h:187
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
ConstIterator begin() const
Returns the constant iterator to the first field in the FieldSet instance.
std::string toString(char delimiter=0x1) const
Returns the string representation of the group instance using the given delimiter.
Definition: Group.h:87
bool operator==(const FieldValueRef &ref, const std::string &str)
std::string toString(char delimiter=0x1) const
Returns the string representation of the group using the given delimiter.
Definition: Group.h:236
Encapsulates operations over a FIX Message.
Definition: Message.h:49
bool valid() const
Indicates whether an instance refers to a valid set of fields.
GroupInstance & reference
Definition: Group.h:190
ConstIterator end() const
Returns the constant iterator to the field after the last one in the FieldSet instance.
void swap(GroupInstance &)
Swaps two instances.
Definition: Group.h:81
bool operator!=(const FieldValueRef &ref, const std::string &str)