diff options
author | Adam Mitz <mitza@ociweb.com> | 2015-04-01 17:50:05 -0500 |
---|---|---|
committer | Adam Mitz <mitza@ociweb.com> | 2015-04-01 17:50:05 -0500 |
commit | f1d214369e66045e00263d6c46d753e62653daf0 (patch) | |
tree | b1d2675db407eb265dbc5b1c1a5b67643711cca3 /ACE/ace/CDR_Base.h | |
parent | 6b5c388813e1bbac774902e449d1a9f3c25fff96 (diff) | |
download | ATCD-f1d214369e66045e00263d6c46d753e62653daf0.tar.gz |
Continued developing ACE_CDR::Fixed and tao_idl fixed parsing.
Diffstat (limited to 'ACE/ace/CDR_Base.h')
-rw-r--r-- | ACE/ace/CDR_Base.h | 157 |
1 files changed, 145 insertions, 12 deletions
diff --git a/ACE/ace/CDR_Base.h b/ACE/ace/CDR_Base.h index ab243515c2a..7e05ed54efb 100644 --- a/ACE/ace/CDR_Base.h +++ b/ACE/ace/CDR_Base.h @@ -38,6 +38,8 @@ #include "ace/Global_Macros.h" #include "ace/iosfwd.h" +#include <iterator> + ACE_BEGIN_VERSIONED_NAMESPACE_DECL // Stuff used by the ACE CDR classes. Watch these values... they're also used @@ -352,39 +354,158 @@ public: }; # endif /* ACE_SIZEOF_LONG_DOUBLE != 16 */ + /// Fixed-point data type: up to 31 decimal digits and a sign bit + /// + /// See OMG 2011-11-01 CORBA Interfaces v3.2 sections 7.10, 7.11.3.4 + /// See OMG 2011-11-02 CORBA Interoperability v3.2 section 9.3.2.8 + /// See OMG 2012-07-02 IDL-to-C++ Mapping v1.3 section 5.13 + /// This class doesn't exactly match the IDL-to-C++ mapping because + /// it is meant for use inside a union in the IDL compiler and therefore + /// has no constructors. Standards-based middlware libraries such as + /// ORBs and DDSs can wrap this class in a class of their own to provide + /// the exactly interface described by the mapping specification. class ACE_Export Fixed { public: - static const Octet POSITIVE = 0xc, NEGATIVE = 0xd; + static const size_t MAX_STRING_SIZE = 34; // includes -, ., terminator - static Fixed from_int (LongLong val = 0); - static Fixed from_int (ULongLong val); + static Fixed from_integer (LongLong val = 0); + static Fixed from_integer (ULongLong val); + static Fixed from_floating (LongDouble val); static Fixed from_string (const char *str); - Octet& scale () { return scale_; } - Octet scale () const { return scale_; } + operator LongLong () const; + operator LongDouble () const; + + Fixed round (UShort scale) const; + Fixed truncate (UShort scale) const; + + bool to_string (char *buffer, size_t buffer_size) const; + + Fixed &operator+= (const Fixed &rhs); + Fixed &operator-= (const Fixed &rhs); + Fixed &operator*= (const Fixed &rhs); + Fixed &operator/= (const Fixed &rhs); + + Fixed& operator++ (); + Fixed operator++ (int); + Fixed& operator-- (); + Fixed operator-- (int); + + Fixed operator+ () const; + Fixed operator- () const; + Boolean operator! () const; + + UShort fixed_digits () const; + UShort fixed_scale () const; - bool operator== (const Fixed &rhs) const; + bool signbit () const; friend ACE_Export ACE_OSTREAM_TYPE &::operator<< (ACE_OSTREAM_TYPE &lhs, const Fixed &rhs); - private: - static const Octet UNUSED = 0xff; + friend ACE_Export + ACE_OSTREAM_TYPE &::operator>> (ACE_OSTREAM_TYPE &lhs, Fixed &rhs); + + friend ACE_Export + bool ::operator< (const Fixed &lhs, const Fixed &rhs); + + friend ACE_Export + bool ::operator> (const Fixed &lhs, const Fixed &rhs); + + friend ACE_Export + bool ::operator>= (const Fixed &lhs, const Fixed &rhs); + + friend ACE_Export + bool ::operator<= (const Fixed &lhs, const Fixed &rhs); + + friend ACE_Export + bool ::operator== (const Fixed &lhs, const Fixed &rhs); + + friend ACE_Export + bool ::operator!= (const Fixed &lhs, const Fixed &rhs); + + class Proxy + { + bool high_nibble_; + Octet &element_; + public: + Proxy (bool high_nibble, Octet &element); + Proxy &operator= (Octet val); + operator Octet () const; + }; + + class IteratorBase + { + protected: + explicit IteratorBase (int digit); + bool high_nibble () const; + Octet &storage (Fixed *outer) const; + Octet storage (const Fixed *outer) const; + bool compare (const IteratorBase &rhs) const; + int digit_; + }; + + class Iterator + : public std::iterator<std::bidirectional_iterator_tag, Proxy> + , private IteratorBase + { + public: + explicit Iterator (Fixed *outer, int digit = 0); + Proxy operator* (); + Iterator &operator++ (); + Iterator operator++ (int); + Iterator &operator-- (); + Iterator operator-- (int); + bool operator== (const Iterator &rhs) const; + bool operator!= (const Iterator &rhs) const; + private: + Fixed *outer_; + }; + + class ConstIterator + : public std::iterator<std::bidirectional_iterator_tag, Octet> + , private IteratorBase + { + public: + explicit ConstIterator (const Fixed *outer, int digit = 0); + Octet operator* (); + ConstIterator &operator++ (); + ConstIterator operator++ (int); + ConstIterator &operator-- (); + ConstIterator operator-- (int); + bool operator== (const ConstIterator &rhs) const; + bool operator!= (const ConstIterator &rhs) const; + private: + const Fixed *outer_; + }; + + Iterator begin (); + ConstIterator begin () const; + ConstIterator cbegin () const; + Iterator end (); + ConstIterator end () const; + ConstIterator cend () const; + private: /// CDR wire format for Fixed: marshaled as an octet array with /// index 0 as the most significant octet and index n the least /// significant. Each octet contains two decimal digits except for - /// the last octet (after least sig) which has one decimal digit in + /// the last octet (least sig) which has one decimal digit in /// the high nibble and the sign indicator in the low nibble. - /// Octets at the start of the array with the value UNUSED are not - /// marshalled. Octet value_[16]; - /// Scale is not marshaled, the receiver needs to know it + /// digits_ is not marshaled, the receiver needs to know it + /// from the type information (for example, IDL). The value of + /// digits_ determines how many octets of value_ are masharled. + Octet digits_; + + /// scale_ is not marshaled, the receiver needs to know it /// from the type information (for example, IDL). Octet scale_; + + static const Octet POSITIVE = 0xc, NEGATIVE = 0xd; }; //@} @@ -398,6 +519,18 @@ public: #endif /* ACE_CDR_GIOP_MINOR_VERSION */ }; +ACE_Export +ACE_CDR::Fixed operator+ (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +ACE_CDR::Fixed operator- (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +ACE_CDR::Fixed operator* (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + +ACE_Export +ACE_CDR::Fixed operator/ (const ACE_CDR::Fixed &lhs, const ACE_CDR::Fixed &rhs); + ACE_END_VERSIONED_NAMESPACE_DECL #if defined (__ACE_INLINE__) |