/* * 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 #include namespace OnixS { namespace FIX { ONIXS_FIXENGINE_API_DECL(class, FlatMessage); ONIXS_FIXENGINE_API_DECL(class, FlatGroup); /// A single instance of the FIX Repeating Group. Provides an access /// to the fields of a particular repeating group instance. class ONIXS_FIXENGINE_API FlatGroupInstance { public: /// Looks for a field using the given tag number. /// @return A valid reference in case of success, otherwise - an invalid one. FlatFieldRef find(Tag) const; /// Provides an access to a field value by the given temporary reference. StringRef operator[](const FlatFieldRef &) const; /// Returns the reference to a repeating group - if exists. /// /// @param numberOfInstancesRef A reference of /// the field that defines the number of instances /// in this repeating group (the NoXXX field). /// /// @throw std::exception if the given field does not contain the number of instances. FlatGroup getGroup(const FlatFieldRef & numberOfInstancesRef) const; private: friend class MessageOperator; FlatGroupInstance(const FlatMessage *, const StringRef &, const FlatGroupInstance * parent); FlatGroupInstance(const FlatMessage *, const FlatGroupInstance *, const FlatGroupInstance * parent); const FlatMessage * container_; Tag parentLeadingTag_; FlatField leadingField_; }; /// Encapsulates operations over the FIX Repeating Group. /// /// The repeating group represents an array of repeating group instances, /// This class exposes corresponding services to manipulate the array /// of repeating group instances. Similar to the OnixS::FIX::FlatGroupInstance /// it behaves like a pointer/reference to the underlying data. It's /// a light-weight object which just wraps the internal data. /// /// The group remains valid until corresponding group fields are updated. class ONIXS_FIXENGINE_API FlatGroup { public: /// Returns the number of instances in the repeating group. size_t size() const { return groupSize_; } /// Returns the StringRef value of the repeating group field. StringRef groupFieldValue() const { return groupFieldValue_; } /// The constant iterator to iterate over all group instances in the repeating group. class ONIXS_FIXENGINE_API ConstIterator { public: typedef std::forward_iterator_tag iterator_category; typedef FlatGroupInstance value_type; typedef FlatGroupInstance difference_type; typedef FlatGroupInstance * pointer; typedef FlatGroupInstance & reference; /// Initializes an iterator by a first group instance from which you need to iterate. ConstIterator(const FlatGroup *, size_t); const FlatGroupInstance & operator*() const { return currentGroupInstance_; } const FlatGroupInstance * operator->() const { return ¤tGroupInstance_; } bool operator == (const ConstIterator &) const; bool operator != (const ConstIterator &) const; ConstIterator & operator ++(); private: /// The FlatMessage instance to iterate. const FlatGroup * container_; /// The current group instance index. size_t currentGroupInstanceIndex_; /// The current group instance. FlatGroupInstance currentGroupInstance_; }; /// Returns the iterator to the first group instance in the group. ConstIterator begin() const; /// Returns the iterator to the group instance after the last one in the group. ConstIterator end() const; private: friend class MessageOperator; FlatGroup(const FlatMessage *, FlatFieldRef, const FlatGroupInstance *); const FlatMessage * container_; const FlatGroupInstance * parent_; StringRef groupFieldValue_; size_t groupSize_; }; } }