DCMTK  Version 3.6.6
OFFIS DICOM Toolkit
Public Member Functions | Private Member Functions | Private Attributes | List of all members
OFConfigFile Class Reference

class for reading and evaluating configuration files. More...

Public Member Functions

 OFConfigFile (FILE *infile, unsigned int maxLevel=OFConfigFile_MaxLevel, char commentChar=OFConfigFile_CommentChar, OFBool orderedMode=OFFalse)
 constructor. More...
 
virtual ~OFConfigFile ()
 destructor
 
void loadFile (FILE *infile)
 load configuration file More...
 
const char * get_keyword (unsigned int level)
 gets the name of the keyword at the specified level in the cursor path. More...
 
const char * get_value ()
 gets the value for the current entry (level 0 keyword). More...
 
OFBool get_bool_value (OFBool defaultvalue)
 gets the value for the current entry and interprets it as a boolean value. More...
 
OFBool section_valid (unsigned int level) const
 checks if the cursor points to a valid entry in the config data tree up to the the specified level. More...
 
void set_section (unsigned int level, const char *key)
 sets cursor to the entry with keyword "key" at the given level. More...
 
void first_section (unsigned int level)
 sets cursor to the first entry at the given level (without changing the cursor position at higher levels). More...
 
void next_section (unsigned int level)
 sets cursor to the next entry at the given level (without changing the cursor position at higher levels). More...
 
void save_cursor ()
 puts the current cursor position on a cursor stack.
 
void restore_cursor ()
 restores a previously stored cursor position from the cursor stack.
 
void select_section (const char *key1, const char *key2=NULL, const char *key3=NULL)
 sets the cursor to a different section. More...
 
const char * get_entry (const char *key0)
 sets the cursor to the given level 0 keyword and returns the string value assigned to this keyword. More...
 
void print (STD_NAMESPACE ostream &out)
 print the content of the configuration to an output stream More...
 

Private Member Functions

char read_char (FILE *infile)
 reads the next character from the input file, maintains the current line number and filters out comments. More...
 
char read_keywordchar (FILE *infile)
 reads the next non-whitespace character from the input file and returns as uppercase character. More...
 
void read_entry (FILE *infile)
 reads a complete entry from the config file. More...
 
void store_char (char c)
 writes a character to the string buffer maintained in "buffer". More...
 
 OFConfigFile (const OFConfigFile &)
 private undefined copy constructor
 
OFConfigFileoperator= (const OFConfigFile &)
 private undefined assignment operator
 

Private Attributes

OFStack< OFConfigFileCursorstack_
 stack of cursor positions that can be saved and restored
 
OFConfigFileCursor cursor_
 current cursor position
 
OFConfigFileNodeanchor_
 anchor to data tree
 
int isnewline_
 flag indicating whether newline during file read
 
int crfound_
 flag indicating whether CR was read during file read
 
char * buffer_
 buffer during file read
 
size_t bufptr_
 index into buffer during file read
 
long bufsize_
 buffer size during file read
 
unsigned int maxLevel_
 depth of tree, i.e. number of entries in array_
 
char commentChar_
 character starting comment lines

 
OFBool orderedMode_
 mode flag for reading configuration file. More...
 

Detailed Description

class for reading and evaluating configuration files.

An object of this class reads upon construction a text config file and offers methods allowing to browse the configuration data

Constructor & Destructor Documentation

◆ OFConfigFile()

OFConfigFile::OFConfigFile ( FILE *  infile,
unsigned int  maxLevel = OFConfigFile_MaxLevel,
char  commentChar = OFConfigFile_CommentChar,
OFBool  orderedMode = OFFalse 
)

constructor.

Parameters
infilefile from which the configuration data is to be read.
maxLeveldepth of the tree maintained in this config file, default 2
commentCharcharacter to start comment lines, default '#'
orderedModemode flag for processing configuration files. See documentation of member variable orderedMode_

Member Function Documentation

◆ first_section()

void OFConfigFile::first_section ( unsigned int  level)
inline

sets cursor to the first entry at the given level (without changing the cursor position at higher levels).

Cursor must be valid at the level higher than the one specified. If no section is found the cursor becomes invalid at the specified level. The cursor always becomes invalid at all levels lower than specified.

Parameters
levelcursor level

◆ get_bool_value()

OFBool OFConfigFile::get_bool_value ( OFBool  defaultvalue)

gets the value for the current entry and interprets it as a boolean value.

The keywords "yes", "no", "on", "off", "1", "0", "true" and false" are recognised in upper, lower and mixed case. If the value is different from any recognised keyword, the specified default is returned Cursor must point to a valid entry (i.e. be valid at level 0)

Parameters
defaultvaluedefault to be returned if no keyword is recognised of if the cursor is invalid.
Returns
boolean value.

◆ get_entry()

const char* OFConfigFile::get_entry ( const char *  key0)

sets the cursor to the given level 0 keyword and returns the string value assigned to this keyword.

Parameters
key0level 0 keyword
Returns
value string if found, NULL otherwise

◆ get_keyword()

const char* OFConfigFile::get_keyword ( unsigned int  level)

gets the name of the keyword at the specified level in the cursor path.

Cursor must be valid at the specified level.

Parameters
levelcursor level
Returns
keyword if valid, NULL otherwise.

◆ get_value()

const char* OFConfigFile::get_value ( )

gets the value for the current entry (level 0 keyword).

Cursor must point to a valid entry (i.e. be valid at level 0)

Returns
value if valid, NULL otherwise.

◆ loadFile()

void OFConfigFile::loadFile ( FILE *  infile)

load configuration file

Parameters
infileconfiguration file, must already be open for reading.

◆ next_section()

void OFConfigFile::next_section ( unsigned int  level)
inline

sets cursor to the next entry at the given level (without changing the cursor position at higher levels).

Cursor must be valid at the level specified. If no section is found the cursor becomes invalid at the specified level. The cursor always becomes invalid at all levels lower than specified.

Parameters
levelcursor level

◆ print()

void OFConfigFile::print ( STD_NAMESPACE ostream &  out)

print the content of the configuration to an output stream

Parameters
outoutput stream to print to

◆ read_char()

char OFConfigFile::read_char ( FILE *  infile)
private

reads the next character from the input file, maintains the current line number and filters out comments.

Parameters
infilethe file to be read
Returns
next character

◆ read_entry()

void OFConfigFile::read_entry ( FILE *  infile)
private

reads a complete entry from the config file.

An entry can either be a section heading or an entry of the form key=value. The entry is inserted into the config data tree managed by this object.

Parameters
infilethe file to be read

◆ read_keywordchar()

char OFConfigFile::read_keywordchar ( FILE *  infile)
private

reads the next non-whitespace character from the input file and returns as uppercase character.

Parameters
infilethe file to be read
Returns
next non-whitespace character

◆ section_valid()

OFBool OFConfigFile::section_valid ( unsigned int  level) const
inline

checks if the cursor points to a valid entry in the config data tree up to the the specified level.

Parameters
leveltree level (0 for leaf)
Returns
OFTrue if valid at the specified level.

◆ select_section()

void OFConfigFile::select_section ( const char *  key1,
const char *  key2 = NULL,
const char *  key3 = NULL 
)

sets the cursor to a different section.

This "shortcut" method allows to specify multiple section levels at the same time. The cursor becomes invalid when the section is not found or if parameters for more level then present in the tree are specified.

Parameters
key1level 1 section key, i.e. [KEY]
key2level 2 section key, i.e. [[KEY]]. If omitted, section 2 remains unchanged.
key2level 3 section key, i.e. [[[KEY]]]. If omitted, section 3 remains unchanged.

◆ set_section()

void OFConfigFile::set_section ( unsigned int  level,
const char *  key 
)
inline

sets cursor to the entry with keyword "key" at the given level.

Cursor must be valid at the level higher than the one specified. If the keyword exists more than once, the first occurance is found. If the keyword does not exist, the cursor becomes invalid at the specified level. The cursor always becomes invalid at all levels lower than specified.

Parameters
levelcursor level
keykey value

◆ store_char()

void OFConfigFile::store_char ( char  c)
private

writes a character to the string buffer maintained in "buffer".

Automatically resizes buffer if necessary.

Parameters
ccharacter to be stored

Member Data Documentation

◆ orderedMode_

OFBool OFConfigFile::orderedMode_
private

mode flag for reading configuration file.

If false, new entries to the tree containing the configuration file are just appended and not sorted. This allows multiple entries with the same keyword to be present, only the first of which will be found by search-by-keyword methods such as set_section, select_section or get_entry. In ordered mode, the tree is maintained in sorted order and a new entry will replace an older entry with identical keyword. This permits multiple configuration files to "overlay" each other but is somewhat slower when reading the configuration file.


The documentation for this class was generated from the following file:


Generated on Thu Jan 14 2021 for DCMTK Version 3.6.6 by Doxygen 1.8.18