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

FX::FXINI Class Reference

The FXINI class loads or saves an FXVariant to an .INI text file. More...

#include <FXINI.h>

Inheritance diagram for FX::FXINI:
FX::FXParseBuffer FX::FXINIFile

Public Types

enum  Error {
  ErrOK, ErrSave, ErrLoad, ErrToken,
  ErrColon, ErrComma, ErrBracket, ErrBrace,
  ErrQuotes, ErrQuote, ErrNumber, ErrEnd
}
 
- Public Types inherited from FX::FXParseBuffer
enum  Direction { Stop = 0, Save = 1, Load = 2 }
 

Public Member Functions

 FXINI ()
 Initialize INI parser.
 
 FXINI (FXchar *buffer, FXuval sz=8192, Direction d=Load)
 Initialize INI parser with buffer of size and direction. More...
 
FXbool open (FXchar *buffer, FXuval sz=8192, Direction d=Load)
 Open INI parse buffer with given size and direction. More...
 
FXint getLine () const
 Return current line number.
 
FXint getColumn () const
 Return current column number.
 
FXlong getOffset () const
 Return offset from begin of file.
 
Error load (FXVariant &variant)
 Load a variant from stream. More...
 
Error save (const FXVariant &variant)
 Save a variant to stream. More...
 
void setNumericPrecision (FXuchar p)
 Floating point output precision control. More...
 
FXuchar getNumericPrecision () const
 
void setNumericFormat (FXuchar f)
 Floating point output format control. More...
 
FXuchar getNumericFormat () const
 
void setEscapeMode (FXuchar e)
 Change string escape mode; 0=don't escape unicode in strings; 1=escape unicode as , 2=escape UTF8 multi-byte characters as or . More...
 
FXuchar getEscapeMode () const
 
FXbool close ()
 Close INI parser. More...
 
virtual ~FXINI ()
 Close INI parser and clean up.
 
- Public Member Functions inherited from FX::FXParseBuffer
 FXParseBuffer ()
 Initialize parse buffer to empty.
 
 FXParseBuffer (FXchar *buffer, FXuval sz=4096, Direction d=Load)
 Initialize parse buffer with given size and direction. More...
 
FXbool open (FXchar *buffer=nullptr, FXuval sz=4096, Direction d=Load)
 Open parse buffer with given size and direction.
 
Direction direction () const
 Return current direction.
 
FXuval size () const
 Return current buffer size.
 
virtual FXival fill (FXival count)
 Read at least count bytes into buffer; return bytes available, or -1 for error.
 
virtual FXival flush (FXival count)
 Write at least count bytes from buffer; return space available, or -1 for error.
 
FXbool close ()
 Close parse buffer.
 
virtual ~FXParseBuffer ()
 Clean up and close buffer.
 

Static Public Member Functions

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

Protected Attributes

FXlong offset
 
FXint token
 
FXint column
 
FXint indent
 
FXint line
 
FXuchar state
 
FXuchar prec
 
FXuchar fmt
 
FXuchar esc
 
- Protected Attributes inherited from FX::FXParseBuffer
FXchar * begptr
 
FXchar * endptr
 
FXchar * wptr
 
FXchar * rptr
 
FXchar * sptr
 
Direction dir
 

Additional Inherited Members

- Protected Member Functions inherited from FX::FXParseBuffer
FXbool need (FXival count)
 
FXbool emit (FXchar ch, FXint count)
 
FXbool emit (const FXchar *str, FXint count)
 

Detailed Description

The FXINI class loads or saves an FXVariant to an .INI text file.

The FXVariant structure is subject to some limits:

  • Must be a map of maps, of the form variant[SECTION][KEY] where SECTION and KEY are both strings.
  • Each KEY maps to boolean, integer, double, or string type, or be empty (equal to FXVariant::null).
  • The variant tree may contain other items, but only items of the aforementioned types will be serialized to the .INI file.

When saving, numeric values are printed with configurable precision; (default=15 digits which results in minimal information loss for real numbers). Values may be arbitrary strings, and this includes any legal UTF8- encoded value. When saving, strings may be escaped to ensure the information may be read back in unchanged. The following applies to when strings are escaped:

  • Escape mode 0: UTF8 characters are passed unescaped.
  • Escape mode 1: UTF8 characters are escaped as .
  • Escape mode 2: UTF8 will be escaed using Unicode escape sequences of the for or (two surrogate-pairs escape codes for code points exceeding 16 bits).

The default setting is to allow UTF8 characters in the output.

Member Enumeration Documentation

◆ 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.

ErrQuote 

Expected closing quotes.

ErrNumber 

Expected closing quote.

ErrEnd 

Numeric conversion.

Unexpected end of file

Constructor & Destructor Documentation

◆ FXINI()

FX::FXINI::FXINI ( FXchar *  buffer,
FXuval  sz = 8192,
Direction  d = Load 
)

Initialize INI parser with buffer of size and direction.

Text location (column, line number, byte offset) is reset.

Member Function Documentation

◆ close()

FXbool FX::FXINI::close ( )

Close INI parser.

To permit diagnostics, text location not reset.

◆ load()

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

Load a variant from stream.

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

◆ open()

FXbool FX::FXINI::open ( FXchar *  buffer,
FXuval  sz = 8192,
Direction  d = Load 
)

Open INI parse buffer with given size and direction.

Text location (column, line number, byte offset) is reset.

◆ save()

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

Save a variant to stream.

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

◆ setEscapeMode()

void FX::FXINI::setEscapeMode ( FXuchar  e)
inline

Change string escape mode; 0=don't escape unicode in strings; 1=escape unicode as , 2=escape UTF8 multi-byte characters as or .

Default is to escape control characters only.

◆ setNumericFormat()

void FX::FXINI::setNumericFormat ( FXuchar  f)
inline

Floating point output format control.

The format mode is interpreted as follows:

0 No exponent. 1 Exponent. 2 Output exponent when required.

The default mode is 2.

◆ setNumericPrecision()

void FX::FXINI::setNumericPrecision ( FXuchar  p)
inline

Floating point output precision control.

This controls the number of significant digits written to the output. The default is 15.


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

Copyright © 1997-2022 Jeroen van der Zijp