Line data Source code
1 : /* Copyright (C) 2017 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
4 : * 0 A.D. is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 2 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * 0 A.D. is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #ifndef INCLUDED_STDSERIALIZER
19 : #define INCLUDED_STDSERIALIZER
20 :
21 : #include "BinarySerializer.h"
22 :
23 : #include <cstring>
24 :
25 : #define DEBUG_SERIALIZER_ANNOTATE 0 // annotate the stream to help debugging if you're reading the output in a hex editor
26 :
27 : class CStdSerializerImpl
28 : {
29 : NONCOPYABLE(CStdSerializerImpl);
30 : public:
31 : CStdSerializerImpl(std::ostream& stream);
32 :
33 104 : ~CStdSerializerImpl()
34 104 : {
35 104 : m_Stream.flush();
36 104 : }
37 :
38 1544 : void Put(const char* name, const u8* data, size_t len)
39 : {
40 : #if DEBUG_SERIALIZER_ANNOTATE
41 : m_Stream.put('<');
42 : m_Stream.write(name, strlen(name));
43 : m_Stream.put('>');
44 : #else
45 : UNUSED2(name);
46 : #endif
47 1544 : m_Stream.write((const char*)data, (std::streamsize)len);
48 1544 : }
49 :
50 0 : std::ostream& GetStream()
51 : {
52 0 : return m_Stream;
53 : }
54 :
55 : private:
56 : std::ostream& m_Stream;
57 : };
58 :
59 104 : class CStdSerializer : public CBinarySerializer<CStdSerializerImpl>
60 : {
61 : public:
62 : CStdSerializer(const ScriptInterface& scriptInterface, std::ostream& stream);
63 :
64 : virtual std::ostream& GetStream();
65 : };
66 :
67 : #endif // INCLUDED_STDSERIALIZER
|