335 lines
9.5 KiB
C++
335 lines
9.5 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 <OnixS/FIXEngine/FIX/StringRef.h>
|
|
#include <OnixS/FIXEngine/FIX/Timestamp.h>
|
|
|
|
namespace OnixS {
|
|
namespace FIX {
|
|
ONIXS_FIXENGINE_API_DECL(class, Message);
|
|
ONIXS_FIXENGINE_API_DECL(class, Group);
|
|
|
|
/// Implements a concept of a read-only
|
|
/// reference to a FIX field value.
|
|
class
|
|
ONIXS_FIXENGINE_API
|
|
FieldValueRef
|
|
{
|
|
public:
|
|
/// The uninitialized value.
|
|
FieldValueRef();
|
|
|
|
/// The shallow copy from another one.
|
|
FieldValueRef(const FieldValueRef & other);
|
|
|
|
/// Indicated whether the instance
|
|
/// refers to a valid value.
|
|
bool valid() const;
|
|
|
|
/// Return the string presentation
|
|
/// of the value being referenced.
|
|
operator std::string() const;
|
|
|
|
/// Compares with another instance for equality.
|
|
bool operator == (const FieldValueRef &) const;
|
|
|
|
/// Compares with another instance for inequality.
|
|
bool operator != (const FieldValueRef &) const;
|
|
|
|
/// Compares the string presentation for
|
|
/// equality with given text reference.
|
|
bool operator == (const StringRef &) const;
|
|
|
|
/// Compares the string presentation for
|
|
/// equality with the given text reference.
|
|
bool operator != (const StringRef &) const;
|
|
|
|
/// Converts the field value into the whole number.
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toNumber(Int32 &) const;
|
|
|
|
/// Converts the field value into the whole number.
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toNumber(UInt32 &) const;
|
|
|
|
/// Converts the field value into the whole number.
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toNumber(Int64 &) const;
|
|
|
|
/// Converts the field value into the whole number.
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toNumber(UInt64 &) const;
|
|
|
|
/// Converts the field value into the floating point value.
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toNumber(Double &) const;
|
|
|
|
/// Converts the field value into the floating point value.
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toNumber(Decimal &) const;
|
|
|
|
/// Converts the field value into the timestamp of the requested format.
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool
|
|
toTimestamp(
|
|
Timestamp &,
|
|
TimestampFormat::Enum =
|
|
TimestampFormat::YYYYMMDDHHMMSSNsec) const;
|
|
|
|
|
|
/// Converts the field value into the timespan
|
|
///
|
|
/// @return false if the conversion fails.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool
|
|
toTimeSpan(
|
|
TimeSpan&, TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSMsec) const;
|
|
|
|
/// If the value represents a text, returns a reference to it.
|
|
///
|
|
/// @return false if the conversion fails (for example,
|
|
/// the stored value is the whole number assigned to a field
|
|
/// using the OnixS::FIX::FieldSet::setV member), otherwise - true.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toStringRef(StringRef &) const;
|
|
|
|
/// If the value represents a text, returns a reference to it.
|
|
///
|
|
/// @return An empty StringRef if the conversion fails (for example,
|
|
/// the stored value is the whole number assigned to a field
|
|
/// using the OnixS::FIX::FieldSet::setV member), otherwise - valid StringRef.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
StringRef toStringRef() const;
|
|
|
|
/// If the value represent a one-char text,
|
|
/// copies it into the given variable.
|
|
///
|
|
/// @return false if the conversion fails (for example,
|
|
/// the stored value is the whole number assigned to a field
|
|
/// using the OnixS::FIX::FieldSet::setV member).
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toChar(char &) const;
|
|
|
|
/// If a repeating group is associated with
|
|
/// the field, allows to get an instance of it.
|
|
///
|
|
/// @return false if no group is associated with the field.
|
|
///
|
|
/// @warning Due to performance considerations
|
|
/// doesn't check whether an instance refers to a valid
|
|
/// value. Use the OnixS::FIX::FieldValueRef::operator bool()
|
|
/// member to check an instance for a validness.
|
|
bool toGroup(Group &) const;
|
|
|
|
/// Appends a copy of a text presentation to the std::string.
|
|
void toString(std::string &) const;
|
|
|
|
/// Return the string presentation of the field value.
|
|
std::string toString() const;
|
|
|
|
/// Updates an instance to refer to another field value.
|
|
/// @warning Does NOT perform a deep copy of field values.
|
|
/// Just updates a reference to point to the value of other field.
|
|
FieldValueRef & operator = (const FieldValueRef &);
|
|
|
|
/// Swaps two references.
|
|
void swap(FieldValueRef & other);
|
|
|
|
private:
|
|
friend class MessageOperator;
|
|
|
|
const void * impl_;
|
|
|
|
const Message * container_;
|
|
|
|
FieldValueRef(
|
|
const Message *,
|
|
const void *);
|
|
};
|
|
|
|
inline StringRef FieldValueRef::toStringRef() const
|
|
{
|
|
StringRef result;
|
|
|
|
if(toStringRef(result))
|
|
return result;
|
|
else
|
|
return StringRef();
|
|
}
|
|
|
|
inline
|
|
FieldValueRef::
|
|
operator std::string() const
|
|
{
|
|
std::string str;
|
|
|
|
toString(str);
|
|
|
|
return str;
|
|
}
|
|
|
|
inline
|
|
std::string
|
|
FieldValueRef::toString() const
|
|
{
|
|
std::string str;
|
|
|
|
toString(str);
|
|
|
|
return str;
|
|
}
|
|
|
|
// More comparison operators.
|
|
|
|
inline
|
|
bool
|
|
operator == (
|
|
const FieldValueRef & ref,
|
|
const std::string & str)
|
|
{
|
|
return ref == StringRef(str);
|
|
}
|
|
|
|
inline
|
|
bool
|
|
operator != (
|
|
const FieldValueRef & ref,
|
|
const std::string & str)
|
|
{
|
|
return ref != StringRef(str);
|
|
}
|
|
|
|
inline
|
|
bool
|
|
operator == (
|
|
const std::string & str,
|
|
const FieldValueRef & ref)
|
|
{
|
|
return ref == StringRef(str);
|
|
}
|
|
|
|
inline
|
|
bool
|
|
operator != (
|
|
const std::string & str,
|
|
const FieldValueRef & ref)
|
|
{
|
|
return ref != StringRef(str);
|
|
}
|
|
|
|
// More comparison operators.
|
|
|
|
inline
|
|
bool
|
|
operator == (
|
|
const FieldValueRef & ref,
|
|
const char * str)
|
|
{
|
|
return ref == StringRef(str);
|
|
}
|
|
|
|
inline
|
|
bool
|
|
operator != (
|
|
const FieldValueRef & ref,
|
|
const char * str)
|
|
{
|
|
return ref != StringRef(str);
|
|
}
|
|
|
|
inline
|
|
bool
|
|
operator == (
|
|
const char * str,
|
|
const FieldValueRef & ref)
|
|
{
|
|
return ref == StringRef(str);
|
|
}
|
|
|
|
inline
|
|
bool
|
|
operator != (
|
|
const char * str,
|
|
const FieldValueRef & ref)
|
|
{
|
|
return ref != StringRef(str);
|
|
}
|
|
}
|
|
}
|