33 #include "dcmtk/config/osconfig.h"
34 #include "dcmtk/ofstd/ofstring.h"
35 #include "dcmtk/ofstd/ofstack.h"
36 #include "dcmtk/ofstd/ofstream.h"
38 #define INCLUDE_CSTDIO
39 #include "dcmtk/ofstd/ofstdinc.h"
66 #define OFConfigFile_MaxLevel 2
67 #define OFConfigFile_CommentChar '#'
125 OFBool
less(
const char *c)
const
166 void print(STD_NAMESPACE ostream& out,
unsigned int level);
355 unsigned int maxLevel = OFConfigFile_MaxLevel,
356 char commentChar = OFConfigFile_CommentChar,
357 OFBool orderedMode = OFFalse);
461 const char *key2=NULL,
462 const char *key3=NULL);
474 void print(STD_NAMESPACE ostream& out);
void save_cursor()
puts the current cursor position on a cursor stack.
OFConfigFileNode(const char *keyword)
constructor.
OFConfigFileNodePtr * array_
the cursor is an array of pointers to OFConfigFileNode objects
unsigned int maxLevel_
depth of tree, i.e. number of entries in array_
char read_keywordchar(FILE *infile)
reads the next non-whitespace character from the input file and returns as uppercase character...
const char * getKeyword(unsigned int level) const
return keyword as C string.
const char * getValue() const
return current value as C string
this class maintains one configuration file entry (key-value pair) and the links that comprise the co...
OFStack< OFConfigFileCursor > stack_
stack of cursor positions that can be saved and restored
virtual ~OFConfigFile()
destructor
char * buffer_
buffer during file read
long bufsize_
buffer size during file read
OFConfigFile & operator=(const OFConfigFile &)
private undefined assignment operator
const char * get_value()
gets the value for the current entry (level 0 keyword).
OFConfigFileNode * getBrother() const
return pointer to next object in tree on same level
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...
const char * get_keyword(unsigned int level)
gets the name of the keyword at the specified level in the cursor path.
OFConfigFileCursor & operator=(const OFConfigFileCursor &source)
assignment operator
char read_char(FILE *infile)
reads the next character from the input file, maintains the current line number and filters out comme...
structure used by class OFConfigFile to store a cursor pointing to the currently selected section and...
void print(STD_NAMESPACE ostream &out, unsigned int level)
print the content of this node to an output stream
void read_entry(FILE *infile)
reads a complete entry from the config file.
void print(STD_NAMESPACE ostream &out)
print the content of the configuration to an output stream
OFBool operator<(const OFConfigFileCursor &) const
dummy comparison operator, needed by MSVC5 with STL.
OFString value_
configuration value
char commentChar_
character starting comment lines
const char * getValue(unsigned int level) const
return value as C string Precondition is that section_valid(level) return true.
OFBool less(const char *c) const
check if keyword compares "<" to given string
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...
OFBool match(const char *c) const
check if keyword matches given string
void setValue(const char *c)
set value from C string
OFBool section_valid(unsigned int level) const
checks if the cursor points to a valid location up to the given level
OFString keyword_
configuration keyword
void store_char(char c)
writes a character to the string buffer maintained in "buffer".
void loadFile(FILE *infile)
load configuration file
void next_section(unsigned int level)
sets cursor to the next entry at the given level (without changing the cursor position at higher leve...
void first_section(unsigned int level, OFConfigFileNode *anchor)
sets cursor to the first entry at the given level (without changing the cursor position at higher lev...
class for reading and evaluating configuration files.
~OFConfigFileCursor()
destructor
unsigned int maxLevel_
depth of tree, i.e. number of entries in array_
OFBool get_bool_value(OFBool defaultvalue)
gets the value for the current entry and interprets it as a boolean value.
void setSon(OFConfigFileNode *son)
set pointer to next object in tree on lower level
const char * getKeyword() const
return keyword as C string
void first_section(unsigned int level)
sets cursor to the first entry at the given level (without changing the cursor position at higher lev...
OFConfigFileCursor cursor_
current cursor position
OFBool operator==(const OFConfigFileCursor &) const
dummy comparison operator, needed by MSVC5 with STL.
OFConfigFileNode & operator=(const OFConfigFileNode &arg)
private undefined copy assignment operator
int isnewline_
flag indicating whether newline during file read
OFConfigFile(FILE *infile, unsigned int maxLevel=OFConfigFile_MaxLevel, char commentChar=OFConfigFile_CommentChar, OFBool orderedMode=OFFalse)
constructor.
OFConfigFileNode * getSon() const
return pointer to next object in tree on lower level
OFBool orderedMode_
mode flag for reading configuration file.
~OFConfigFileNode()
destructor, recursively deletes whole tree
void clear()
return object to default constructed state (invalid cursor)
size_t bufptr_
index into buffer during file read
void set_section(unsigned int level, const char *key)
sets cursor to the entry with keyword "key" at the given level.
void select_section(const char *key1, const char *key2=NULL, const char *key3=NULL)
sets the cursor to a different section.
a simple string class that implements a subset of std::string.
void setBrother(OFConfigFileNode *brother)
set pointer to next object in tree on same level
OFConfigFileNode * anchor_
anchor to data tree
void insert(unsigned int level, OFConfigFileNode *&newnode, OFConfigFileNode *&anchor, OFBool orderedMode)
inserts a new node into the tree at the current cursor position
int crfound_
flag indicating whether CR was read during file read
const char * c_str() const
returns a pointer to the initial element of an array of length size()+1 whose first size() elements e...
void restore_cursor()
restores a previously stored cursor position from the cursor stack.
void orderedInsert(OFConfigFileNode *parent, OFConfigFileNode *&newnode)
helper method that is called by insert() in ordered mode to insert a new node at a given tree level (...
void next_section(unsigned int level)
sets cursor to the next entry at the given level (without changing the cursor position at higher leve...
void set_section(unsigned int level, const char *key, OFConfigFileNode *anchor)
sets cursor to the entry with keyword "key" at the given level.
OFConfigFileNode * brother_
pointer to next object in tree on same level
OFConfigFileNode * son_
pointer to next object in tree on lower level
OFConfigFileCursor(unsigned int maxLevel)
default constructor