- Split CConfigCore into two classes: - DataTreeCore.h - Tree data structure and access - JSONparseCore.h - JSON parsing functionality - Renamed TConfigParam struct to TDataMember - Renamed most of CDataTreeCore methods
81 lines
1.8 KiB
C++
81 lines
1.8 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 ParseObject( TDataMember * Object );
|
|
bool ParseString( char ** Value, int * pLen = NULL, EDataType * pType = NULL );
|
|
bool ParsePrimitive( char ** Value, int * pLen = NULL, EDataType * pType = NULL );
|
|
|
|
bool SaveObject( TDataMember * Object, const int Indent );
|
|
|
|
public:
|
|
CJSONparse( CDataTree * pDataTree );
|
|
~CJSONparse();
|
|
|
|
bool LoadFile( const char * FilePath, int pBufLen = 500 );
|
|
bool SaveFile( const char * FilePath, const int ValueTab = 20 );
|
|
|
|
const char * GetError() { return ((Error)? ErrorText : "Success"); };
|
|
};
|
|
|
|
#endif /* REDACORE_JSONPARSECORE_H_ */
|