Added GPLv3 headers all over the place.
[fail.git] / src / services / fbf / write-context.h
blobd69135dc24f0d2fc86f76105402a2276940cc1de
1 /*
2 Fail game engine
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
22 #include <map>
24 namespace fail { namespace fbf { namespace Impl
26 template< class WCT, class C > struct WriteObjVisitor
28 WriteObjVisitor( WCT& wct_, const C* pObj_ ) :
29 wct( wct_ ),
30 pObj( pObj_ )
34 template< class SC > void declSuperClass()
36 class_traits< SC >::template VisitSuperClasses( *this );
37 class_traits< SC >::template VisitAttributes( *this );
40 template< typename AttrTag > void declAttribute()
42 if( flags::Storable< AttrTag >::value )
44 typedef attribute_traits< C, AttrTag > traits;
45 typedef TypeMarshaler< typename traits::category, typename traits::type > tm;
46 tm::write( wct, pObj->*( traits::MemberPointer() ) );
50 WCT& wct;
51 const C* pObj;
54 template< class stream_type > template< class C > void WriteContext< stream_type >::
55 writeObject( const Pointer< C >& pObj_ )
57 if( !flags::Storable< C >::value )
58 return;
60 const RefCounted* pObjBase = static_cast< RefCounted* >( pObj_ );
61 m_Objects.insert( std::make_pair( pObjBase, m_NextObjectID++ ) );
63 WriteObjVisitor< WriteContext< stream_type >, C > wov( *this, pObj_ );
64 class_traits< C >::template VisitSuperClasses( wov );
65 class_traits< C >::template VisitAttributes( wov );
67 }}}
69 #endif