/* ----------------------------------------------------------------------- *//** * * @file ByteStream_proto.hpp * *//* ----------------------------------------------------------------------- */ #ifndef MADLIB_DBAL_BYTESTREAM_PROTO_HPP #define MADLIB_DBAL_BYTESTREAM_PROTO_HPP namespace madlib { namespace dbal { struct ByteStreamMaximumAlignmentType { }; template struct ByteStreamDefaultTypeTraits { enum { alignment = sizeof(T) <= 16 ? sizeof(T) : 16 }; }; // Specialize for the maximum-alignment dummy type. There is no supported // architecture at the moment for which 16 bytes would not be enough. template <> struct ByteStreamDefaultTypeTraits { enum { alignment = 16 }; }; template < class StreamBuf, template class TypeTraits = ByteStreamDefaultTypeTraits, bool IsMutable = StreamBuf::isMutable> class ByteStream { public: typedef StreamBuf StreamBuf_type; typedef typename StreamBuf_type::char_type char_type; enum { isMutable = IsMutable }; enum { maximumAlignment = TypeTraits::alignment }; friend class DryRun; class DryRun { public: DryRun(ByteStream& inStream); ~DryRun(); void leave(); protected: ByteStream& mStream; bool mIsIn; }; ByteStream(StreamBuf_type* inStreamBuf); template size_t seek(std::ptrdiff_t inOffset, std::ios_base::seekdir inDir); size_t seek(size_t inPos); size_t seek(std::ptrdiff_t inOffset, std::ios_base::seekdir inDir); size_t available() const; const char_type* ptr() const; size_t size() const; size_t tell() const; std::ios_base::iostate rdstate() const; bool eof() const; bool isInDryRun() const; template const T* read(size_t inCount = 1); protected: void enterDryRun(); void leaveDryRun(); /** * @brief The associated storage to the stream (similar to a streambuf for * IOStreams) */ StreamBuf_type* mStreamBuf; /** * @brief In dry mode read/write operations will only move the cursor, but * other objects are not touched */ int32_t mDryRun; }; template class TypeTraits> class ByteStream : public ByteStream { public: typedef ByteStream Base; typedef typename Base::StreamBuf_type StreamBuf_type; typedef typename Base::char_type char_type; ByteStream(StreamBuf_type* inStreamBuf); char_type* ptr(); template T* read(size_t inCount = 1); }; } // namespace dbal } // namespace madlib #endif // defined(MADLIB_DBAL_BYTESTREAM_PROTO_HPP)