OnixS C++ FIX Engine  4.2.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 /// Single instance of FIX Repeating Group. Provides 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 reference
36 /// to the field-set being pointed, no deep copying is performed.
37 class
39  GroupInstance : public FieldSet
40 {
41 public:
42  /// Group instance which refers to nothing.
43  GroupInstance();
44 
45  /// Initializes instance as reference to the other one.
46  GroupInstance(const GroupInstance & other);
47 
48  /// Reinitializes 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 field delimiter to be used.
58  std::string toString(char delimiter = 0x1) const;
59 
60  /// Appends string representation of the group instance using
61  /// the given delimiter.
62  ///
63  /// @param str String to which presentation is appended.
64  /// @param delimiter Defines 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 FIX Repeating Group.
97 ///
98 /// Repeating group represents array of repeating group instances,
99 /// So, class exposes corresponding services to manipulate 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 /// Group remains valid until corresponding field (which defines
105 /// size/length of repeating group) from field-set (message or outer
106 /// repeating group instance) is updated.
108 {
109 public:
110  /// Group which refers to nothing.
111  Group();
112 
113  /// Initializes instance as reference to given repeating group.
114  Group(const Group & other);
115 
116  /// Indicated whether group refers to a valid instance.
117  operator bool() const;
118 
119  /// Return number of instances in repeating group.
120  ///
121  /// @warning Due to performance considerations,
122  /// instance is not checked for validness. Member
123  /// must be used only when instance is in valid state.
124  size_t size() const;
125 
126  /// Accesses to repeating group instance.
127  ///
128  /// @throw std::exception if If index exceeds allowed bounds.
129  ///
130  /// @warning Due to performance considerations,
131  /// instance is not checked for validness. Member
132  /// must be used only when instance is in valid state.
133  GroupInstance at(size_t index);
134 
135  /// Accesses to repeating group instance.
136  ///
137  /// @throw std::exception if If index exceeds allowed bounds.
138  ///
139  /// @warning Due to performance considerations,
140  /// instance is not checked for validness. Member
141  /// must be used only when instance is in valid state.
142  const GroupInstance at(size_t index) const;
143 
144  /// Accesses to repeating group instance.
145  ///
146  /// Does NOT check index validness.
147  ///
148  /// @warning Due to performance considerations,
149  /// instance is not checked for validness. Member
150  /// must be used only when instance is in valid state.
151  GroupInstance operator [](size_t index);
152 
153  /// Accesses to repeating group instance.
154  ///
155  /// Does NOT check index validness.
156  ///
157  /// @warning Due to performance considerations,
158  /// instance is not checked for validness. Member
159  /// must be used only when instance is in valid state.
160  const GroupInstance operator [](size_t index) const;
161 
162  /// Reinitializes instance as 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 field delimiter to be used.
172  std::string toString(char delimiter = 0x1) const;
173 
174  /// Appends string representation of the message using
175  /// the given delimiter.
176  ///
177  /// @param str String to which presentation is appended.
178  /// @param delimiter Defines field delimiter to be used.
179  void toString(std::string & str, char delimiter = 0x1) const;
180 
181  /// Mutable iterator to iterate over all group instances in the repeating group.
183  std::iterator<std::forward_iterator_tag, GroupInstance>
184  {
185  public:
186  /// Initializes iterator by a first group instance from which you need to iterate.
187  Iterator(Group *, size_t);
188 
189  GroupInstance & operator *() {
190  return currentGroupInstance_;
191  }
192 
193  GroupInstance * operator ->() {
194  return &currentGroupInstance_;
195  }
196 
197  bool operator == (const Iterator &) const;
198  bool operator != (const Iterator &) const;
199 
200  Iterator & operator ++();
201 
202  private:
203  /// Group instance to iterate.
204  Group * container_;
205 
206  /// Current group instance index.
207  size_t currentGroupInstanceIndex_;
208 
209  /// Current group instance.
210  GroupInstance currentGroupInstance_;
211  };
212 
213  /// Returns the iterator to the first group instance in the group.
214  Iterator begin();
215 
216  /// Returns the iterator to the group instance after the last one in the group.
217  Iterator end();
218 
219 private:
220  friend class MessageOperator;
221 
222  void * impl_;
223 
224  const Message * container_;
225 
226  Group(const Message *, void *);
227 };
228 
229 inline
230 std::string Group::toString(char delimiter) const
231 {
232  std::string str;
233 
234  toString(str, delimiter);
235 
236  return str;
237 }
238 
239 /// Stream output.
241 std::ostream & operator << (std::ostream & os, const Group & group);
242 
243 /// Stream output.
245 std::ostream & operator << (std::ostream & os, const GroupInstance & instance);
246 
247 }
248 }
void swap(GroupInstance &)
Swaps two instances.
Definition: Group.h:81
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
bool operator!=(const FieldValueRef &ref, const std::string &str)
friend class MessageOperator
Definition: Group.h:68
Encapsulates primary operations over collection of FIX fields like FIX message and repeating group in...
Definition: FieldSet.h:61
ONIXS_FIXENGINE_API std::ostream & operator<<(std::ostream &os, const Group &group)
Stream output.
std::string toString(char delimiter=0x1) const
Returns the string representation of the group instance using the given delimiter.
Definition: Group.h:87
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
Mutable iterator to iterate over all group instances in the repeating group.
Definition: Group.h:182
Encapsulates operations over FIX Repeating Group.
Definition: Group.h:107
GroupInstance & operator=(const GroupInstance &)
Reinitializes instance as reference of other one.
Definition: Group.h:74
ConstIterator begin() const
Returns the constant iterator to the first field in the FieldSet instance.
void swap(FieldSet &)
Single instance of FIX Repeating Group.
Definition: Group.h:37
const Message * container_
Definition: FieldSet.h:767
Encapsulates operations over a FIX Message.
Definition: Message.h:49
bool operator==(const FieldValueRef &ref, const std::string &str)
ConstIterator end() const
Returns the constant iterator to the field after the last one in the FieldSet instance.
std::string toString(char delimiter=0x1) const
Returns the string representation of the group using the given delimiter.
Definition: Group.h:230