Author: astitcher
Date: Thu Oct 18 07:06:09 2007
New Revision: 585966
URL: http://svn.apache.org/viewvc?rev=585966&view=rev
Log:
Recast int to FixedWidthValue conversions to avoid tamplate specialisation and
be more general
Modified:
incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp?rev=585966&r1=585965&r2=585966&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp Thu Oct 18
07:06:09 2007
@@ -26,117 +26,6 @@
namespace qpid {
namespace framing {
-/*
- * Specialisations for construction from integers
- */
-template<>
-FixedWidthValue<8>::FixedWidthValue(uint64_t v)
-{
- octets[7] = (uint8_t) (0xFF & v); v >>= 8;
- octets[6] = (uint8_t) (0xFF & v); v >>= 8;
- octets[5] = (uint8_t) (0xFF & v); v >>= 8;
- octets[4] = (uint8_t) (0xFF & v); v >>= 8;
- octets[3] = (uint8_t) (0xFF & v); v >>= 8;
- octets[2] = (uint8_t) (0xFF & v); v >>= 8;
- octets[1] = (uint8_t) (0xFF & v); v >>= 8;
- octets[0] = (uint8_t) (0xFF & v);
-}
-
-template<>
-FixedWidthValue<4>::FixedWidthValue(uint64_t v)
-{
- octets[3] = (uint8_t) (0xFF & v); v >>= 8;
- octets[2] = (uint8_t) (0xFF & v); v >>= 8;
- octets[1] = (uint8_t) (0xFF & v); v >>= 8;
- octets[0] = (uint8_t) (0xFF & v);
-}
-
-template<>
-FixedWidthValue<2>::FixedWidthValue(uint64_t v)
-{
- octets[1] = (uint8_t) (0xFF & v); v >>= 8;
- octets[0] = (uint8_t) (0xFF & v);
-}
-
-template<>
-FixedWidthValue<1>::FixedWidthValue(uint64_t v)
-{
- octets[0] = (uint8_t) (0xFF & v);
-}
-
-/*
- * Specialisations for turning into integers
- */
-template<>
-int64_t FixedWidthValue<8>::getInt() const
-{
- int64_t v = 0;
- v |= octets[0]; v <<= 8;
- v |= octets[1]; v <<= 8;
- v |= octets[2]; v <<= 8;
- v |= octets[3]; v <<= 8;
- v |= octets[4]; v <<= 8;
- v |= octets[5]; v <<= 8;
- v |= octets[6]; v <<= 8;
- v |= octets[7];
- return v;
-}
-
-template<>
-int64_t FixedWidthValue<4>::getInt() const
-{
- int64_t v = 0;
- v |= octets[0]; v <<= 8;
- v |= octets[1]; v <<= 8;
- v |= octets[2]; v <<= 8;
- v |= octets[3];
- return v;
-}
-
-template<>
-int64_t FixedWidthValue<2>::getInt() const
-{
- int64_t v = 0;
- v |= octets[0]; v <<= 8;
- v |= octets[1];
- return v;
-}
-
-template<>
-int64_t FixedWidthValue<1>::getInt() const
-{
- int64_t v = 0;
- v |= octets[0];
- return v;
-}
-
-/*
- * Specialisations for convertion to int predicate
- */
-template<>
-bool FixedWidthValue<8>::convertsToInt() const
-{
- return true;
-}
-
-template<>
-bool FixedWidthValue<4>::convertsToInt() const
-{
- return true;
-}
-
-template<>
-bool FixedWidthValue<2>::convertsToInt() const
-{
- return true;
-}
-
-template<>
-bool FixedWidthValue<1>::convertsToInt() const
-{
- return true;
-}
-
void FieldValue::decode(Buffer& buffer)
{
typeOctet = buffer.getOctet();
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h?rev=585966&r1=585965&r2=585966&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h Thu Oct 18
07:06:09 2007
@@ -90,7 +90,14 @@
public:
FixedWidthValue() {}
FixedWidthValue(const uint8_t (&data)[width]) : octets(data) {}
- FixedWidthValue(uint64_t v);
+ FixedWidthValue(uint64_t v)
+ {
+ for (int i = width; i > 0; --i) {
+ octets[i-1] = (uint8_t) (0xFF & v); v >>= 8;
+ }
+ octets[0] = (uint8_t) (0xFF & v);
+ }
+
uint32_t size() const { return width; }
void encode(Buffer& buffer) { buffer.putRawData(octets, width); }
void decode(Buffer& buffer) { buffer.getRawData(octets, width); }
@@ -100,8 +107,16 @@
else return std::equal(&octets[0], &octets[width], &rhs->octets[0]);
}
- bool convertsToInt() const { return false; }
- int64_t getInt() const { return 0; }
+ bool convertsToInt() const { return true; }
+ int64_t getInt() const
+ {
+ int64_t v = 0;
+ for (int i = 0; i < width-1; ++i) {
+ v |= octets[i]; v <<= 8;
+ }
+ v |= octets[width-1];
+ return v;
+ }
void print(std::ostream& o) const { o << "F" << width << ":"; };
};
@@ -119,22 +134,6 @@
}
void print(std::ostream& o) const { o << "F0"; };
};
-
-template<> FixedWidthValue<8>::FixedWidthValue(uint64_t v);
-template<> int64_t FixedWidthValue<8>::getInt() const;
-template<> bool FixedWidthValue<8>::convertsToInt() const;
-
-template<> int64_t FixedWidthValue<4>::getInt() const;
-template<> FixedWidthValue<4>::FixedWidthValue(uint64_t v);
-template<> bool FixedWidthValue<4>::convertsToInt() const;
-
-template<> FixedWidthValue<2>::FixedWidthValue(uint64_t v);
-template<> int64_t FixedWidthValue<2>::getInt() const;
-template<> bool FixedWidthValue<2>::convertsToInt() const;
-
-template<> FixedWidthValue<1>::FixedWidthValue(uint64_t v);
-template<> int64_t FixedWidthValue<1>::getInt() const;
-template<> bool FixedWidthValue<1>::convertsToInt() const;
template <int lenwidth>
class VariableWidthValue : public FieldValue::Data {