Important Update: (ConfigCore)
- Implemented full support for multi-layer objects - Implemented RootObject for all other elements - Added method CreateParam() - Converted GetParam methods from inline to normal methods - Added GetParent method - Use Object->Len to count no of child objects
This commit is contained in:
80
ConfigCore.h
80
ConfigCore.h
@@ -27,9 +27,11 @@ typedef enum { jtNull = 0, jtBool = 1, jtInt = 2, jtFloat = 3, jtString = 4, jtA
|
||||
typedef struct SConfigParam TConfigParam;
|
||||
|
||||
// One Config Parameters
|
||||
struct SConfigParam {
|
||||
struct SConfigParam
|
||||
{
|
||||
char * Name;
|
||||
EJSONtype Type;
|
||||
TConfigParam * FirstObject;
|
||||
char * Value;
|
||||
int Len;
|
||||
|
||||
@@ -41,23 +43,41 @@ struct SConfigParam {
|
||||
class CConfigCore
|
||||
{
|
||||
private:
|
||||
TConfigParam * FirstParam;
|
||||
TConfigParam * RootObject;
|
||||
|
||||
// File operation
|
||||
FILE * InputFile;
|
||||
FILE * OutputFile;
|
||||
char * Buffer;
|
||||
int BufLen;
|
||||
|
||||
// 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];
|
||||
|
||||
// Manage Parameters
|
||||
TConfigParam * CreateParam( const char * Name );
|
||||
bool DestroyParam( TConfigParam ** Param );
|
||||
|
||||
// Find Param
|
||||
bool GetParent( const char * ParentPath, TConfigParam **Parent );
|
||||
TConfigParam * GetParam( TConfigParam * Parent, const char * Name );
|
||||
TConfigParam ** GetParamPtr( TConfigParam * Parent, const char * Name );
|
||||
|
||||
// Set Param value
|
||||
bool SetParam( TConfigParam * Param, EJSONtype Type, const char * Value, const int Len );
|
||||
|
||||
// File Buffer operation
|
||||
bool CreateBuffer( int pBufLen );
|
||||
bool FillBuffer();
|
||||
@@ -77,54 +97,28 @@ private:
|
||||
bool ParseString( char ** Value, int * pLen = NULL, EJSONtype * pType = NULL );
|
||||
bool ParsePrimitive( char ** Value, int * pLen = NULL, EJSONtype * pType = NULL );
|
||||
|
||||
// Find Param
|
||||
inline TConfigParam * GetParam( const char * Name ) {
|
||||
TConfigParam * Param = FirstParam;
|
||||
while (Param && strcasecmp( Param->Name, Name ))
|
||||
Param = Param->Next;
|
||||
return Param;
|
||||
}
|
||||
inline TConfigParam ** GetParamPtr( const char * Name ) {
|
||||
TConfigParam ** Param = &FirstParam;
|
||||
while (*Param && strcasecmp( (*Param)->Name, Name ))
|
||||
Param = &((*Param)->Next);
|
||||
return Param;
|
||||
}
|
||||
|
||||
// Create Param
|
||||
inline TConfigParam * FindCreateParam( const char * Name ) {
|
||||
TConfigParam ** Param = NULL;
|
||||
if (!*(Param = GetParamPtr( Name ))) {
|
||||
*Param = (TConfigParam *)calloc( 1, sizeof(TConfigParam) );
|
||||
(*Param)->Name = (char *)calloc( 1, strlen( Name )+1 );
|
||||
strcpy( (*Param)->Name, Name );
|
||||
}
|
||||
return (*Param);
|
||||
}
|
||||
|
||||
// Manage Parameters
|
||||
bool SetParam( TConfigParam * Param, EJSONtype Type, const char * Value, const int Len );
|
||||
bool DestroyParam( TConfigParam ** Param );
|
||||
bool SaveObject( TConfigParam * Object, const int Indent );
|
||||
|
||||
public:
|
||||
CConfigCore();
|
||||
~CConfigCore();
|
||||
|
||||
bool SetParamStr( const char * Name, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values
|
||||
bool SetParamInt( const char * Name, const long Value );
|
||||
bool SetParamFloat( const char * Name, const double Value );
|
||||
bool SetParamBool( const char * Name, const bool Value );
|
||||
bool SetParamNull( const char * Name );
|
||||
bool SetParamObject( const char * ParentPath, const char * Name );
|
||||
bool SetParamStr( const char * ParentPath, const char * Name, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values
|
||||
bool SetParamInt( const char * ParentPath, const char * Name, const long Value );
|
||||
bool SetParamFloat( const char * ParentPath, const char * Name, const double Value );
|
||||
bool SetParamBool( const char * ParentPath, const char * Name, const bool Value );
|
||||
bool SetParamNull( const char * ParentPath, const char * Name );
|
||||
|
||||
const EJSONtype GetParamType( const char * Name );
|
||||
const EJSONtype GetParamType( const char * ParentPath, const char * Name );
|
||||
|
||||
const char * GetParamStr( const char * Name, const char * Default = NULL );
|
||||
const char * GetParamStr( const char * Name, int &Len, const char * Default = NULL );
|
||||
const long GetParamInt( const char * Name, long Default = 0 );
|
||||
const double GetParamFloat( const char * Name, double Default = 0.0 );
|
||||
const bool GetParamBool( const char * Name, bool Default = false );
|
||||
const char * GetParamStr( const char * ParentPath, const char * Name, const char * Default = NULL );
|
||||
const char * GetParamStr( const char * ParentPath, const char * Name, int &Len, const char * Default = NULL );
|
||||
const long GetParamInt( const char * ParentPath, const char * Name, long Default = 0 );
|
||||
const double GetParamFloat( const char * ParentPath, const char * Name, double Default = 0.0 );
|
||||
const bool GetParamBool( const char * ParentPath, const char * Name, bool Default = false );
|
||||
|
||||
bool DeleteParam( const char * Name );
|
||||
bool DeleteParam( const char * ParentPath, const char * Name );
|
||||
bool DeleteAll();
|
||||
|
||||
bool LoadFile( const char * FilePath, int pBufLen = 500 );
|
||||
|
||||
Reference in New Issue
Block a user