/* ----------------------------------------------------------------------- *//** * * @file DynamicStruct_proto.hpp * *//* ----------------------------------------------------------------------- */ #ifndef MADLIB_DBAL_DYNAMICSTRUCT_PROTO_HPP #define MADLIB_DBAL_DYNAMICSTRUCT_PROTO_HPP namespace madlib { namespace dbal { template < class Storage, template class TypeTraits> class DynamicStructRootContainer { public: typedef ByteStreamHandleBuf StreamBuf_type; typedef typename StreamBuf_type::Storage_type Storage_type; typedef ByteStream ByteStream_type; enum { isMutable = Storage_type::isMutable }; DynamicStructRootContainer(const Storage_type& inStorage); const StreamBuf_type& streambuf() const; StreamBuf_type& streambuf(); protected: StreamBuf_type mByteStreamBuf; }; template class DynamicStructBase { public: typedef Container Container_type; typedef typename Container_type::RootContainer_type RootContainer_type; typedef typename Container_type::Storage_type Storage_type; typedef typename Container_type::ByteStream_type ByteStream_type; typedef Container_type Init_type; DynamicStructBase(Init_type& inContainer); void initialize(); void rebindAll(); const RootContainer_type& rootContainer() const; protected: Container_type& mContainer; }; template class DynamicStructBase : public DynamicStructBase { public: typedef DynamicStructBase Base; typedef typename Base::Init_type Init_type; DynamicStructBase(Init_type& inContainer); protected: template void setSize(SubStruct &inSubStruct, size_t inSize); using Base::mContainer; }; template < class Derived, bool IsMutable, class Storage, template class TypeTraits> class DynamicStructBase, IsMutable> { public: typedef DynamicStructRootContainer Container_type; typedef Derived RootContainer_type; typedef typename Container_type::Storage_type Storage_type; typedef typename Container_type::ByteStream_type ByteStream_type; typedef const Storage_type Init_type; DynamicStructBase(Init_type& inStorage); void initialize(); void rebindAll(); const RootContainer_type& rootContainer() const; const Storage_type& storage() const; const ByteStream_type& byteStream() const; protected: Container_type mContainer; ByteStream_type mByteStream; }; template < class Derived, class Storage, template class TypeTraits> class DynamicStructBase, Mutable> : public DynamicStructBase, Immutable> { public: typedef DynamicStructBase, Immutable> Base; typedef typename Base::Container_type Container_type; typedef typename Base::Init_type Init_type; DynamicStructBase(Init_type& inStorage) : Base(inStorage) { } // void initialize(); protected: template void setSize(SubStruct &inSubStruct, size_t inSize); using Base::mContainer; using Base::mByteStream; }; template class DynamicStruct : public DynamicStructBase { public: typedef DynamicStructBase Base; typedef typename Base::Storage_type Storage_type; typedef typename Base::Container_type Container_type; typedef typename Base::RootContainer_type RootContainer_type; typedef typename Base::ByteStream_type ByteStream_type; typedef typename Base::Init_type Init_type; typedef typename ByteStream_type::char_type char_type; enum { isMutable = Container_type::isMutable }; DynamicStruct(Init_type& inInitialization); using Base::rootContainer; RootContainer_type& rootContainer(); using Base::storage; Storage_type& storage(); using Base::byteStream; ByteStream_type& byteStream(); size_t begin() const; size_t end() const; const char_type* ptr() const; char_type* ptr(); size_t size() const; void bindToStream(ByteStream_type& inStream); /** * @brief Bind a DynamicStruct object to the current position in the stream * * The following idiom (in-class friend function together with static * polymorphism) is called the "Barton-Nackman trick". Essentially, we only * make operator>> visible if type Derived is involved. * * Subclasses have to implement the bind() function. */ friend ByteStream_type& operator>>(ByteStream_type& inStream, Derived& inStruct) { inStruct.bindToStream(inStream); return inStream; } protected: size_t mBegin; size_t mEnd; }; template class DynamicStruct : public DynamicStruct { public: typedef DynamicStruct Base; typedef typename Base::Init_type Init_type; typedef typename Base::ByteStream_type ByteStream_type; DynamicStruct(Init_type& inInitialization); using Base::setSize; void setSize(size_t inSize); void resize(); void bindToStream(ByteStream_type& inStream); protected: bool mSizeIsLocked; template DynamicStruct& copy( const OtherDerived &inOtherStruct); }; template class Ref; namespace eigen_integration { template class HandleMap; } // Because of its dependencies on Eigen, DynamicStructType is only declared in // DynamicStruct_impl.hpp. template struct DynamicStructType; #define MADLIB_DYNAMIC_STRUCT_TYPEDEFS \ enum { isMutable = Base::isMutable }; \ typedef typename Base::Init_type Init_type; \ typedef typename Base::ByteStream_type ByteStream_type; \ typedef typename Base::Storage_type Storage_type; \ typedef typename DynamicStructType::type bool_type; \ typedef typename DynamicStructType::type double_type; \ typedef typename DynamicStructType::type float_type; \ typedef typename DynamicStructType::type uint64_type; \ typedef typename DynamicStructType::type int64_type; \ typedef typename DynamicStructType::type uint32_type; \ typedef typename DynamicStructType::type int32_type; \ typedef typename DynamicStructType::type uint16_type; \ typedef typename DynamicStructType::type int16_type; \ typedef typename DynamicStructType::type \ ColumnVector_type; \ typedef typename DynamicStructType::type \ IntegerVector_type; \ typedef typename DynamicStructType::type Matrix_type } // namespace dbal } // namespace madlib #endif // defined(MADLIB_DBAL_DYNAMICSTRUCT_PROTO_HPP)