RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
soa/jsoncpp/writer.h
00001 // Copyright 2007-2010 Baptiste Lepilleur
00002 // Distributed under MIT license, or public domain if desired and
00003 // recognized in your jurisdiction.
00004 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
00005 #ifndef JSON_WRITER_H_INCLUDED
00006 # define JSON_WRITER_H_INCLUDED
00007 
00008 # include "value.h"
00009 # include <vector>
00010 # include <string>
00011 # include <iostream>
00012 
00013 namespace Json {
00014 
00015    class Value;
00016 
00019    class JSON_API Writer
00020    {
00021    public:
00022       virtual ~Writer();
00023 
00024       virtual std::string write( const Value &root ) = 0;
00025    };
00026 
00033    class JSON_API FastWriter : public Writer
00034    {
00035    public:
00036       FastWriter();
00037       virtual ~FastWriter(){}
00038 
00039       void enableYAMLCompatibility();
00040 
00041    public: // overridden from Writer
00042       virtual std::string write( const Value &root );
00043 
00044    private:
00045       void writeValue( const Value &value );
00046 
00047       std::string document_;
00048       bool yamlCompatiblityEnabled_;
00049    };
00050 
00069    class JSON_API StyledWriter: public Writer
00070    {
00071    public:
00072       StyledWriter();
00073       virtual ~StyledWriter(){}
00074 
00075    public: // overridden from Writer
00080       virtual std::string write( const Value &root );
00081 
00082    private:
00083       void writeValue( const Value &value );
00084       void writeArrayValue( const Value &value );
00085       bool isMultineArray( const Value &value );
00086       void pushValue( const std::string &value );
00087       void writeIndent();
00088       void writeWithIndent( const std::string &value );
00089       void indent();
00090       void unindent();
00091       void writeCommentBeforeValue( const Value &root );
00092       void writeCommentAfterValueOnSameLine( const Value &root );
00093       bool hasCommentForValue( const Value &value );
00094       static std::string normalizeEOL( const std::string &text );
00095 
00096       typedef std::vector<std::string> ChildValues;
00097 
00098       ChildValues childValues_;
00099       std::string document_;
00100       std::string indentString_;
00101       int rightMargin_;
00102       int indentSize_;
00103       bool addChildValues_;
00104    };
00105 
00126    class JSON_API StyledStreamWriter
00127    {
00128    public:
00129       StyledStreamWriter( std::string indentation="\t" );
00130       ~StyledStreamWriter(){}
00131 
00132    public:
00138       void write( std::ostream &out, const Value &root );
00139 
00140    private:
00141       void writeValue( const Value &value );
00142       void writeArrayValue( const Value &value );
00143       bool isMultineArray( const Value &value );
00144       void pushValue( const std::string &value );
00145       void writeIndent();
00146       void writeWithIndent( const std::string &value );
00147       void indent();
00148       void unindent();
00149       void writeCommentBeforeValue( const Value &root );
00150       void writeCommentAfterValueOnSameLine( const Value &root );
00151       bool hasCommentForValue( const Value &value );
00152       static std::string normalizeEOL( const std::string &text );
00153 
00154       typedef std::vector<std::string> ChildValues;
00155 
00156       ChildValues childValues_;
00157       std::ostream* document_;
00158       std::string indentString_;
00159       int rightMargin_;
00160       std::string indentation_;
00161       bool addChildValues_;
00162    };
00163 
00164    std::string JSON_API valueToString( Int value );
00165    std::string JSON_API valueToString( UInt value );
00166    std::string JSON_API valueToString( double value );
00167    std::string JSON_API valueToString( bool value );
00168    std::string JSON_API valueToQuotedString( const char *value );
00169 
00172    std::ostream& operator<<( std::ostream&, const Value &root );
00173 
00174 } // namespace Json
00175 
00176 
00177 
00178 #endif // JSON_WRITER_H_INCLUDED
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator