Files
2024-09-23 12:00:04 -04:00

197 lines
4.9 KiB
C++

/*
* 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 <cstdlib>
namespace OnixS {
namespace FIX {
namespace Core {
namespace Messaging {
namespace Extras {
class FlatMessage;
}
}
}
struct KnownFlatFieldKeys;
/// Represents a temporary reference to a field in an editable serialized message.
///
/// @note Reference remains valid since the moment it is obtained till the moment any other field of the same Serialized message is modified.
class FlatFieldRef
{
public:
/// Initializes as a references to nothing.
FlatFieldRef()
: valueOffset_(0),
valueSize_(0) {
}
/// Message only should use this constructor to initialize a valid reference.
FlatFieldRef(size_t valueOffset, size_t valueSize)
: valueOffset_(valueOffset), valueSize_(valueSize) {
}
/// Gets value offset.
size_t valueOffset() const {
return valueOffset_;
}
/// Gets value size.
size_t valueSize() const {
return valueSize_;
}
/// Indicates whether the instance refers to the field or not.
operator bool() const {
return (0 != valueOffset_);
}
/// Compares the instance with the given one.
bool
operator == (
const FlatFieldRef & other) const {
return (
valueOffset_ == other.valueOffset_ &&
valueSize_ == other.valueSize_);
}
/// Compares the instance with the given one.
bool
operator != (
const FlatFieldRef & other) const {
return (
valueOffset_ != other.valueOffset_ ||
valueSize_ != other.valueSize_);
}
private:
friend
class
OnixS::FIX::Core::Messaging::Extras::
FlatMessage;
size_t valueOffset_;
size_t valueSize_;
};
typedef FlatFieldRef SerializedFieldRef;
/// Key to a serialized field - represents another way of accessing fields in an editable serialized message.
///
/// In contrast to FlatFieldRef, FlatFieldKey remains constant and valid during all the life of serialized message object.
/// So they are suitable in case of multiple modifications of the same field.
class FlatFieldKey
{
public:
/// Initializes as a non-valid key.
FlatFieldKey()
: key_(static_cast<size_t>(-1)) {
}
// Initializes valid key.
explicit FlatFieldKey(size_t key)
: key_(key) {
}
/// Implicit conversion to the index value.
operator size_t() const {
return key_;
}
/// Compares to the given instance.
bool
operator ==(
const FlatFieldKey & other) const {
return (key_ == other.key_);
}
/// Compares to the given instance.
bool
operator !=(
const FlatFieldKey & other) const {
return (key_ != other.key_);
}
private:
friend
class
OnixS::FIX::Core::Messaging::Extras::
FlatMessage;
friend
struct
KnownFlatFieldKeys;
// Numeric value of the key.
size_t key_;
};
typedef FlatFieldKey SerializedFieldKey;
/// Keys are constant during the serialized message lifetime.
/// However, keys are allocated privately by each particular
/// message instance and thus may differ for same fields in
/// different instances. For commonly used fields, there are
/// pre-allocated keys which are same for all messages.
struct KnownFlatFieldKeys {
/// Key to access the BodyLength field.
static
FlatFieldKey
bodyLength() {
return FlatFieldKey(0);
}
/// Key to access the MsgType field.
static
FlatFieldKey
msgType() {
return FlatFieldKey(1);
}
/// Key to access the MsgSeqNum field.
static
FlatFieldKey
seqNumber() {
return FlatFieldKey(2);
}
/// Key to access the SendingTime field.
static
FlatFieldKey
sendingTime() {
return FlatFieldKey(3);
}
/// Value of the first key to be allocated dynamically.
static
FlatFieldKey
dynamic() {
return FlatFieldKey(4);
}
};
typedef KnownFlatFieldKeys KnownSerializedFieldKeys;
}
}