Important Update:
- DataTreeCore: - Re-arrange method declaration order - Renamed methods Delete() to DeleteCh() - Added GetChName(), GetChType(), GetChLen() & ClearCh(Path) methods - ApplicationCore: - Add WriteToScreen() method (Hide access to JSONparser)
This commit is contained in:
@@ -88,6 +88,7 @@ public:
|
|||||||
|
|
||||||
// Manually set configuration
|
// Manually set configuration
|
||||||
bool SetLogParam( EDebugLevel pDebugLevel, int pOutputDisplay );
|
bool SetLogParam( EDebugLevel pDebugLevel, int pOutputDisplay );
|
||||||
|
inline void WriteToScreen( const char * BasePath, const int Indent = 2 ) { JSONparser->WriteToScreen( BasePath, Indent ); };
|
||||||
|
|
||||||
// Init application
|
// Init application
|
||||||
bool InitApplication();
|
bool InitApplication();
|
||||||
|
|||||||
@@ -130,18 +130,33 @@ CDataMember * CDataMember::CreateChild( const char * Name, const int Len )
|
|||||||
|
|
||||||
bool CDataMember::Clear()
|
bool CDataMember::Clear()
|
||||||
{
|
{
|
||||||
|
// Clear value
|
||||||
if (Value) {
|
if (Value) {
|
||||||
free( Value );
|
free( Value );
|
||||||
Value = NULL;
|
Value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear children
|
||||||
while (FirstChild) {
|
while (FirstChild) {
|
||||||
delete FirstChild;
|
delete FirstChild;
|
||||||
// FirstChild = NULL;
|
|
||||||
// LastChild = NULL;
|
|
||||||
// Len = 0;
|
|
||||||
}
|
}
|
||||||
Type = jtNull;
|
|
||||||
|
|
||||||
|
// Reset value
|
||||||
|
Type = jtNull;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool CDataMember::ClearCh( const char * Path )
|
||||||
|
{
|
||||||
|
CDataMember * Child = NULL;
|
||||||
|
|
||||||
|
// Find member
|
||||||
|
if (!(Child = (!Path || !*Path)? this : GetChild( Path, false )))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Clear
|
||||||
|
Child->Clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -318,7 +333,7 @@ CDataMember * CDataMember::GetChElement( const char * Path, const int Index, boo
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool CDataMember::Delete( const char * Path )
|
bool CDataMember::DeleteCh( const char * Path )
|
||||||
{
|
{
|
||||||
CDataMember * Member;
|
CDataMember * Member;
|
||||||
|
|
||||||
@@ -484,7 +499,7 @@ bool CDataMember::SetChNull( const char * Path )
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
const char * CDataMember::GetName( const char * Path )
|
const char * CDataMember::GetChName( const char * Path )
|
||||||
{
|
{
|
||||||
CDataMember * Member;
|
CDataMember * Member;
|
||||||
|
|
||||||
@@ -496,7 +511,7 @@ const char * CDataMember::GetName( const char * Path )
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
EDataType CDataMember::GetType( const char * Path )
|
EDataType CDataMember::GetChType( const char * Path )
|
||||||
{
|
{
|
||||||
CDataMember * Member;
|
CDataMember * Member;
|
||||||
|
|
||||||
@@ -508,7 +523,7 @@ EDataType CDataMember::GetType( const char * Path )
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
const int CDataMember::GetLen( const char * Path )
|
const int CDataMember::GetChLen( const char * Path )
|
||||||
{
|
{
|
||||||
CDataMember * Member;
|
CDataMember * Member;
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,16 @@ public:
|
|||||||
CDataMember( CDataMember * pParent, const char * pName = NULL, const int pLen = -1 );
|
CDataMember( CDataMember * pParent, const char * pName = NULL, const int pLen = -1 );
|
||||||
~CDataMember();
|
~CDataMember();
|
||||||
|
|
||||||
|
const char * GetName() { return Name; };
|
||||||
|
const int GetLen() { return Len; };
|
||||||
|
|
||||||
|
const char * GetChName( const char * Path );
|
||||||
|
const int GetChLen( const char * Path );
|
||||||
|
|
||||||
|
/* Check Type */
|
||||||
|
|
||||||
EDataType GetType() { return Type; };
|
EDataType GetType() { return Type; };
|
||||||
EDataType GetType( const char * Path );
|
EDataType GetChType( const char * Path );
|
||||||
|
|
||||||
inline bool isNull() { return (Type == jtNull); };
|
inline bool isNull() { return (Type == jtNull); };
|
||||||
inline bool isBool() { return (Type == jtBool); };
|
inline bool isBool() { return (Type == jtBool); };
|
||||||
@@ -60,28 +68,20 @@ public:
|
|||||||
inline bool isArray() { return (Type == jtArray); };
|
inline bool isArray() { return (Type == jtArray); };
|
||||||
inline bool isObject() { return (Type == jtObject); };
|
inline bool isObject() { return (Type == jtObject); };
|
||||||
|
|
||||||
const char * GetName() { return Name; };
|
/* Navigating members */
|
||||||
const char * GetName( const char * Path );
|
|
||||||
|
|
||||||
const int GetLen() { return Len; };
|
inline CDataMember * GetFirstChild() { return GetChFirstChild( NULL, false ); };
|
||||||
const int GetLen( const char * Path );
|
inline CDataMember * GetElement( const int Index ) { return GetChElement( NULL, Index, false ); };
|
||||||
|
|
||||||
CDataMember * GetChild( const char * Path, bool Create = false );
|
CDataMember * GetChild( const char * Path, bool Create = false );
|
||||||
CDataMember * GetChFirstChild( const char * Path, bool Create = false );
|
CDataMember * GetChFirstChild( const char * Path, bool Create = false );
|
||||||
CDataMember * GetChElement( const char * Path, const int Index, bool Create = false );
|
CDataMember * GetChElement( const char * Path, const int Index, bool Create = false );
|
||||||
|
|
||||||
inline CDataMember * GetFirstChild() { return GetChFirstChild( NULL, false ); };
|
|
||||||
inline CDataMember * GetElement( const int Index ) { return GetChElement( NULL, Index, false ); };
|
|
||||||
|
|
||||||
inline CDataMember * GetParent() { return Parent; };
|
inline CDataMember * GetParent() { return Parent; };
|
||||||
inline CDataMember * GetPrevPeer() { return PrevPeer; };
|
inline CDataMember * GetPrevPeer() { return PrevPeer; };
|
||||||
inline CDataMember * GetNextPeer() { return NextPeer; };
|
inline CDataMember * GetNextPeer() { return NextPeer; };
|
||||||
|
|
||||||
const char * GetChStr( const char * Path, const char * Default = NULL, bool Create = false );
|
/* Read Values */
|
||||||
const char * GetChStr( const char * Path, int &Len, const char * Default = NULL, bool Create = false );
|
|
||||||
const bool GetChBool( const char * Path, bool Default = false, bool Create = false );
|
|
||||||
const long GetChInt( const char * Path, long Default = 0, bool Create = false, const char * Mask = NULL );
|
|
||||||
const double GetChFloat( const char * Path, double Default = 0.0, bool Create = false, const char * Mask = NULL );
|
|
||||||
|
|
||||||
inline const char * GetStr( const char * Default = NULL ) { return GetChStr( NULL, Default, false ); };
|
inline const char * GetStr( const char * Default = NULL ) { return GetChStr( NULL, Default, false ); };
|
||||||
inline const char * GetStr( int &Len, const char * Default = NULL ) { return GetChStr( NULL, Len, Default, false ); };
|
inline const char * GetStr( int &Len, const char * Default = NULL ) { return GetChStr( NULL, Len, Default, false ); };
|
||||||
@@ -89,26 +89,39 @@ public:
|
|||||||
inline const long GetInt( long Default = 0, const char * Mask = NULL ) { return GetChInt( NULL, Default, false, Mask ); };
|
inline const long GetInt( long Default = 0, const char * Mask = NULL ) { return GetChInt( NULL, Default, false, Mask ); };
|
||||||
inline const double GetFloat( double Default = 0.0, const char * Mask = NULL ) { return GetChFloat( NULL, Default, false, Mask ); };
|
inline const double GetFloat( double Default = 0.0, const char * Mask = NULL ) { return GetChFloat( NULL, Default, false, Mask ); };
|
||||||
|
|
||||||
bool SetChBool( const char * Path, const bool Value );
|
const char * GetChStr( const char * Path, const char * Default = NULL, bool Create = false );
|
||||||
bool SetChInt( const char * Path, const long Value, const char * Mask = NULL );
|
const char * GetChStr( const char * Path, int &Len, const char * Default = NULL, bool Create = false );
|
||||||
bool SetChFloat( const char * Path, const double Value, const char * Mask = NULL );
|
const bool GetChBool( const char * Path, bool Default = false, bool Create = false );
|
||||||
bool SetChStr( const char * Path, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values
|
const long GetChInt( const char * Path, long Default = 0, bool Create = false, const char * Mask = NULL );
|
||||||
|
const double GetChFloat( const char * Path, double Default = 0.0, bool Create = false, const char * Mask = NULL );
|
||||||
|
|
||||||
|
/* Modify Values */
|
||||||
|
|
||||||
|
inline bool SetNull() { return SetChNull( NULL ); };
|
||||||
|
inline bool SetObject() { return SetChObject( NULL ); };
|
||||||
|
inline bool SetArray() { return SetChArray( NULL ); };
|
||||||
|
|
||||||
inline bool SetBool( const bool Value ) { return SetChBool( NULL, Value ); };
|
inline bool SetBool( const bool Value ) { return SetChBool( NULL, Value ); };
|
||||||
inline bool SetInt( const long Value, const char * Mask = NULL ) { return SetChInt( NULL, Value, Mask ); };
|
inline bool SetInt( const long Value, const char * Mask = NULL ) { return SetChInt( NULL, Value, Mask ); };
|
||||||
inline bool SetFloat( const double Value, const char * Mask = NULL ) { return SetChFloat( NULL, Value, Mask ); };
|
inline bool SetFloat( const double Value, const char * Mask = NULL ) { return SetChFloat( NULL, Value, Mask ); };
|
||||||
inline bool SetStr( const char * Value = NULL, const int Len = -1 ) { return SetChStr( NULL, Value, Len ); };
|
inline bool SetStr( const char * Value = NULL, const int Len = -1 ) { return SetChStr( NULL, Value, Len ); };
|
||||||
|
|
||||||
bool SetChNull( const char * Path );
|
bool SetChStr( const char * Path, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values
|
||||||
bool SetChObject( const char * Path );
|
bool SetChObject( const char * Path );
|
||||||
bool SetChArray( const char * Path );
|
bool SetChArray( const char * Path );
|
||||||
|
|
||||||
inline bool SetNull() { return SetChNull( NULL ); };
|
bool SetChNull( const char * Path );
|
||||||
inline bool SetObject() { return SetChObject( NULL ); };
|
bool SetChBool( const char * Path, const bool Value );
|
||||||
inline bool SetArray() { return SetChArray( NULL ); };
|
bool SetChInt( const char * Path, const long Value, const char * Mask = NULL );
|
||||||
|
bool SetChFloat( const char * Path, const double Value, const char * Mask = NULL );
|
||||||
|
|
||||||
|
/* Clear / Remove values */
|
||||||
|
|
||||||
bool Clear();
|
bool Clear();
|
||||||
bool Delete( const char * Path );
|
bool ClearCh( const char * Path );
|
||||||
|
bool DeleteCh( const char * Path );
|
||||||
|
|
||||||
|
/* Parsing */
|
||||||
|
|
||||||
friend class CJSONparse;
|
friend class CJSONparse;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -588,7 +588,7 @@ bool CJSONparse::ParseObject( CDataMember * Object )
|
|||||||
if (!ParseObject( Member ) && !Error && !ParseArray( Member ) && !Error && !ParseString( Member ) && !Error && !ParsePrimitive( Member ) ) {}
|
if (!ParseObject( Member ) && !Error && !ParseArray( Member ) && !Error && !ParseString( Member ) && !Error && !ParsePrimitive( Member ) ) {}
|
||||||
if (Error) {
|
if (Error) {
|
||||||
// Destroy member
|
// Destroy member
|
||||||
Object->Delete( MemberName );
|
Object->DeleteCh( MemberName );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user