CMS 3D CMS Logo

writer.h
Go to the documentation of this file.
1 #ifndef JSON_WRITER_H_INCLUDED
2 #define JSON_WRITER_H_INCLUDED
3 
4 #include "value.h"
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 
9 namespace Json {
10 
11  class Value;
12 
15  class JSON_API Writer {
16  public:
17  virtual ~Writer();
18 
19  virtual std::string write(const Value &root) = 0;
20  };
21 
28  class JSON_API FastWriter : public Writer {
29  public:
30  FastWriter();
31  ~FastWriter() override {}
32 
33  void enableYAMLCompatibility();
34 
35  public: // overridden from Writer
36  std::string write(const Value &root) override;
37 
38  private:
39  void writeValue(const Value &value);
40 
43  };
44 
63  class JSON_API StyledWriter : public Writer {
64  public:
65  StyledWriter();
66  ~StyledWriter() override {}
67 
68  public: // overridden from Writer
73  std::string write(const Value &root) override;
74 
75  private:
76  void writeValue(const Value &value);
77  void writeArrayValue(const Value &value);
78  bool isMultineArray(const Value &value);
79  void pushValue(const std::string &value);
80  void writeIndent();
81  void writeWithIndent(const std::string &value);
82  void indent();
83  void unindent();
84  void writeCommentBeforeValue(const Value &root);
85  void writeCommentAfterValueOnSameLine(const Value &root);
86  bool hasCommentForValue(const Value &value);
87  static std::string normalizeEOL(const std::string &text);
88 
89  typedef std::vector<std::string> ChildValues;
90 
97  };
98 
120  public:
123 
124  public:
130  void write(std::ostream &out, const Value &root);
131 
132  private:
133  void writeValue(const Value &value);
134  void writeArrayValue(const Value &value);
135  bool isMultineArray(const Value &value);
136  void pushValue(const std::string &value);
137  void writeIndent();
138  void writeWithIndent(const std::string &value);
139  void indent();
140  void unindent();
141  void writeCommentBeforeValue(const Value &root);
142  void writeCommentAfterValueOnSameLine(const Value &root);
143  bool hasCommentForValue(const Value &value);
144  static std::string normalizeEOL(const std::string &text);
145 
146  typedef std::vector<std::string> ChildValues;
147 
149  std::ostream *document_;
154  };
155 
161 
164  std::ostream &operator<<(std::ostream &, const Value &root);
165 
166 } // namespace Json
167 
168 #endif // JSON_WRITER_H_INCLUDED
unsigned int UInt
Definition: forwards.h:20
std::vector< std::string > ChildValues
Definition: writer.h:89
std::ostream * document_
Definition: writer.h:149
#define JSON_API
Definition: config.h:40
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
std::string valueToQuotedString(const char *value)
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string...
Definition: writer.h:119
std::string indentString_
Definition: writer.h:93
bool yamlCompatiblityEnabled_
Definition: writer.h:42
std::string document_
Definition: writer.h:41
Represents a JSON value.
Definition: value.h:99
bool addChildValues_
Definition: writer.h:96
Outputs a Value in JSON format without formatting (not human friendly).
Definition: writer.h:28
std::string valueToString(Int value)
Abstract class for writers.
Definition: writer.h:15
reco::JetExtendedAssociation::JetExtendedData Value
Definition: value.py:1
JSON (JavaScript Object Notation).
std::string indentString_
Definition: writer.h:150
int Int
Definition: forwards.h:16
~FastWriter() override
Definition: writer.h:31
void writeValue(std::ostream &os, int indentation, int const &value_, ValueFormat format)
std::string indentation_
Definition: writer.h:152
ChildValues childValues_
Definition: writer.h:148
std::string document_
Definition: writer.h:92
std::vector< std::string > ChildValues
Definition: writer.h:146
Writes a Value in JSON format in a human friendly way.
Definition: writer.h:63
ChildValues childValues_
Definition: writer.h:91
~StyledWriter() override
Definition: writer.h:66