From 67474659bd802c11bdcb8f26662236637eab0851 Mon Sep 17 00:00:00 2001 From: Antoine Chavasse Date: Sun, 10 Jun 2007 20:00:54 +0200 Subject: [PATCH] ABF: moar work on the reimplementation. --- abf/basic_types.h | 39 +++++++++++++++++++++++ abf/implementation.h | 4 ++- abf/test/Tubgirl.h | 8 ++--- abf/test/abftest.aidl | 2 +- abf/writer-OBJS.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ abf/writer-save.h | 1 + 6 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 abf/basic_types.h create mode 100644 abf/writer-OBJS.h diff --git a/abf/basic_types.h b/abf/basic_types.h new file mode 100644 index 0000000..8dda481 --- /dev/null +++ b/abf/basic_types.h @@ -0,0 +1,39 @@ +#ifndef AWFUL_ABF_BASIC_TYPES_H +#define AWFUL_ABF_BASIC_TYPES_H + +namespace awful { namespace abf { namespace Impl +{ + template< typename category, typename T > struct TypeMarshaler + { + }; + + template<> struct TypeMarshaler< NormalType, uint32_t > + { + template< class WCT > void write( WCT& wct_, uint32_t val_ ) + { + wct_.Stream.writeU32( val_ ); + } + + template< class RCT > void read( RCT& rct_, uint32_t& val_ ) + { + val_ = rct_.Stream.readU32(); + } + }; + + template<> struct TypeMarshaler< NormalType, int32_t > + { + template< class WCT > void write( WCT& wct_, int32_t val_ ) + { + wct_.Stream.writeU32( val_ ); + } + + template< class RCT > void read( RCT& rct_, int32_t& val_ ) + { + val_ = rct_.Stream.readU32(); + } + }; + + // TODO: all other types +}}} + +#endif diff --git a/abf/implementation.h b/abf/implementation.h index f6d41c4..88c9111 100644 --- a/abf/implementation.h +++ b/abf/implementation.h @@ -4,8 +4,10 @@ #include "interface.h" #include "schema-digest/digest.h" +#include "basic_types.h" #include "writer-header.h" #include "writer-DGST.h" +#include "writer-OBJS.h" #include "writer-save.h" #include "registry.h" @@ -34,7 +36,7 @@ namespace awful { namespace abf } }; } - + template< typename ModuleTag > void Setup() { std::cout << "module " << module_traits< ModuleTag >::FullName() << diff --git a/abf/test/Tubgirl.h b/abf/test/Tubgirl.h index fadb198..f46838f 100644 --- a/abf/test/Tubgirl.h +++ b/abf/test/Tubgirl.h @@ -15,13 +15,13 @@ namespace awful { namespace abftest Tubgirl( const Serialization_tag& ) {} - int32_t getblah() const { return m_blah; } - void setblah( const int32_t& x ) { m_blah = x; } - const int32_t& blah() const { return m_blah; } + uint32_t getblah() const { return m_blah; } + void setblah( const uint32_t& x ) { m_blah = x; } + const uint32_t& blah() const { return m_blah; } private: template< class C, typename T > friend struct awful::attribute_traits; - int32_t m_blah; + uint32_t m_blah; //char pron; /*Goatse( long lulz_ ) : diff --git a/abf/test/abftest.aidl b/abf/test/abftest.aidl index 857c030..7f3d5c9 100644 --- a/abf/test/abftest.aidl +++ b/abf/test/abftest.aidl @@ -2,7 +2,7 @@ namespace awful { namespace abftest { class Tubgirl { - int32_t blah; + uint32_t blah; }; class Goatse : Tubgirl diff --git a/abf/writer-OBJS.h b/abf/writer-OBJS.h new file mode 100644 index 0000000..479da45 --- /dev/null +++ b/abf/writer-OBJS.h @@ -0,0 +1,86 @@ +#ifndef AWFUL_ABF_WRITER_OBJS_H +#define AWFUL_ABF_WRITER_OBJS_H + +#include + +namespace awful { namespace abf +{ + namespace Impl + { + template< class stream_type > class WriteContext + { + template< class C > struct WriteObjVisitor + { + WriteObjVisitor( WriteContext& wct_, const C* pObj_ ) : + wct( wct_ ), + pObj( pObj_ ) + { + } + + template< class SC > void declSuperClass() + { + class_traits< SC >::template VisitSuperClasses( *this ); + } + + template< typename AttrTag > void declAttribute() + { + typedef attribute_traits< C, AttrTag > traits; + TypeMarshaler< typename traits::category, typename traits::type > tm; + tm.write( wct, pObj->*( traits::MemberPointer() ) ); + } + + WriteContext& wct; + const C* pObj; + }; + + public: + WriteContext( stream_type& Stream_ ) : + Stream( Stream_ ), + m_NextObjectID( 0 ) + { + } + + template< class C > void writeObject( const Pointer< C >& pObj_ ) + { + const RefCounted* pObjBase = static_cast< RefCounted* >( pObj_ ); + m_Objects.insert( std::make_pair( pObjBase, m_NextObjectID++ ) ); + + // TODO: for abstract classes, use a table to find the actual writing function + // to use by using the typeid of the object. + Stream.writeU32( class_traits< C >::Digest() ); + + WriteObjVisitor< C > wov( *this, pObj_ ); + class_traits< C >::template VisitSuperClasses( wov ); + class_traits< C >::template VisitAttributes( wov ); + } + + stream_type& Stream; + + private: + std::map< const RefCounted*, int > m_Objects; + int m_NextObjectID; + }; + } + + template< class EndianessPolicy > template< class C > void BaseWriter< EndianessPolicy >:: + WriteOBJS( buffered_stream_type& Stream, const Pointer< C >& pObj_ ) + { + const char objs[] = { 'O', 'B', 'J', 'S' }; + Stream.write( objs, sizeof( objs ) ); + + uint64_t begin = Stream.tell(); + + // Write 0 for the chunk size, it will be fixed after the object chunk is written + Stream.writeU32( 0 ); + + Impl::WriteContext< buffered_stream_type > wct( Stream ); + wct.writeObject( pObj_ ); + //ABFImpl::writeObj( w, pObj ); + + uint32_t size = Stream.tell() - begin - 4; + Stream.seek( begin ); + Stream.writeU32( size ); + } +}} + +#endif diff --git a/abf/writer-save.h b/abf/writer-save.h index 925e935..748220e 100644 --- a/abf/writer-save.h +++ b/abf/writer-save.h @@ -9,6 +9,7 @@ namespace awful { namespace abf io::BufferedSeekableOutputStream< EndianessPolicy > Stream( pStream_ ); WriteHeader( Stream ); WriteDGST< C >( Stream, pObj_ ); + WriteOBJS< C >( Stream, pObj_ ); } }} -- 2.11.4.GIT