OnixS C++ CME MDP Conflated UDP Handler 1.1.2
API documentation
Loading...
Searching...
No Matches
MultiContainer.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
23#include <cassert>
24
25#include <vector>
26#include <algorithm>
27
30
32
35{
36 Tag tag_;
37 StrRef value_;
38
39public:
41 typedef StrRef Value;
42
46 : tag_(0), value_()
47 {
48 }
49
53 Tag tag,
54 const Value& value)
55 : tag_(tag)
56 , value_(value)
57 {
58 }
59
61 Tag tag() const
62 {
63 return tag_;
64 }
65
67 void
69 Tag tag)
70 {
71 tag_ = tag;
72 }
73
75 const Value& value() const
76 {
77 return value_;
78 }
79
81 void
83 const Value& value)
84 {
85 value_ = value;
86 }
87
89 void
91 const Char* data,
92 size_t size)
93 {
94 value_.reset(data, size);
95 }
96};
97
99ONIXS_CONFLATEDUDP_EXPORTED
100void
102 std::string&,
103 const TagValue&);
104
106inline
107std::string
109 const TagValue& tagValue)
110{
111 std::string str;
112
113 toStr(str, tagValue);
114
115 return str;
116}
117
118//
119
121typedef
122std::vector<TagValue>
124
126typedef
127TagValues::iterator
129
131typedef
132TagValues::const_iterator
134
135//
136
140{
141 Tag tag_;
142
143public:
145 explicit
147 Tag tag)
148 : tag_(tag)
149 {
150 }
151
154 bool
155 operator ()(
156 const TagValue& tagValue) const
157 {
158 return (
159 tagValue.tag() ==
160 tag_);
161 }
162};
163
164//
165
169{
170 const TagValues* container_;
172
173public:
176 : container_(NULL)
177 , ref_()
178 {
179 }
180
184 const TagValues& container,
185 Tag selection)
186 : container_(
187 &container)
188 , ref_(
189 std::find_if(
190 container.begin(),
191 container.end(),
192 TagValueSelector(selection)))
193 {
194 }
195
198 operator bool() const
199 {
200 return (
201 container_ &&
202 ref_ != container_->end());
203 }
204
207 const TagValue& operator *() const
208 {
209 assert(static_cast<bool>(*this));
210
211 return *ref_;
212 }
213
219 operator ++()
220 {
221 assert(static_cast<bool>(*this));
222
223 const Tag selection = ref_->tag();
224
225 ref_ =
226 std::find_if
227 (
228 ++ref_,
229 container_->end(),
230 TagValueSelector(selection)
231 );
232
233 return *this;
234 }
235};
236
237//
238
248{
249 TagValues tagValues_;
250
251 // Builds sequence of tag-value pairs
252 // from the given FIX (tag=value) string.
254 static
255 void
256 deserialize(
257 TagValues&,
258 const Char*,
259 size_t);
260
261public:
264 typedef Tag Key;
265
268
270 typedef
271 TagValues::const_iterator
273
275 typedef
278
281 {
282 }
283
286 {
287 }
288
292 {
293 return tagValues_.begin();
294 }
295
298 Iterator end() const
299 {
300 return tagValues_.end();
301 }
302
306 Iterator
308 Key tag) const
309 {
310 return std::find_if
311 (
312 tagValues_.begin(),
313 tagValues_.end(),
315 );
316 }
317
320 SelectionIterator
322 Key tag) const
323 {
324 return
326 (
327 tagValues_,
328 tag
329 );
330 }
331
334 void
336 const Char* fixStr,
337 size_t fixSize)
338 {
339 tagValues_.clear();
340
341 deserialize
342 (
343 tagValues_,
344 fixStr,
345 fixSize
346 );
347 }
348};
349
352inline
353MultiContainer::Value
355 const MultiContainer& container,
356 Tag tag,
357 const
359 defaultValue =
361{
362 const
364 result =
365 container.first(tag);
366
367 if (result !=
368 container.end())
369 {
370 return result->value();
371 }
372
373 return defaultValue;
374}
375
382template
383<
384 class Number
385>
386bool
388 Number& number,
389 const MultiContainer& container,
390 Tag tag)
391{
392 const
394 strValue =
396 container,
397 tag);
398
399 return fromStr
400 (
401 number,
402 strValue.items(),
403 strValue.size()
404 );
405}
406
414template
415<
416 class Number
417>
418bool
420 Number& number,
421 const MultiContainer& container,
422 Tag tag, Number defaultValue = Number())
423{
424 const
426 strValue =
428 container,
429 tag);
430
431 if (strValue.empty())
432 {
433 number = defaultValue;
434
435 return true;
436 }
437
438 return fromStr
439 (
440 number,
441 strValue.items(),
442 strValue.size()
443 );
444}
445
446//
447
449ONIXS_CONFLATEDUDP_EXPORTED
450void
452 std::string&,
453 const MultiContainer&);
454
456inline
457std::string
459 const MultiContainer& container)
460{
461 std::string str;
462
463 toStr(str, container);
464
465 return str;
466}
467
468//
469
#define ONIXS_CONFLATEDUDP_LTWT_EXPORTED
Definition Bootstrap.h:103
#define ONIXS_CONFLATEDUDP_LTWT_CLASS
Definition Bootstrap.h:95
#define ONIXS_CONFLATEDUDPFIX_NAMESPACE_BEGIN
Definition Bootstrap.h:161
#define ONIXS_CONFLATEDUDPFIX_NAMESPACE_END
Definition Bootstrap.h:165
MultiContainer()
Initializes an empty instance.
SelectionIterator all(Key tag) const
void deserialize(const Char *fixStr, size_t fixSize)
TagValueSelectionIterator SelectionIterator
Iterator over items having the same tag value.
TagValues::const_iterator Iterator
Iterator over container items.
TagValue::Value Value
Alias for value type.
Iterator over tag-value pairs having the same tag value.
TagValueSelectionIterator(const TagValues &container, Tag selection)
TagValueSelectionIterator()
Initializes the interator pointing to nothing.
TagValueSelector(Tag tag)
Initializes functor with the given tag.
Represents a pair of a tag and a value.
void value(const Char *data, size_t size)
Updates value component.
Tag tag() const
Tag component of the pair.
StrRef Value
Alias for the value type.
void value(const Value &value)
Updates value component.
TagValue(Tag tag, const Value &value)
void tag(Tag tag)
Updates tag component.
const Value & value() const
Value component of the pair.
const Char * items() const
Read-only content.
Definition String.h:86
size_t size() const
Number of chars.
Definition String.h:92
bool empty() const
Indicates whether the referenced text is empty.
Definition String.h:80
void toStr(std::string &str, const Message &message)
Serializes FIX message into tag=value format.
Definition Message.h:379
TagValues::const_iterator TagValueConstIterator
Constant iterator over the tag-value sequence.
std::vector< TagValue > TagValues
Sequence of tag-value pairs.
TagValues::iterator TagValueIterator
Iterator over the tag-value sequence.
MultiContainer::Value valueOrDefault(const MultiContainer &container, Tag tag, const MultiContainer::Value &defaultValue=MultiContainer::Value())
bool value(Number &number, const MultiContainer &container, Tag tag)
ONIXS_CONFLATEDUDP_EXPORTED bool fromStr(Decimal &, const Char *, size_t)
char Char
Character type alias.
Definition String.h:36