test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
16  {
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  {
31  public:
32  FastWriter();
33  virtual ~FastWriter(){}
34 
35  void enableYAMLCompatibility();
36 
37  public: // overridden from Writer
38  virtual std::string write( const Value &root );
39 
40  private:
41  void writeValue( const Value &value );
42 
45  };
46 
66  {
67  public:
68  StyledWriter();
69  virtual ~StyledWriter(){}
70 
71  public: // overridden from Writer
76  virtual std::string write( const Value &root );
77 
78  private:
79  void writeValue( const Value &value );
80  void writeArrayValue( const Value &value );
81  bool isMultineArray( const Value &value );
82  void pushValue( const std::string &value );
83  void writeIndent();
84  void writeWithIndent( const std::string &value );
85  void indent();
86  void unindent();
87  void writeCommentBeforeValue( const Value &root );
88  void writeCommentAfterValueOnSameLine( const Value &root );
89  bool hasCommentForValue( const Value &value );
90  static std::string normalizeEOL( const std::string &text );
91 
92  typedef std::vector<std::string> ChildValues;
93 
100  };
101 
123  {
124  public:
125  StyledStreamWriter( std::string indentation="\t" );
127 
128  public:
134  void write( std::ostream &out, const Value &root );
135 
136  private:
137  void writeValue( const Value &value );
138  void writeArrayValue( const Value &value );
139  bool isMultineArray( const Value &value );
140  void pushValue( const std::string &value );
141  void writeIndent();
142  void writeWithIndent( const std::string &value );
143  void indent();
144  void unindent();
145  void writeCommentBeforeValue( const Value &root );
146  void writeCommentAfterValueOnSameLine( const Value &root );
147  bool hasCommentForValue( const Value &value );
148  static std::string normalizeEOL( const std::string &text );
149 
150  typedef std::vector<std::string> ChildValues;
151 
153  std::ostream* document_;
158  };
159 
165 
168  std::ostream& operator<<( std::ostream&, const Value &root );
169 
170 } // namespace Json
171 
172 
173 
174 #endif // JSON_WRITER_H_INCLUDED
unsigned int UInt
Definition: forwards.h:20
std::vector< std::string > ChildValues
Definition: writer.h:92
std::ostream * document_
Definition: writer.h:153
#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:122
std::string indentString_
Definition: writer.h:96
bool yamlCompatiblityEnabled_
Definition: writer.h:44
std::string document_
Definition: writer.h:43
Represents a JSON value.
Definition: value.h:111
bool addChildValues_
Definition: writer.h:99
Outputs a Value in JSON format without formatting (not human friendly).
Definition: writer.h:29
std::string valueToString(Int value)
Abstract class for writers.
Definition: writer.h:15
reco::JetExtendedAssociation::JetExtendedData Value
tuple text
Definition: runonSM.py:42
virtual ~StyledWriter()
Definition: writer.h:69
std::string indentString_
Definition: writer.h:154
tuple out
Definition: dbtoconf.py:99
int Int
Definition: forwards.h:16
void writeValue(std::ostream &os, int indentation, int const &value_, ValueFormat format)
std::string indentation_
Definition: writer.h:156
ChildValues childValues_
Definition: writer.h:152
std::string document_
Definition: writer.h:95
std::vector< std::string > ChildValues
Definition: writer.h:150
Writes a Value in JSON format in a human friendly way.
Definition: writer.h:65
virtual ~FastWriter()
Definition: writer.h:33
ChildValues childValues_
Definition: writer.h:94
string root
initialization
Definition: dbtoconf.py:70