Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StdSerializer.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 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 
33  void Put(const char* name, const u8* data, size_t len)
34  {
35 #if DEBUG_SERIALIZER_ANNOTATE
36  m_Stream.put('<');
37  m_Stream.write(name, strlen(name));
38  m_Stream.put('>');
39 #else
40  UNUSED2(name);
41 #endif
42  m_Stream.write((const char*)data, (std::streamsize)len);
43  }
44 
45  std::ostream& GetStream()
46  {
47  return m_Stream;
48  }
49 
50 private:
51  std::ostream& m_Stream;
52 };
53 
54 class CStdSerializer : public CBinarySerializer<CStdSerializerImpl>
55 {
56 public:
57  CStdSerializer(ScriptInterface& scriptInterface, std::ostream& stream);
58 
59  virtual std::ostream& GetStream();
60 };
61 
62 #endif // INCLUDED_STDSERIALIZER
#define u8
Definition: types.h:39
virtual std::ostream & GetStream()
Returns a stream which can be used to serialize data directly.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
CStdSerializerImpl(std::ostream &stream)
std::ostream & m_Stream
Definition: StdSerializer.h:51
NONCOPYABLE(CStdSerializerImpl)
CStdSerializer(ScriptInterface &scriptInterface, std::ostream &stream)
std::ostream & GetStream()
Definition: StdSerializer.h:45
Abstraction around a SpiderMonkey JSContext.
Serialize to a binary stream.
void Put(const char *name, const u8 *data, size_t len)
Definition: StdSerializer.h:33