/* * Copyright Onix Solutions Limited [OnixS]. All rights reserved. * * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law * and international copyright treaties. * * Access to and use of the software is governed by the terms of the applicable OnixS Software * Services Agreement (the Agreement) and Customer end user license agreements granting * a non-assignable, non-transferable and non-exclusive license to use the software * for it's own data processing purposes under the terms defined in the Agreement. * * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part * of this source code or associated reference material to any other location for further reproduction * or redistribution, and any amendments to this copyright notice, are expressly prohibited. * * Any reproduction or redistribution for sale or hiring of the Software not in accordance with * the terms of the Agreement is a violation of copyright law. */ #pragma once #include #include namespace OnixS { namespace FIX { ONIXS_FIXENGINE_API_DECL(class, Message); ONIXS_FIXENGINE_API_DECL(class, Group); /// The single instance of the FIX Repeating Group. Provides an access /// to the fields of a particular repeating group instance. /// /// Class behaves like a pointer/reference to a set of FIX /// fields. Coping and assignment operations just update a reference /// to the field-set being pointed, no deep copying is performed. class ONIXS_FIXENGINE_API GroupInstance : public FieldSet { public: /// The group instance which refers to nothing. GroupInstance(); /// Initializes an instance as a reference to the other one. GroupInstance(const GroupInstance & other); /// Reinitializes an instance as reference of other one. GroupInstance & operator = (const GroupInstance &); /// Swaps two instances. void swap(GroupInstance &); /// Returns the string representation of the group instance using /// the given delimiter. /// /// @param delimiter Defines the field delimiter to be used. std::string toString(char delimiter = 0x1) const; /// Appends a string representation of the group instance using /// the given delimiter. /// /// @param str The string to which the presentation is appended. /// @param delimiter Defines the field delimiter to be used. void toString(std::string & str, char delimiter = 0x1) const; private: friend class MessageOperator; GroupInstance(const Message *, void *); }; inline GroupInstance & GroupInstance::operator =(const GroupInstance & other) { *static_cast
(this) = static_cast(other); return *this; } inline void GroupInstance::swap(GroupInstance & other) { FieldSet::swap(static_cast
(other)); } inline std::string GroupInstance::toString(char delimiter) const { std::string str; toString(str, delimiter); return str; } /// Encapsulates operations over the FIX Repeating Group. /// /// The repeating group represents an array of repeating group instances, /// So, the class exposes corresponding services to manipulate an array /// of repeating group instances. Similar to the OnixS::FIX::GroupInstance /// it behaves like a pointer/reference to the underlying data. It's /// a light-weight object which just wraps internal data. /// /// The group remains valid until the corresponding field (which defines /// the size/length of the repeating group) from field-set (a message or an outer /// repeating group instance) is updated. class ONIXS_FIXENGINE_API Group { public: /// The group which refers to nothing. Group(); /// Initializes an instance as a reference to the given repeating group. Group(const Group & other); /// Indicated whether the group refers to a valid instance. bool valid() const; /// Return the number of instances in the repeating group. /// /// @warning Due to performance considerations, /// instance is not checked for validness. The member /// must be used only when an instance is in the valid state. size_t size() const; /// Accesses to the repeating group instance. /// /// @throw std::exception If the index exceeds allowed bounds. /// /// @warning Due to performance considerations, /// instance is not checked for validness. The member /// must be used only when an instance is in the valid state. GroupInstance at(size_t index); /// Accesses to the repeating group instance. /// /// @throw std::exception If the index exceeds allowed bounds. /// /// @warning Due to performance considerations, /// instance is not checked for validness. The member /// must be used only when an instance is in the valid state. const GroupInstance at(size_t index) const; /// Accesses to the repeating group instance. /// /// Does NOT check the index validness. /// /// @warning Due to performance considerations, /// instance is not checked for validness. The member /// must be used only when an instance is in the valid state. GroupInstance operator [](size_t index); /// Accesses to the repeating group instance. /// /// Does NOT check the index validness. /// /// @warning Due to performance considerations, /// instance is not checked for validness. The member /// must be used only when an instance is in the valid state. const GroupInstance operator [](size_t index) const; /// Reinitializes the instance as a reference to other one. Group & operator = (const Group & other); /// Swaps two instances. void swap(Group & other); /// Returns the string representation of the group using /// the given delimiter. /// /// @param delimiter Defines the field delimiter to be used. std::string toString(char delimiter = 0x1) const; /// Appends the string representation of the message using /// the given delimiter. /// /// @param str The string to which the presentation is appended. /// @param delimiter Defines the field delimiter to be used. void toString(std::string & str, char delimiter = 0x1) const; /// The mutable iterator to iterate over all group instances in the repeating group. class ONIXS_FIXENGINE_API Iterator { public: typedef std::forward_iterator_tag iterator_category; typedef GroupInstance value_type; typedef GroupInstance difference_type; typedef GroupInstance * pointer; typedef GroupInstance & reference; /// Initializes the iterator by a first group instance from which you need to iterate. Iterator(Group *, size_t); GroupInstance & operator *() { return currentGroupInstance_; } GroupInstance * operator ->() { return ¤tGroupInstance_; } bool operator == (const Iterator &) const; bool operator != (const Iterator &) const; Iterator & operator ++(); private: /// The group instance to iterate. Group * container_; /// The current group instance index. size_t currentGroupInstanceIndex_; /// The current group instance. GroupInstance currentGroupInstance_; }; /// Returns the iterator to the first group instance in the group. Iterator begin(); /// Returns the iterator to the group instance after the last one in the group. Iterator end(); private: friend class MessageOperator; void * impl_; const Message * container_; Group(const Message *, void *); }; inline std::string Group::toString(char delimiter) const { std::string str; toString(str, delimiter); return str; } /// Stream output. ONIXS_FIXENGINE_API std::ostream & operator << (std::ostream & os, const Group & group); /// Stream output. ONIXS_FIXENGINE_API std::ostream & operator << (std::ostream & os, const GroupInstance & instance); } }