Added GPLv3 headers all over the place.
[fail.git] / src / services / fbf / writer-DGST.h
blobd90595b9042277cba8c7e712668b6c33d66c1083
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_WRITER_DGST_H
20 #define FAIL_FBF_WRITER_DGST_H
22 #include <set>
24 namespace fail { namespace fbf
26 namespace Impl
28 // TODO: this is supposed to scan all of the objects that we are going to save
29 // and make sure that the digests for all the concerned modules are included.
30 template< class C > static void AddObjDigest(
31 const Pointer< C >& pObj_,
32 std::set< uint64_t >& Digests_,
33 std::set< const void* >& Objects_ )
35 if( !Objects_.insert( static_cast< const void* >( pObj_ ) ).second )
36 return;
38 uint64_t digest = SchemaDigest< typename class_traits< C >::module_tag >::digest;
39 Digests_.insert( digest );
41 // TODO: recurse
45 template< class EndianessPolicy > template< class C > void BaseWriter< EndianessPolicy >::
46 WriteDGST( buffered_stream_type& Stream, const Pointer< C >& pObj_ )
48 const char dgst[] = { 'D', 'G', 'S', 'T' };
49 Stream.write( dgst, sizeof( dgst ) );
51 std::set< const void* > Objects;
52 std::set< uint64_t > Digests;
54 Impl::AddObjDigest( pObj_, Digests, Objects );
55 Stream.writeU32( Digests.size() * sizeof( uint64_t ) );
57 std::set< uint64_t >::const_iterator it;
58 for( it = Digests.begin(); it != Digests.end(); ++it )
59 Stream.writeU64( *it );
63 #endif