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_DEBUGSERIALIZER
19 : #define INCLUDED_DEBUGSERIALIZER
20 :
21 : #include "ISerializer.h"
22 :
23 : /**
24 : * Serialize to a human-readable YAML-like format.
25 : */
26 21 : class CDebugSerializer : public ISerializer
27 : {
28 : NONCOPYABLE(CDebugSerializer);
29 : public:
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 :
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:
61 : const ScriptInterface& m_ScriptInterface;
62 : std::ostream& m_Stream;
63 : bool m_IsDebug;
64 : int m_Indent;
65 : };
66 :
67 : #endif // INCLUDED_DEBUGSERIALIZER
|