File indexing completed on 2023-03-17 11:00:28
0001 #ifndef JSON_WRITER_H_INCLUDED
0002 #define JSON_WRITER_H_INCLUDED
0003
0004 #include "value.h"
0005 #include <vector>
0006 #include <string>
0007 #include <iostream>
0008
0009 namespace Json {
0010
0011 class Value;
0012
0013
0014
0015 class JSON_API Writer {
0016 public:
0017 virtual ~Writer();
0018
0019 virtual std::string write(const Value &root) = 0;
0020 };
0021
0022
0023
0024
0025
0026
0027
0028 class JSON_API FastWriter : public Writer {
0029 public:
0030 FastWriter();
0031 ~FastWriter() override {}
0032
0033 void enableYAMLCompatibility();
0034
0035 public:
0036 std::string write(const Value &root) override;
0037
0038 private:
0039 void writeValue(const Value &value);
0040
0041 std::string document_;
0042 bool yamlCompatiblityEnabled_;
0043 };
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 class JSON_API StyledWriter : public Writer {
0064 public:
0065 StyledWriter();
0066 ~StyledWriter() override {}
0067
0068 public:
0069
0070
0071
0072
0073 std::string write(const Value &root) override;
0074
0075 private:
0076 void writeValue(const Value &value);
0077 void writeArrayValue(const Value &value);
0078 bool isMultineArray(const Value &value);
0079 void pushValue(const std::string &value);
0080 void writeIndent();
0081 void writeWithIndent(const std::string &value);
0082 void indent();
0083 void unindent();
0084 void writeCommentBeforeValue(const Value &root);
0085 void writeCommentAfterValueOnSameLine(const Value &root);
0086 bool hasCommentForValue(const Value &value);
0087 static std::string normalizeEOL(const std::string &text);
0088
0089 typedef std::vector<std::string> ChildValues;
0090
0091 ChildValues childValues_;
0092 std::string document_;
0093 std::string indentString_;
0094 int rightMargin_;
0095 int indentSize_;
0096 bool addChildValues_;
0097 };
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 class JSON_API StyledStreamWriter {
0120 public:
0121 StyledStreamWriter(std::string indentation = "\t");
0122 ~StyledStreamWriter() {}
0123
0124 public:
0125
0126
0127
0128
0129
0130 void write(std::ostream &out, const Value &root);
0131
0132 private:
0133 void writeValue(const Value &value);
0134 void writeArrayValue(const Value &value);
0135 bool isMultineArray(const Value &value);
0136 void pushValue(const std::string &value);
0137 void writeIndent();
0138 void writeWithIndent(const std::string &value);
0139 void indent();
0140 void unindent();
0141 void writeCommentBeforeValue(const Value &root);
0142 void writeCommentAfterValueOnSameLine(const Value &root);
0143 bool hasCommentForValue(const Value &value);
0144 static std::string normalizeEOL(const std::string &text);
0145
0146 typedef std::vector<std::string> ChildValues;
0147
0148 ChildValues childValues_;
0149 std::ostream *document_;
0150 std::string indentString_;
0151 int rightMargin_;
0152 std::string indentation_;
0153 bool addChildValues_;
0154 };
0155
0156 std::string JSON_API valueToString(Int value);
0157 std::string JSON_API valueToString(UInt value);
0158 std::string JSON_API valueToString(double value);
0159 std::string JSON_API valueToString(bool value);
0160 std::string JSON_API valueToQuotedString(const char *value);
0161
0162
0163
0164 std::ostream &operator<<(std::ostream &, const Value &root);
0165
0166 }
0167
0168 #endif