Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
DebugSerializer.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_DEBUGSERIALIZER
19#define INCLUDED_DEBUGSERIALIZER
20
21#include "ISerializer.h"
22
23/**
24 * Serialize to a human-readable YAML-like format.
25 */
27{
29public:
30 /**
31 * @param scriptInterface Script interface corresponding to any JS::Value 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(const 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
45protected:
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
60private:
62 std::ostream& m_Stream;
65};
66
67#endif // INCLUDED_DEBUGSERIALIZER
Serialize to a human-readable YAML-like format.
Definition: DebugSerializer.h:27
NONCOPYABLE(CDebugSerializer)
void Dedent(int spaces)
Definition: DebugSerializer.cpp:68
void Indent(int spaces)
Definition: DebugSerializer.cpp:63
virtual void PutBool(const char *name, bool value)
Definition: DebugSerializer.cpp:131
virtual void PutRaw(const char *name, const u8 *data, size_t len)
Definition: DebugSerializer.cpp:173
virtual std::ostream & GetStream()
Returns a stream which can be used to serialize data directly.
Definition: DebugSerializer.cpp:192
CDebugSerializer(const ScriptInterface &scriptInterface, std::ostream &stream, bool includeDebugInfo=true)
Definition: DebugSerializer.cpp:58
int m_Indent
Definition: DebugSerializer.h:64
void Comment(const std::string &comment)
Definition: DebugSerializer.cpp:76
void TextLine(const std::string &text)
Definition: DebugSerializer.cpp:81
const ScriptInterface & m_ScriptInterface
Definition: DebugSerializer.h:61
virtual bool IsDebug() const
Returns true if the serializer is being used in debug mode.
Definition: DebugSerializer.cpp:187
std::ostream & m_Stream
Definition: DebugSerializer.h:62
bool m_IsDebug
Definition: DebugSerializer.h:63
virtual void PutScriptVal(const char *name, JS::MutableHandleValue value)
Definition: DebugSerializer.cpp:153
virtual void PutString(const char *name, const std::string &value)
Definition: DebugSerializer.cpp:136
virtual void PutNumber(const char *name, uint8_t value)
Definition: DebugSerializer.cpp:86
A simple fixed-point number class.
Definition: Fixed.h:120
Serialization interface; see serialization overview.
Definition: ISerializer.h:121
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
uint8_t u8
Definition: types.h:37
unsigned short uint16_t
Definition: wposix_types.h:52
unsigned int uint32_t
Definition: wposix_types.h:53
short int16_t
Definition: wposix_types.h:38
unsigned char uint8_t
Definition: wposix_types.h:51
signed char int8_t
Definition: wposix_types.h:37