Pyrogenesis  trunk
DebugSerializer.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_DEBUGSERIALIZER
19 #define INCLUDED_DEBUGSERIALIZER
20 
21 #include "ISerializer.h"
22 
23 /**
24  * Serialize to a human-readable YAML-like format.
25  */
27 {
29 public:
30  /**
31  * @param scriptInterface Script interface corresponding to any jsvals passed to ScriptVal()
32  * @param stream Stream to receive UTF-8 encoded output
33  * @param includeDebugInfo If true then additional non-deterministic data will be included in the output
34  */
35  CDebugSerializer(ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo = true);
36 
37  void Comment(const std::string& comment);
38  void TextLine(const std::string& text);
39  void Indent(int spaces);
40  void Dedent(int spaces);
41 
42  virtual bool IsDebug() const;
43  virtual std::ostream& GetStream();
44 
45 protected:
46  virtual void PutNumber(const char* name, uint8_t value);
47  virtual void PutNumber(const char* name, int8_t value);
48  virtual void PutNumber(const char* name, uint16_t value);
49  virtual void PutNumber(const char* name, int16_t value);
50  virtual void PutNumber(const char* name, uint32_t value);
51  virtual void PutNumber(const char* name, int32_t value);
52  virtual void PutNumber(const char* name, float value);
53  virtual void PutNumber(const char* name, double value);
54  virtual void PutNumber(const char* name, fixed value);
55  virtual void PutBool(const char* name, bool value);
56  virtual void PutString(const char* name, const std::string& value);
57  virtual void PutScriptVal(const char* name, JS::MutableHandleValue value);
58  virtual void PutRaw(const char* name, const u8* data, size_t len);
59 
60 private:
62  std::ostream& m_Stream;
63  bool m_IsDebug;
64  int m_Indent;
65 };
66 
67 #endif // INCLUDED_DEBUGSERIALIZER
signed char int8_t
Definition: wposix_types.h:37
A simple fixed-point number class.
Definition: Fixed.h:115
virtual void PutScriptVal(const char *name, JS::MutableHandleValue value)
Definition: DebugSerializer.cpp:150
int m_Indent
Definition: DebugSerializer.h:64
virtual std::ostream & GetStream()
Returns a stream which can be used to serialize data directly.
Definition: DebugSerializer.cpp:176
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
virtual void PutBool(const char *name, bool value)
Definition: DebugSerializer.cpp:128
short int16_t
Definition: wposix_types.h:38
Serialize to a human-readable YAML-like format.
Definition: DebugSerializer.h:26
void Dedent(int spaces)
Definition: DebugSerializer.cpp:65
uint8_t u8
Definition: types.h:37
virtual void PutNumber(const char *name, uint8_t value)
Definition: DebugSerializer.cpp:83
void Indent(int spaces)
Definition: DebugSerializer.cpp:60
virtual bool IsDebug() const
Returns true if the serializer is being used in debug mode.
Definition: DebugSerializer.cpp:171
unsigned char uint8_t
Definition: wposix_types.h:51
virtual void PutRaw(const char *name, const u8 *data, size_t len)
Definition: DebugSerializer.cpp:157
void TextLine(const std::string &text)
Definition: DebugSerializer.cpp:78
std::ostream & m_Stream
Definition: DebugSerializer.h:62
bool m_IsDebug
Definition: DebugSerializer.h:63
void Comment(const std::string &comment)
Definition: DebugSerializer.cpp:73
NONCOPYABLE(CDebugSerializer)
virtual void PutString(const char *name, const std::string &value)
Definition: DebugSerializer.cpp:133
ScriptInterface & m_ScriptInterface
Definition: DebugSerializer.h:61
unsigned int uint32_t
Definition: wposix_types.h:53
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptInterface.h:71
unsigned short uint16_t
Definition: wposix_types.h:52
CDebugSerializer(ScriptInterface &scriptInterface, std::ostream &stream, bool includeDebugInfo=true)
Definition: DebugSerializer.cpp:55