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 jsoncollector {
10  namespace Json {
11 
12  class Value;
13 
16  class JSON_API Writer {
17  public:
18  virtual ~Writer();
19 
20  virtual std::string write(const Value &root) = 0;
21  };
22 
29  class JSON_API FastWriter : public Writer {
30  public:
31  FastWriter();
32  ~FastWriter() override {}
33 
34  void enableYAMLCompatibility();
35 
36  public: // overridden from Writer
37  std::string write(const Value &root) override;
38 
39  private:
40  void writeValue(const Value &value);
41 
44  };
45 
64  class JSON_API StyledWriter : public Writer {
65  public:
66  StyledWriter();
67  ~StyledWriter() override {}
68 
69  public: // overridden from Writer
74  std::string write(const Value &root) override;
75 
76  private:
77  void writeValue(const Value &value);
78  void writeArrayValue(const Value &value);
79  bool isMultineArray(const Value &value);
80  void pushValue(const std::string &value);
81  void writeIndent();
82  void writeWithIndent(const std::string &value);
83  void indent();
84  void unindent();
85  void writeCommentBeforeValue(const Value &root);
86  void writeCommentAfterValueOnSameLine(const Value &root);
87  bool hasCommentForValue(const Value &value);
88  static std::string normalizeEOL(const std::string &text);
89 
90  typedef std::vector<std::string> ChildValues;
91 
98  };
99 
121  public:
124 
125  public:
131  void write(std::ostream &out, const Value &root);
132 
133  private:
134  void writeValue(const Value &value);
135  void writeArrayValue(const Value &value);
136  bool isMultineArray(const Value &value);
137  void pushValue(const std::string &value);
138  void writeIndent();
139  void writeWithIndent(const std::string &value);
140  void indent();
141  void unindent();
142  void writeCommentBeforeValue(const Value &root);
143  void writeCommentAfterValueOnSameLine(const Value &root);
144  bool hasCommentForValue(const Value &value);
145  static std::string normalizeEOL(const std::string &text);
146 
147  typedef std::vector<std::string> ChildValues;
148 
150  std::ostream *document_;
155  };
156 
162 
165  std::ostream &operator<<(std::ostream &, const Value &root);
166 
167  } // namespace Json
168 } // namespace jsoncollector
169 
170 #endif // JSON_WRITER_H_INCLUDED
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string...
Definition: writer.h:120
std::vector< std::string > ChildValues
Definition: writer.h:90
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
std::vector< std::string > ChildValues
Definition: writer.h:147
Abstract class for writers.
Definition: writer.h:16
Outputs a Value in JSON format without formatting (not human friendly).
Definition: writer.h:29
Writes a Value in JSON format in a human friendly way.
Definition: writer.h:64
#define JSON_API
Definition: config.h:40
reco::JetExtendedAssociation::JetExtendedData Value
Definition: value.py:1
unsigned int UInt
Definition: forwards.h:21
std::string valueToString(Int value)
void writeValue(std::ostream &os, int indentation, int const &value_, ValueFormat format)
std::string valueToQuotedString(const char *value)
Represents a JSON value.
Definition: value.h:101
JSON (JavaScript Object Notation).
Definition: DataPoint.h:26