OnixS CME Drop Copy Handler C++ library 5.7.1
API documentation
Loading...
Searching...
No Matches
Messaging.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 protected by copyright law
4// and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable OnixS Software
7// Services Agreement (the Agreement) and Customer end user license agreements granting
8// a non-assignable, non-transferable and non-exclusive license to use the software
9// for it's own data processing purposes under the terms defined in the Agreement.
10//
11// Except as otherwise granted within the terms of the Agreement, copying or reproduction of any
12// part of this source code or associated reference material to any other location for further
13// reproduction or redistribution, and any amendments to this copyright notice, are expressly
14// 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 "OnixS/CME/DropCopy/Export.h"
27
28namespace OnixS { namespace CME { namespace DropCopy {
29
30class Message;
31class Group;
32class MessageOperator;
33
39class ONIXS_CME_DROP_COPY_EXPORT FieldValueRef
40{
41public:
44
47
50 operator bool() const;
51
54 operator std::string() const;
55
57 bool operator==(const FieldValueRef&) const;
58
60 bool operator!=(const FieldValueRef&) const;
61
64 bool operator==(const StringRef&) const;
65
68 bool operator!=(const StringRef&) const;
69
77 bool toNumber(Int32&) const;
78
86 bool toNumber(UInt32&) const;
87
95 bool toNumber(Int64&) const;
96
104 bool toNumber(UInt64&) const;
105
113 bool toNumber(Decimal&) const;
114
123
133 bool toStringRef(StringRef&) const;
134
143 bool toChar(char&) const;
144
149 bool toGroup(Group&) const;
150
153 void toString(std::string&) const;
154
156 std::string toString() const;
157
162
163private:
164 friend class MessageOperator;
165
166 const void* impl_;
167 const Message* container_;
168
169 FieldValueRef(const Message*, const void*);
170};
171
172inline FieldValueRef::operator std::string() const
173{
174 std::string str;
175 toString(str);
176 return str;
177}
178
179inline std::string FieldValueRef::toString() const
180{
181 std::string str;
182 toString(str);
183 return str;
184}
185
186// More comparison operators.
187
188inline bool operator==(const FieldValueRef& ref, const std::string& str)
189{
190 return ref == StringRef(str);
191}
192
193inline bool operator!=(const FieldValueRef& ref, const std::string& str)
194{
195 return ref != StringRef(str);
196}
197
198inline bool operator==(const std::string& str, const FieldValueRef& ref)
199{
200 return ref == StringRef(str);
201}
202
203inline bool operator!=(const std::string& str, const FieldValueRef& ref)
204{
205 return ref != StringRef(str);
206}
207
208// More comparison operators.
209
210inline bool operator==(const FieldValueRef& ref, const char* str)
211{
212 return ref == StringRef(str);
213}
214
215inline bool operator!=(const FieldValueRef& ref, const char* str)
216{
217 return ref != StringRef(str);
218}
219
220inline bool operator==(const char* str, const FieldValueRef& ref)
221{
222 return ref == StringRef(str);
223}
224
225inline bool operator!=(const char* str, const FieldValueRef& ref)
226{
227 return ref != StringRef(str);
228}
229
232class ONIXS_CME_DROP_COPY_EXPORT FieldSet
233{
234public:
239 operator bool() const;
240
252
262 char getChar(Tag tag) const;
263
273 Int32 getInt32(Tag tag) const;
274
284 UInt32 getUInt32(Tag tag) const;
285
295 Int64 getInt64(Tag tag) const;
296
306 UInt64 getUInt64(Tag tag) const;
307
318
329
340
349 Group getGroup(Tag tag) const;
350
364 Group getOptionalGroup(Tag tag, bool strict = true) const;
365
373 bool hasFlag(Tag tag) const;
374
378 bool contain(Tag tag) const;
379
380protected:
381 // Underlying implementation.
382 const void* impl_;
383
384 // Message to which given set belongs to.
386
387 // Full details initialization.
388 FieldSet(const Message*, const void*);
389
390 // Clone construction.
392
393 // Destruction available via descendants.
395
397
398private:
399 friend class Message;
400 friend class GroupInstance;
401 friend class MessageOperator;
402};
403
404template <typename Enumeration>
405inline typename Enumeration::Enum getIntEnumFieldValue(const FieldSet& fieldSet, Tag tag)
406{
407 UInt32 value = 0;
408 FieldValueRef valueRef = fieldSet.get(tag);
409
410 return (valueRef && valueRef.toNumber(value)) ? static_cast<typename Enumeration::Enum>(value)
411 : Enumeration::Undefined;
412}
413
414template <typename Enumeration>
415inline typename Enumeration::Enum getCharEnumFieldValue(const FieldSet& fieldSet, Tag tag)
416{
417 char value = 0;
418 FieldValueRef valueRef = fieldSet.get(tag);
419
420 return (valueRef && valueRef.toChar(value)) ? static_cast<typename Enumeration::Enum>(value)
421 : Enumeration::Undefined;
422}
423
424inline bool getDate(const FieldSet& fieldSet, Tag tag, Timestamp& date)
425{
426 UInt64 value;
427
428 if (fieldSet.get(tag).toNumber(value))
429 {
431 return true;
432 }
433
434 return false;
435}
436
443class ONIXS_CME_DROP_COPY_EXPORT GroupInstance : public FieldSet
444{
445public:
448
451
454
462 const Message& message() const;
463
464private:
465 friend class MessageOperator;
466
467 GroupInstance(const Message*, const void*);
468};
469
470inline const Message& GroupInstance::message() const
471{
472 return *container_;
473}
474
486class ONIXS_CME_DROP_COPY_EXPORT Group
487{
488public:
491
493 Group(const Group& other);
494
496 operator bool() const;
497
503 size_t size() const;
504
512 const GroupInstance at(size_t index) const;
513
521 const GroupInstance operator[](size_t index) const;
522
524 Group& operator=(const Group& other);
525
533 const Message& message() const;
534
535private:
536 friend class MessageOperator;
537
538 const void* impl_;
539
540 const Message* container_;
541
542 Group(const Message*, const void*);
543};
544
545inline const Message& Group::message() const
546{
547 return *container_;
548}
549
550template <typename Entry>
552{
553public:
557 {
558 }
559
561 size_t size() const
562 {
563 return underlyingGroup_ ? underlyingGroup_.size() : 0;
564 }
565
567 bool empty() const
568 {
569 return 0 == size();
570 }
571
575 Entry operator[](size_t index) const
576 {
577 return Entry(underlyingGroup_[index]);
578 }
579
583 Entry at(size_t index) const
584 {
585 if (index < size())
586 {
587 return Entry(underlyingGroup_[index]);
588 }
589
590 throw std::out_of_range("Index");
591 }
592
593protected:
594 TypedGroup(const Group& group)
595 : underlyingGroup_(group)
596 {
597 }
598
600};
601
603struct ONIXS_CME_DROP_COPY_EXPORT MessageStringingFlag
604{
606 enum Enum
607 {
610
613
616 };
617};
618
620typedef unsigned MessageStringingFlags;
621
633class ONIXS_CME_DROP_COPY_EXPORT Message : public FieldSet
634{
635public:
638
642 Message(const Message& other);
643
650
653
658
663
666 const Timestamp& receiveTime() const;
667
672 std::string toString(char delimiter = 0x1) const;
673
679 void toString(std::string& str, char delimiter = 0x1) const;
680
681 // Reassigns message as copy of other one.
683
684private:
685 friend class MessageOperator;
686
687 Message(const void* core, const Timestamp& receiveTime);
688
689private:
690 const void* core_;
691 Timestamp receiveTime_;
692};
693
694inline std::string Message::toString(char delimiter) const
695{
696 std::string str;
697 toString(str, delimiter);
698 return str;
699}
700
702class ONIXS_CME_DROP_COPY_EXPORT BitmapField
703{
704public:
706
709 : bits_(bits)
710 {
711 }
712
714 BitmapField(const FieldSet& msg, Tag tag)
715 : bits_(0)
716 {
717 msg.get(tag).toNumber(bits_);
718 }
719
720protected:
721 bool state(BaseType bit) const
722 {
723 return (bits_ >> bit) & 1;
724 }
725
726 bool any() const
727 {
728 return bits_ != 0;
729 }
730
732 {
733 return bits_;
734 }
735
736private:
737 BaseType bits_;
738};
739
740}}}
741
742namespace std {
743
744// Outputs message into standard stream.
745ONIXS_CME_DROP_COPY_EXPORT std::ostream&
746operator<<(std::ostream&, const OnixS::CME::DropCopy::Message&);
747
748}
bool state(BaseType bit) const
Definition Messaging.h:721
BitmapField(const FieldSet &msg, Tag tag)
Initializes bitmap field instance from FIX field set.
Definition Messaging.h:714
BitmapField(BaseType bits=0)
Initializes bitmap field instance with explicit value.
Definition Messaging.h:708
Decimal type for better precision.
Definition Numeric.h:45
UInt32 getUInt32(Tag tag) const
Int32 getInt32(Tag tag) const
bool hasFlag(Tag tag) const
FieldSet & operator=(const FieldSet &)
Group getGroup(Tag tag) const
Timestamp getTimestamp(Tag tag, SinceEpochUnit unit) const
Decimal getDecimal(Tag tag) const
UInt64 getUInt64(Tag tag) const
StringRef getStringRef(Tag tag) const
char getChar(Tag tag) const
bool contain(Tag tag) const
Int64 getInt64(Tag tag) const
FieldValueRef get(Tag tag) const
FieldSet(const Message *, const void *)
Group getOptionalGroup(Tag tag, bool strict=true) const
FieldValueRef(const FieldValueRef &)
Shallow copy from another one.
bool operator!=(const StringRef &) const
bool toStringRef(StringRef &) const
bool operator==(const StringRef &) const
std::string toString() const
Return string presentation of field value.
Definition Messaging.h:179
bool toNumber(Decimal &) const
bool operator!=(const FieldValueRef &) const
Compares with another instance for inequality.
FieldValueRef()
Uninitialized value.
bool operator==(const FieldValueRef &) const
Compares with another instance for equality.
void toString(std::string &) const
FieldValueRef & operator=(const FieldValueRef &)
bool toTimestamp(Timestamp &, SinceEpochUnit) const
GroupInstance & operator=(const GroupInstance &)
Reinitializes instance as reference of other one.
GroupInstance()
Initializes instance referencing to nothing.
GroupInstance(const GroupInstance &other)
Initializes instance as reference to the other one.
const Message & message() const
Definition Messaging.h:470
Group()
Initializes instance as referred to nothing.
Group & operator=(const Group &other)
Reinitializes instance as reference to other one.
const GroupInstance at(size_t index) const
const GroupInstance operator[](size_t index) const
Group(const Group &other)
Initializes instance as reference to given repeating group.
const Message & message() const
Definition Messaging.h:545
FieldValueRef type() const
Returns the message type (MsgType(35) field value).
Timestamp sendingTime() const
SequenceNumber sequenceNumber() const
const Timestamp & receiveTime() const
Message(const Message &other)
std::string toString(char delimiter=0x1) const
Definition Messaging.h:694
void toString(std::string &str, char delimiter=0x1) const
Message & operator=(const Message &)
Message()
Initializes message in 'unconstructed' state.
Provides efficient way of accessing text-based FIX field values.
Definition String.h:324
Represents timestamp without time-zone information.
Definition Time.h:438
static Timestamp fromUnixTimestamp(UInt64 sinceEpoch, SinceEpochUnit unit)
size_t size() const
Return number of instances in repeating group.
Definition Messaging.h:561
Entry at(size_t index) const
Definition Messaging.h:583
bool empty() const
Indicates whether set has an entries.
Definition Messaging.h:567
TypedGroup()
Initializes set with no entries.
Definition Messaging.h:555
Entry operator[](size_t index) const
Definition Messaging.h:575
TypedGroup(const Group &group)
Definition Messaging.h:594
SinceEpochUnits::Enum SinceEpochUnit
Since epoch units format.
Definition Time.h:434
Enumeration::Enum getIntEnumFieldValue(const FieldSet &fieldSet, Tag tag)
Definition Messaging.h:405
bool getDate(const FieldSet &fieldSet, Tag tag, Timestamp &date)
Definition Messaging.h:424
unsigned int UInt32
Definition Numeric.h:33
long long Int64
Definition Numeric.h:35
unsigned int Tag
FIX message field identifying/indexing type.
Definition Types.h:31
bool operator==(const FieldValueRef &ref, const std::string &str)
Definition Messaging.h:188
unsigned long long UInt64
Definition Numeric.h:36
Enumeration::Enum getCharEnumFieldValue(const FieldSet &fieldSet, Tag tag)
Definition Messaging.h:415
unsigned int SequenceNumber
Alias for message/packet sequence number.
Definition Types.h:28
bool operator!=(const FieldValueRef &ref, const std::string &str)
Definition Messaging.h:193
unsigned MessageStringingFlags
Collection of message stringing flags.
Definition Messaging.h:620
STL namespace.
std::ostream & operator<<(std::ostream &, const OnixS::CME::DropCopy::Error &)
Contains flags which affect FIX message textual presentation.
Definition Messaging.h:604
Enum
Flags which affect FIX message textual presentation.
Definition Messaging.h:607
@ NoFieldInfo
Only field values are serialized.
Definition Messaging.h:609
@ IncludeFieldName
Field names are included during serialization.
Definition Messaging.h:615
@ IncludeFieldTagNumber
Field tag numbers are included during serialization.
Definition Messaging.h:612