- DataTreeCore: - Merge TDataMember and CDataTree into => CDataMember - Each node, incl root is now CDataMember object - Modified function to not require BaseMember (Object is basemember) - Split/duplicat most functions to require, or not require child path - Added isNull/Object/Array/Sting() etc methods - Many other methods removed or restructured - Updated DataTree usage in: JSONparseCore, ApplicationCore, FunctionCore, SelectableCore, WatchdogCore
116 lines
5.1 KiB
C++
116 lines
5.1 KiB
C++
/*
|
|
* DataTreeCore.h
|
|
*
|
|
* Created on: 5 Mar 2017
|
|
* Author: wentzelc
|
|
*/
|
|
|
|
#ifndef REDACORE_DATATREECORE_H_
|
|
#define REDACORE_DATATREECORE_H_
|
|
|
|
// Standard C/C++ Libraries
|
|
#include <stdlib.h>
|
|
|
|
// redA Libraries
|
|
#include "CharBufferCore.h"
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
typedef enum { jtNull = 0, jtBool = 1, jtInt = 2, jtFloat = 3, jtString = 4, jtArray = 5, jtObject = 6 } EDataType;
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// One Config Members
|
|
class CDataMember
|
|
{
|
|
char * Name;
|
|
unsigned short NameLen;
|
|
EDataType Type;
|
|
|
|
char * Value;
|
|
unsigned short Len;
|
|
|
|
CDataMember * FirstChild;
|
|
CDataMember * LastChild;
|
|
|
|
CDataMember * Parent;
|
|
CDataMember * PrevPeer;
|
|
CDataMember * NextPeer;
|
|
|
|
// Manage Members
|
|
CDataMember * CreateChild( const char * Name, const int Len = -1 );
|
|
|
|
// Set Member value
|
|
bool SetValue( EDataType Type, const char * Value = NULL, int Len = -1 );
|
|
|
|
public:
|
|
CDataMember( const char * pName = NULL, const int pLen = -1 );
|
|
CDataMember( CDataMember * pParent, const char * pName = NULL, const int pLen = -1 );
|
|
~CDataMember();
|
|
|
|
EDataType GetType() { return Type; };
|
|
EDataType GetType( const char * Path );
|
|
|
|
inline bool isNull() { return (Type == jtNull); };
|
|
inline bool isBool() { return (Type == jtBool); };
|
|
inline bool isInt() { return (Type == jtInt); };
|
|
inline bool isFloat() { return (Type == jtFloat); };
|
|
inline bool isString() { return (Type == jtString); };
|
|
inline bool isArray() { return (Type == jtArray); };
|
|
inline bool isObject() { return (Type == jtObject); };
|
|
|
|
const char * GetName() { return Name; };
|
|
const char * GetName( const char * Path );
|
|
|
|
const int GetLen() { return Len; };
|
|
const int GetLen( const char * Path );
|
|
|
|
CDataMember * GetMember( const char * Path, bool Create = false );
|
|
CDataMember * GetFirstChild( const char * Path );
|
|
CDataMember * GetElement( const char * Path, const int Index );
|
|
|
|
inline CDataMember * GetFirstChild() { return FirstChild; };
|
|
inline CDataMember * GetElement( const int Index ) { return GetElement( NULL, Index ); };
|
|
|
|
inline CDataMember * GetParent() { return Parent; };
|
|
inline CDataMember * GetPrevPeer() { return PrevPeer; };
|
|
inline CDataMember * GetNextPeer() { return NextPeer; };
|
|
|
|
const char * GetChildStr( const char * Path, const char * Default = NULL, bool Create = false );
|
|
const char * GetChildStr( const char * Path, int &Len, const char * Default = NULL, bool Create = false );
|
|
const bool GetChildBool( const char * Path, bool Default = false, bool Create = false );
|
|
const long GetChildInt( const char * Path, long Default = 0, bool Create = false, const char * Mask = NULL );
|
|
const double GetChildFloat( const char * Path, double Default = 0.0, bool Create = false, const char * Mask = NULL );
|
|
|
|
inline const char * GetStr( const char * Default = NULL, bool Create = false ) { return GetChildStr( NULL, Default, Create ); };
|
|
inline const char * GetStr( int &Len, const char * Default = NULL, bool Create = false ) { return GetChildStr( NULL, Len, Default, Create ); };
|
|
inline const bool GetBool( bool Default = false, bool Create = false ) { return GetChildBool( NULL, Default, Create ); };
|
|
inline const long GetInt( long Default = 0, bool Create = false, const char * Mask = NULL ) { return GetChildInt( NULL, Default, Create, Mask ); };
|
|
inline const double GetFloat( double Default = 0.0, bool Create = false, const char * Mask = NULL ) { return GetChildFloat( NULL, Default, Create, Mask ); };
|
|
|
|
bool SetChildBool( const char * Path, const bool Value );
|
|
bool SetChildInt( const char * Path, const long Value, const char * Mask = NULL );
|
|
bool SetChildFloat( const char * Path, const double Value, const char * Mask = NULL );
|
|
bool SetChildStr( const char * Path, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values
|
|
|
|
inline bool SetBool( const bool Value ) { return SetChildBool( NULL, Value ); };
|
|
inline bool SetInt( const long Value, const char * Mask = NULL ) { return SetChildInt( NULL, Value, Mask ); };
|
|
inline bool SetFloat( const double Value, const char * Mask = NULL ) { return SetChildFloat( NULL, Value, Mask ); };
|
|
inline bool SetStr( const char * Value = NULL, const int Len = -1 ) { return SetChildStr( NULL, Value, Len ); };
|
|
|
|
bool SetChildNull( const char * Path );
|
|
bool SetChildObject( const char * Path );
|
|
bool SetChildArray( const char * Path );
|
|
|
|
inline bool SetNull() { return SetChildNull( NULL ); };
|
|
inline bool SetObject() { return SetChildObject( NULL ); };
|
|
inline bool SetArray() { return SetChildArray( NULL ); };
|
|
|
|
bool Clear();
|
|
bool Delete( const char * Path );
|
|
|
|
friend class CJSONparse;
|
|
};
|
|
|
|
#endif /* REDACORE_DATATREECORE_H_ */
|