Files
redAcore/JSONparseCore.h
Charl Wentzel a22f60b152 Major Update:
- Bug fix: BufferCore - set correct auto buffer size
- Change Get/Set methods to use BaseReference and full path instead of
    ParentPath and MemberName
- Add Create param to all Get methods (create if not found)
- Implement arrays & parsing of arrays
- Set CJSONparse as friend class to DataTree (access protected methods)
- Print JSON to screen
2017-03-26 22:26:52 +02:00

86 lines
1.9 KiB
C++

/*
* JSONparseCore.h
*
* Created on: 5 Mar 2017
* Author: wentzelc
*/
#ifndef REDACORE_JSONPARSECORE_H_
#define REDACORE_JSONPARSECORE_H_
// redA Libraries
#include <BufferCore.h>
#include <DataTreeCore.h>
// Standard C/C++ Libraries
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
//---------------------------------------------------------------------------
class CJSONparse
{
private:
CDataTree * DataTree;
// File operation
int InputHandle;
int OutputHandle;
CShiftBuffer * Buffer;
// Parsing operation
char * BufEnd;
char * BufPos;
char * LineMark;
int LineNo;
int Level;
// Printing Operation
char Spacer[100];
int SpacerLen;
// Error
bool Error;
char ErrorText[100];
// File Buffer operation
bool CreateBuffer( int pBufLen );
bool FillBuffer();
void FreeBuffer();
// Parsing functions
inline void SkipWhiteSpace() {
while (isspace(*BufPos)) {
if (*BufPos == '\n') {
LineMark = BufPos;
LineNo++;
}
BufPos++;
}
}
bool ParseString( char ** Value, int &pLen );
bool ParseObject( TDataMember * Object );
bool ParseArray( TDataMember * Array );
bool ParseString( TDataMember * Member );
bool ParsePrimitive( TDataMember * Member );
bool PrintObject( TDataMember * Object, const int Indent );
bool PrintArray( TDataMember * Object, const int Indent );
public:
CJSONparse( CDataTree * pDataTree );
~CJSONparse();
bool PrintToScreen( const int Indent );
bool LoadFromFile( const char * FilePath, int pBufLen = 500 );
bool SaveToFile( const char * FilePath, const int Indent = 2 );
const char * GetError() { return ((Error)? ErrorText : "Success"); };
};
#endif /* REDACORE_JSONPARSECORE_H_ */