Files
redAcore/JSONparseCore.h
Charl Wentzel 12a8ddb7ba Important Update:
- JSONparseCore:
  - Allow JSON to be parsed from string data
- DataTreeCore:
  - Allow GetMember to work with now path, ie. return BaseMember param
2018-10-28 22:36:31 +00:00

85 lines
2.3 KiB
C++

/*
* JSONparseCore.h
*
* Created on: 5 Mar 2017
* Author: wentzelc
*/
#ifndef REDACORE_JSONPARSECORE_H_
#define REDACORE_JSONPARSECORE_H_
// Standard C/C++ Libraries
#include <string.h>
#include <ctype.h>
// redA Libraries
#include "DataTreeCore.h"
#include "CharBufferCore.h"
//---------------------------------------------------------------------------
class CJSONparse
{
private:
CDataTree * DataTree;
// File operation
int InputHandle;
int OutputHandle;
CShiftBuffer * Buffer;
// Parsing operation
char * BufPos;
char * Mark;
int LineNo;
int CharNo;
bool RefillBuffer;
// Printing Operation
char Spacer[100];
int SpacerLen;
// Error
bool Error;
char ErrorText[100];
// Parsing functions
void SkipWhiteSpace();
bool ParseString( char ** Value, int &pLen );
bool ParseObject( TDataMember * Object );
bool ParseArray( TDataMember * Array );
bool ParseString( TDataMember * Member );
bool ParsePrimitive( TDataMember * Member );
bool PrintString( char * String, int Len );
bool PrintObject( TDataMember * Object, const int Indent );
bool PrintArray( TDataMember * Object, const int Indent );
public:
CJSONparse( CDataTree * pDataTree );
~CJSONparse();
// Buffer operation
bool CreateBuffer( int pBufLen );
bool FillBuffer();
void FreeBuffer();
bool ReadFromBuffer( const char * BasePath );
// Input
bool ReadFromString( const char * BasePath, const char * InString, const int Len );
bool ReadFromHandle( const char * BasePath, const int Handle, bool pRefillBuffer );
bool ReadFromFile( const char * BasePath, const char * Path, const char * FileName );
bool ReadFromFile( const char * BasePath, const char * FilePath );
// Output
bool WriteToHandle( const char * BasePath, const int Handle, const int Indent = 2 );
bool WriteToScreen( const char * BasePath, const int Indent = 2 );
bool WriteToFile( const char * BasePath, const char * Path, const char * FileName, const int Indent = 2 );
bool WriteToFile( const char * BasePath, const char * FilePath, const int Indent = 2 );
const char * GetError() { return ((Error)? ErrorText : "Success"); };
};
#endif /* REDACORE_JSONPARSECORE_H_ */