Pyrogenesis  trunk
StdSerializer.h
Go to the documentation of this file.
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 
28 {
30 public:
31  CStdSerializerImpl(std::ostream& stream);
32 
34  {
35  m_Stream.flush();
36  }
37 
38  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  m_Stream.write((const char*)data, (std::streamsize)len);
48  }
49 
50  std::ostream& GetStream()
51  {
52  return m_Stream;
53  }
54 
55 private:
56  std::ostream& m_Stream;
57 };
58 
59 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
uint8_t u8
Definition: types.h:37
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
Definition: code_annotation.h:56
CStdSerializerImpl(std::ostream &stream)
Definition: StdSerializer.cpp:22
std::ostream & m_Stream
Definition: StdSerializer.h:56
~CStdSerializerImpl()
Definition: StdSerializer.h:33
Definition: StdSerializer.h:27
NONCOPYABLE(CStdSerializerImpl)
std::ostream & GetStream()
Definition: StdSerializer.h:50
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:71
Serialize to a binary stream.
Definition: BinarySerializer.h:108
Definition: StdSerializer.h:59
void Put(const char *name, const u8 *data, size_t len)
Definition: StdSerializer.h:38