Opened 13 years ago

#465 new task

avoid copy & repeat code in Configuration

Reported by: Peter Johansson Owned by: Peter Johansson
Priority: trivial Milestone: svndigest 0.x+
Component: configuration Version: trunk
Keywords: Cc:

Description

The load function in Configuration basically reads in line by line in config file, keeps track of which section we are in, and reads in various keys with values.

The implementation is very much

if (in-section-a) {
  if (key == key1)
    <some code>
  else if (key == key2)
    <some code>
}
else if (in-section-b) {{{
...

The thing is that <some code> is not the same all the time but it is often repeated and the function is awfully long. It would probably be better to re-write this in a more object oriented way. The structure if-elseif blocks somehow suggest a container such as

map<Section, map<Key, Value> >

where the inner map perhaps should be replaced by some wrapper around a map. There are two types of Sections: 1) where the keys are well defined and key outside that list would indicate a invalid config 2) section where the key is a filename (with wildcards) and could be anything.

Likewise for the values; we have a couple of different. Most are boolean (true/false), but there are also arrays of strings or single strings.

Change History (0)

Note: See TracTickets for help on using tickets.