#include <ace/Configuration.h>
class ACE_Configuration {
public:
enum VALUETYPE { STRING, INTEGER, BINARY, INVALID };
virtual ~ACE_Configuration (void);
virtual const ACE_Configuration_Section_Key& root_section (void);
virtual int open_section ( const ACE_Configuration_Section_Key &base, const TCHAR *sub_section, int create, ACE_Configuration_Section_Key& result ) = 0;
virtual int remove_section ( const ACE_Configuration_Section_Key &key, const TCHAR *sub_section, int recursive ) = 0;
virtual int enumerate_values ( const ACE_Configuration_Section_Key& key, int index, ACE_TString& name, VALUETYPE& type ) = 0;
virtual int enumerate_sections ( const ACE_Configuration_Section_Key& key, int index, ACE_TString& name ) = 0;
virtual int set_string_value ( const ACE_Configuration_Section_Key& key, const TCHAR* name, const ACE_TString& value ) = 0;
virtual int set_integer_value ( const ACE_Configuration_Section_Key& key, const TCHAR* name, u_int value ) = 0;
virtual int set_binary_value ( const ACE_Configuration_Section_Key& key, const TCHAR* name, const void* data, u_int length ) = 0;
virtual int get_string_value ( const ACE_Configuration_Section_Key& key, const TCHAR* name, ACE_TString& value ) = 0;
virtual int get_integer_value ( const ACE_Configuration_Section_Key& key, const TCHAR* name, u_int& value ) = 0;
virtual int get_binary_value ( const ACE_Configuration_Section_Key& key, const TCHAR* name, void*& data, u_int& length ) = 0;
virtual int remove_value ( const ACE_Configuration_Section_Key& key, const TCHAR* name ) = 0;
int expand_path ( const ACE_Configuration_Section_Key& key, const ACE_TString& path_in, ACE_Configuration_Section_Key& key_out, int create = 1 );
virtual int export_config (const TCHAR* filename);
virtual int import_config (const TCHAR* filename);
protected:
ACE_Configuration (void);
ACE_Section_Key_Internal* get_internal_key ( const ACE_Configuration_Section_Key& key );
int validate_name (const TCHAR* name);
int export_section ( const ACE_Configuration_Section_Key& section, const ACE_TString& path, FILE* out );
ACE_Configuration (const ACE_Configuration& rhs);
ACE_Configuration& operator= (const ACE_Configuration& rhs);
ACE_Configuration_Section_Key root_;
};
virtual ~ACE_Configuration (void);
virtual const ACE_Configuration_Section_Key& root_section (void);
virtual int open_section (
const ACE_Configuration_Section_Key &base,
const TCHAR *sub_section,
int create,
ACE_Configuration_Section_Key& result
) = 0;
sub_section
in base
and places the resulting key in
result
. If create is non zero, the sub_section will be created
if it doesn't exist
virtual int remove_section (
const ACE_Configuration_Section_Key &key,
const TCHAR *sub_section,
int recursive
) = 0;
sub_section
from key
. If recursive is non zero,
any subkeys below sub_section
are remove as well.
virtual int enumerate_values (
const ACE_Configuration_Section_Key& key,
int index,
ACE_TString& name,
VALUETYPE& type
) = 0;
name
and type
of values in a
key
. To begin iteration, index
must be zero. to continue
iteration, invoke enumerate_values again while incrementing
index. Each iteration will return the name
of the value and
its type
. This method returns 0 on success, 0 on error and 1
when there are no more values to iterate through. Note - you may
not delete or add values while enumerating. If you need to do
this, you start the enumeration over again.
virtual int enumerate_sections (
const ACE_Configuration_Section_Key& key,
int index,
ACE_TString& name
) = 0;
name
subsections in key
. To
begin iteration, index
must zero. to continue iteration, invoke
enumerate_sections again while incrementing index. Each
iteration will return the name
of the sub section. This method
returns 0 on success, 0 on error and 1 when there are no more
subsections to iterate through. Note - you may not delete or add
values while enumerating. If you need to do this, you start the
enumeration over again.
virtual int set_string_value (
const ACE_Configuration_Section_Key& key,
const TCHAR* name,
const ACE_TString& value
) = 0;
key
with name
to a string of value
virtual int set_integer_value (
const ACE_Configuration_Section_Key& key,
const TCHAR* name,
u_int value
) = 0;
key
with name
to an integer of value
virtual int set_binary_value (
const ACE_Configuration_Section_Key& key,
const TCHAR* name,
const void* data,
u_int length
) = 0;
key
with name
to binary data of data
with
length
.
virtual int get_string_value (
const ACE_Configuration_Section_Key& key,
const TCHAR* name,
ACE_TString& value
) = 0;
name
from key
and places it in
value
. Returns non zero on error (if value is not a string).
virtual int get_integer_value (
const ACE_Configuration_Section_Key& key,
const TCHAR* name,
u_int& value
) = 0;
name
from key
and places it in
value
. Returns non zero on error (if value is not an integer).
virtual int get_binary_value (
const ACE_Configuration_Section_Key& key,
const TCHAR* name,
void*& data,
u_int& length
) = 0;
name
from key
and places a copy in
data
and sets length
to the length of the data. caller is
responsible for freeing data
. Returns non zero on error (if
value is not binary).
virtual int remove_value (
const ACE_Configuration_Section_Key& key,
const TCHAR* name
) = 0;
name
from key
. returns non zero on
error.
int expand_path (
const ACE_Configuration_Section_Key& key,
const ACE_TString& path_in,
ACE_Configuration_Section_Key& key_out,
int create = 1
);
path_in
to key_out
from key
. If create is true,
the subsections are created. Returns 0 on success, non zero on
error The path consists of sections separated by the backslash
'\\'.
virtual int export_config (const TCHAR* filename);
filename
is
alredy present, it is overwritten.
virtual int import_config (const TCHAR* filename);
ACE_Configuration (void);
ACE_Section_Key_Internal* get_internal_key (
const ACE_Configuration_Section_Key& key
);
int validate_name (const TCHAR* name);
name
is valid. name
must be 255 characters
and not contain the path separator '\\', brackets [] or = (maybe
just restrict to alphanumeric?) returns non zero if name is not
valid
int export_section (
const ACE_Configuration_Section_Key& section,
const ACE_TString& path,
FILE* out
);
ACE_Configuration (const ACE_Configuration& rhs);
ACE_Configuration& operator= (const ACE_Configuration& rhs);
ACE_Configuration_Section_Key root_;
chris@stentorsoft.com