Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FX::FXJSON Class Reference

The FXJSON serializer loads or saves an FXVariant to a json text file. More...

#include <FXJSON.h>

Inheritance diagram for FX::FXJSON:
FX::FXJSONFile

Public Types

enum  Error {
  ErrOK, ErrSave, ErrLoad, ErrToken,
  ErrColon, ErrComma, ErrBracket, ErrBrace,
  ErrQuotes, ErrNumber, ErrEnd
}
 
enum  Flow { Stream, Compact, Pretty }
 
enum  Direction { Stop = 0, Save = 1, Load = 2 }
 

Public Member Functions

 FXJSON ()
 Construct JSON serializer.
 
 FXJSON (FXchar *data, FXuval sz=4096, Direction d=Load)
 Construct JSON serializer and open for direction d. More...
 
FXbool open (FXchar *data=NULL, FXuval size=4096, Direction d=Load)
 Open JSON stream for given direction d. More...
 
Direction direction () const
 Return direction in effect.
 
FXuval size () const
 Return size of parse buffer.
 
Error load (FXVariant &variant)
 Load a variant from stream. More...
 
Error save (const FXVariant &variant)
 Save a variant to stream. More...
 
FXint getLine () const
 Return current line number.
 
FXint getColumn () const
 Return current column number.
 
void setNumericPrecision (FXint p)
 Floating point output precision control.
 
FXint getNumericPrecision () const
 
void setNumericFormat (FXint f)
 Floating point output precision control.
 
FXint getNumericFormat () const
 
void setOutputFlow (FXint f)
 Change output flow format (Stream, Compact, Pretty). More...
 
FXint getOutputFlow () const
 
void setIndentation (FXint d)
 Change indentation level for pretty print flow, the amount of indentation applied for each level.
 
FXint getIndentation () const
 
void setLineWrap (FXint w)
 Change column at which lines are wrapped.
 
FXint getLineWrap () const
 
virtual FXbool fill ()
 Fill buffer from file. More...
 
virtual FXbool flush ()
 Flush buffer to file. More...
 
virtual FXbool close ()
 Close stream and delete buffer, if owned.
 
virtual ~FXJSON ()
 Close JSON stream and clean up.
 

Static Public Member Functions

static const FXchar * getError (Error err)
 Returns error code for given error.
 

Protected Attributes

FXchar * begptr
 
FXchar * endptr
 
FXchar * sptr
 
FXchar * rptr
 
FXchar * wptr
 
FXint token
 
FXint column
 
FXint indent
 
FXint line
 
FXint wrap
 
Direction dir
 
FXuchar flow
 
FXuchar prec
 
FXuchar fmt
 
FXuchar dent
 
FXbool owns
 

Detailed Description

The FXJSON serializer loads or saves an FXVariant to a json text file.

Since FXVariant can contain an arbitrarily complex data structure, this provides applications with a convenient way to load and save state information in a well-defined and human-readable file format.

Member Enumeration Documentation

◆ Direction

Enumerator
Save 

Not active.

Load 

Save to device.

◆ Error

Enumerator
ErrSave 

No errors.

ErrLoad 

Unable to save.

ErrToken 

Unable to load.

ErrColon 

Illegal token.

ErrComma 

Expected colon ':'.

ErrBracket 

Expected comma ','.

ErrBrace 

Expected closing bracket.

ErrQuotes 

Expected closing brace.

ErrNumber 

Expected closing quotes.

ErrEnd 

Numeric conversion.

Unexpected end of file

◆ Flow

Enumerator
Compact 

Stream-of-consciousness output.

Pretty 

Compact, human readable output (default)

Pretty printed, indented output

Constructor & Destructor Documentation

◆ FXJSON()

FX::FXJSON::FXJSON ( FXchar *  data,
FXuval  sz = 4096,
Direction  d = Load 
)

Construct JSON serializer and open for direction d.

Use given buffer data of size sz, or allocate a local buffer.

Member Function Documentation

◆ fill()

virtual FXbool FX::FXJSON::fill ( )
virtual

Fill buffer from file.

Return false if not open for reading, or fail to read from disk.

Reimplemented in FX::FXJSONFile.

◆ flush()

virtual FXbool FX::FXJSON::flush ( )
virtual

Flush buffer to file.

Return false if not open for writing, or if fail to write to disk.

Reimplemented in FX::FXJSONFile.

◆ load()

Error FX::FXJSON::load ( FXVariant variant)

Load a variant from stream.

Return false if stream wasn't opened for loading, or syntax error.

◆ open()

FXbool FX::FXJSON::open ( FXchar *  data = NULL,
FXuval  size = 4096,
Direction  d = Load 
)

Open JSON stream for given direction d.

Use given buffer data of size sz, or allocate a local buffer.

◆ save()

Error FX::FXJSON::save ( const FXVariant variant)

Save a variant to stream.

Return false if stream wasn't opened for saving, or disk was full.

◆ setOutputFlow()

void FX::FXJSON::setOutputFlow ( FXint  f)
inline

Change output flow format (Stream, Compact, Pretty).

Stream is the most compact, but pretty much unreadable by humans; it aims to be compact. Compact is very human-readable while at the same time using minimum number of lines to represent the output. Pretty will print one item on each line, with indentation. It is very easily readable but produces large numbers of text lines.


The documentation for this class was generated from the following file:

Copyright © 1997-2018 Jeroen van der Zijp