// Represent // // Douglas Thrift // // $Id$ #ifndef _Binary_hpp_ #define _Binary_hpp_ #include "Represent.hpp" #ifdef MENES_PRAGMA_ONCE #pragma once #endif class Binary { protected: ext::Vector bytes; Binary(size_t size, byte_t value) : bytes(size, value) {} public: Binary() : bytes(size_t(1), 0) {} Binary(const ext::String& string, bool signed_); template Binary(const Type& type); template Type convert(bool signed_); virtual operator ext::String() const; }; template Binary::Binary(const Type& type) : bytes(sizeof (type)) { byte_t* type_(reinterpret_cast(const_cast(&type))); _foreach (ext::Vector, byte, bytes) *byte = *type_++; } template Type Binary::convert(bool signed_) { Type type; if (sizeof (type) != bytes.GetSize()) bytes.SetSize(sizeof (type), signed_ && bytes.Last() >> 7 ? ~0 : 0); byte_t* type_(reinterpret_cast(&type)); _foreach (ext::Vector, byte, bytes) *type_++ = *byte; return type; } #endif // _Binary_hpp_