jsonwriter.h

Go to the documentation of this file.
00001 
00002 // Name:        jsonwriter.h
00003 // Purpose:     the generator of JSON text from a JSON value
00004 // Author:      Luciano Cattani
00005 // Created:     2007/09/15
00006 // RCS-ID:      $Id: jsonwriter.h,v 1.4 2008/03/03 19:05:45 luccat Exp $
00007 // Copyright:   (c) 2007 Luciano Cattani
00008 // Licence:     wxWidgets licence
00010 
00011 #if !defined( _WX_JSONWRITER_H )
00012 #define _WX_JSONWRITER_H
00013 
00014 #ifdef __GNUG__
00015     #pragma interface "jsonwriter.h"
00016 #endif
00017 
00018 // For compilers that support precompilation, includes "wx/wx.h".
00019 #include "wx/wxprec.h"
00020  
00021 #ifdef __BORLANDC__
00022     #pragma hdrstop
00023 #endif
00024 
00025 // for all others, include the necessary headers (this file is usually all you
00026 // need because it includes almost all "standard" wxWidgets headers)
00027 #ifndef WX_PRECOMP
00028     #include <wx/stream.h>
00029     #include <wx/string.h>
00030 #endif
00031 
00032 #include "json_defs.h"
00033 #include "jsonval.h"
00034 
00035 
00036 // The 'style' flags for the writer
00037 // BIT= 10 9 8 7 6 5 4 3 2 1 0
00038 //       | | | | | | | | | | |
00039 //       | | | | | | | | | |  -> 1=styled (indentation), 0=not styled (other bits ignored)
00040 //       | | | | | | | | |  ---> 0=do not write comments, 1=write comments
00041 //       | | | | | | | |  -----> 1=force comments to be written before.the value
00042 //       | | | | | | |  -------> 1=forcecomments to be written after the value
00043 //       | | | | | |  ---------> 0=do not split strings, 1=split strings
00044 //       | | | | |  -----------> 1=do not add linefeeds between values (STYLED only)
00045 //       | | | |  -------------> 1=escape the solidus '/' character
00046 //       | | |  ---------------> 1=multiline string (LF and TAB not escaped)
00047 //       | |  -----------------> 1=prepend a plus (+) sign to unsigned integers
00048 //       |  -------------------> 1=use tabs for indentation
00049 //        ---------------------> 1= do not add indentation (STYLED only)
00050 enum {
00051   wxJSONWRITER_NONE            = 0,
00052   wxJSONWRITER_STYLED          = 1,
00053   wxJSONWRITER_WRITE_COMMENTS  = 2,
00054   wxJSONWRITER_COMMENTS_BEFORE = 4,
00055   wxJSONWRITER_COMMENTS_AFTER  = 8,
00056   wxJSONWRITER_SPLIT_STRING    = 16,
00057   wxJSONWRITER_NO_LINEFEEDS    = 32,
00058   wxJSONWRITER_ESCAPE_SOLIDUS     = 64,
00059   wxJSONWRITER_MULTILINE_STRING   = 128,
00060   wxJSONWRITER_RECOGNIZE_UNSIGNED = 256,
00061   wxJSONWRITER_TAB_INDENT         = 512,
00062   wxJSONWRITER_NO_INDENTATION     = 1024
00063 };
00064 
00065 // class declaration
00066 
00067 class WXDLLIMPEXP_JSON wxJSONWriter
00068 {
00069 public:
00070   wxJSONWriter( int style = wxJSONWRITER_STYLED, int indent = 0, int step = 3 );
00071   ~wxJSONWriter();
00072 
00073   void Write( const wxJSONValue& value, wxString& str );
00074   void Write( const wxJSONValue& value, wxOutputStream& os );
00075 
00076 protected:
00077 
00078   int  DoWrite( const wxJSONValue& value, const wxString* key,
00079                                 bool comma );
00080   int  WriteIndent();
00081   int  WriteIndent( int num );
00082   bool IsSpace( wxChar ch );
00083   bool IsPunctuation( wxChar ch );
00084 
00085   int  WriteString( const wxString& str );
00086   int  WriteStringValue( const wxString& str );
00087   int  WritePrimitiveValue( const wxJSONValue& value );
00088   int  WriteInvalid();
00089   int  WriteSeparator();
00090 
00091   // the following functions are no more used: replaced by 'WritePrimitiveValue'
00092   // int  WriteInt( int i );
00093   // int  WriteUInt( unsigned int ui );
00094   // int  WriteBool( bool b );
00095   // int  WriteDouble( double d );
00096   // int  WriteNull();
00097   // int  WriteEmpty();
00098 
00099   int  WriteKey( const wxString& key );
00100   int  WriteComment( const wxJSONValue& value, bool indent );
00101   int  WriteChar( wxChar ch );
00102 
00103   int  WriteError( const wxString& err );
00104 
00105 private:
00107   int   m_style;
00108 
00110   int   m_indent;
00111 
00113   int   m_step;
00114 
00116   int   m_level;
00117 
00119   void* m_outObject;
00120 
00122   int   m_outType;
00123 
00125 
00130   wxMBConv*  m_conv; 
00131 
00132   // The line number when printing JSON text output (not yet used)
00133   int   m_lineNo;
00134 
00135   // The column number when printing JSON text output
00136   int   m_colNo;
00137 
00138 
00139 };
00140 
00141 
00142 #endif                  // not defined _WX_JSONWRITER_H
00143 
00144 
00145 

Generated on Mon Aug 18 22:54:22 2008 for wxJSON by  doxygen 1.4.7