User Documentation
RAVL, Recognition And Vision Library
DEVELOP HOME PAGE CLASS LIST CONTENTS
Ravl - OS - Configuration Files


Configuration files

The basics

ConfigFileC reads configuration files in a format similar to that used by make. In its simplest form a files consists of a number of lines of the form '(variable) = (value)'. Comments start with '#', every thing between the '#' and the new line is ignored. Variable names are case sensitive and must not contain spaces or punctuation other than an underscore '_'. The value is taken as the first non space character after the '=' sign until the end of the line. Lines may be continued with a backslash '\'. Values may be enclosed with double quotes, special characters (such as '#' and '\n') will not be interpreted inside the quoted text. If you wish to include quotes in your text the can be escaped with '\' and backslashes with '\\'.

Typically a configuration file would contain something like the following:


# My program setup.
Threshold = 1.2
MaxRegions = 4 # Typically set to 3.
InputFile = "windmill.cif"

The 'ConfigFileC' class deals entirely with strings. If you ask for an undefined variable an empty string is given. The code to read and process this file would look something like:

ConfigFileC cfg("setup.conf");
RealT threshold = cfg["Threshold"].RealValue();
StringC filename = cfg["InputFile"];
IntT maxRegions = cfg["MaxRegions"].IntValue();

Sections

The following examples shows how to declare a section in your config file. The contents of a section are exactly as before, and may be defined recursively.


Filter1 {
  Gamma = 1.2
  Alpha = 0.4
}

You can access sections with the 'Section(..)' method. If the section exists it will return the a ConfigFileC which can then be used to access the configuration information it contains.

ConfigFileC cfg("setup.conf");
ConfigFileC cfg_filt1 = cfg.Section("Filter1");
if(cfg_filt1.IsValid()) { // Check that section has been found.
  RealT gamma = cfg_filt1["Gamma"].RealValue();
  RealT alpha = cfg_filt1["Alpha"].RealValue();
}

Normal classes:

 ConfigFileC Config file.
Documentation by CxxDoc: Tue Aug 13 10:00:52 2002