PyNE C++
jsoncustomwriter.h
1 /**********************************************************************
2 Copyright (c) 2013 by Matt Swain <m.swain@me.com>
3 
4 The MIT License
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 
24 ***********************************************************************/
25 
26 #ifndef PYNE_46Z7LQYFI5HZNASIPCWHVX3X5E
27 #define PYNE_46Z7LQYFI5HZNASIPCWHVX3X5E
28 
29 #include <string>
30 
31 namespace Json {
32 
42  class JSON_API CustomWriter : public Writer
43  {
44  public:
45  CustomWriter( std::string opencurly = "{",
46  std::string closecurly = "}",
47  std::string opensquare = "[",
48  std::string closesquare = "]",
49  std::string colon = ":",
50  std::string comma = ",",
51  std::string indent = " ",
52  int maxWidth = 74);
53  virtual ~CustomWriter(){}
54 
55  public: // overridden from Writer
56  virtual std::string write( const Value &root );
57 
58  private:
59  void writeValue( const Value &value, std::string &doc, bool forceSingleLine );
60  bool isMultiline( const Value &value );
61  void indent();
62  void unindent();
63 
64  std::string document_;
65  std::string indentString_;
66  std::string opencurly_;
67  std::string closecurly_;
68  std::string opensquare_;
69  std::string closesquare_;
70  std::string colon_;
71  std::string comma_;
72  std::string indent_;
73  int maxWidth_;
74  };
75 
76 }
77 
78 #endif
JSON (JavaScript Object Notation).
Definition: json-forwards.h:162