3 Copyright 2007 Antoine Chavasse <a.chavasse@gmail.com>
5 This file is part of Fail.
7 Fail is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3
9 as published by the Free Software Foundation.
11 Fail is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef FAIL_FBF_WRITE_CONTEXT_H
20 #define FAIL_FBF_WRITE_CONTEXT_H
24 namespace fail
{ namespace fbf
{ namespace Impl
26 template< class C
, bool bStorable
= flags::Storable
< C
>::value
> struct VisitSuperClassIfStorable
28 template< class V
> static void Visit( V
& v
)
30 class_traits
< C
>::template VisitSuperClasses( v
);
31 class_traits
< C
>::template VisitAttributes( v
);
35 template< class C
> struct VisitSuperClassIfStorable
< C
, false >
37 template< class V
> static void Visit( V
& v
)
43 template< typename AttrTag
, bool bStorable
= flags::Storable
< AttrTag
>::value
> struct WriteAttrIfStorable
45 template< class C
, class WCT
> static void Write( C
* pObj
, WCT
& wct
)
47 typedef attribute_traits
< C
, AttrTag
> traits
;
48 typedef TypeMarshaler
< C
, typename
traits::category
, typename
traits::type
> tm
;
49 tm::write( pObj
, wct
, pObj
->*( traits::MemberPointer() ) );
53 template< typename AttrTag
> struct WriteAttrIfStorable
< AttrTag
, false >
55 template< class C
, class WCT
> static void Write( C
* pObj
, WCT
& wct
) {}
58 template< class WCT
, class C
> struct WriteObjVisitor
60 WriteObjVisitor( WCT
& wct_
, const C
* pObj_
) :
66 template< class SC
> void declSuperClass()
68 VisitSuperClassIfStorable
< SC
>::Visit( *this );
71 template< typename AttrTag
> void declAttribute()
73 WriteAttrIfStorable
< AttrTag
>::Write( pObj
, wct
);
80 template< class stream_type
> template< class C
> void WriteContext
< stream_type
>::
81 writeObject( const Pointer
< C
>& pObj_
)
83 if( !flags::Storable
< C
>::value
)
86 const RefCounted
* pObjBase
= static_cast< RefCounted
* >( pObj_
);
87 addObject( pObjBase
);
89 WriteObjVisitor
< WriteContext
< stream_type
>, C
> wov( *this, pObj_
);
90 class_traits
< C
>::template VisitSuperClasses( wov
);
91 class_traits
< C
>::template VisitAttributes( wov
);