Files
redAcore/JSONparseCore.h
Charl Wentzel 3472f506b6 Major Update:
- JSONparseCore:
  - Add initialisations values for class params
  - Add method AddBase() to dynamically change DataTree
  - Added Error messages
- DeviceCore:
  - Implement ValueTree (JSON tree)
    - Node are added as devices & params are created/added
    - Nodes (and path) are referenced on devices & params
    - Node values are updated as device params are updated
  - Added Persistence File (not yet complete)
  - Updated InitDevices() & InitDeviceParams()
    - Split into smaller methods: CopyTemplateParam() & InitDeviceParam()
    - Load Device definition or Parameter maps from files
    - Allow loading of nested parameter map files
    - Load Parameter as JSON tree, generate names/path dynamically
2019-01-09 10:56:38 +02:00

89 lines
2.5 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:
CDataMember * DataTree = NULL;
// File operation
int InputHandle = -1;
int OutputHandle = -1;
CShiftBuffer * Buffer = NULL;
// Parsing operation
char * BufPos = NULL;
char * Mark = NULL;
int LineNo = 0;
int CharNo = 0;
bool RefillBuffer = false;
// Printing Operation
char Spacer[100] = "";
int SpacerLen = 0;
// Error
bool Error = false;
char ErrorText[100] = "";
// Parsing functions
void SkipWhiteSpace();
bool ParseString( char ** Value, int &pLen );
bool ParseObject( CDataMember * Object );
bool ParseArray( CDataMember * Array );
bool ParseString( CDataMember * Member );
bool ParsePrimitive( CDataMember * Member );
bool PrintString( char * String, int Len );
bool PrintObject( CDataMember * Object, const int Indent );
bool PrintArray( CDataMember * Object, const int Indent );
public:
CJSONparse();
CJSONparse( CDataMember * pDataTree );
~CJSONparse();
// Tree
bool SetBase( CDataMember * Object );
// 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_ */