Class DConfigTree

Inherits from:
Object
Conforms to:
DConfigHandler
Declared in:
DConfig.h

Class Hierarchy

    Object
      |
      +---DConfigTree

Class Description

The ConfigTree class implements methods for storing config options, including reading and writing to a config file, and changing and removing options. Config options are structured in sections with multiple options with values.

Example:
#include <stdio.h>
#include "ofc/DConfig.h"
#include "ofc/DFile.h"

int main(int argc, char *argv[])
{
  DConfigTree *tree = [DConfigTree new];
  DFile       *file = [DFile       new];

  char         name1[] = "example.ini";
  char         name2[] = "example2.ini";

  if ([file open :name1 :"r"])         // Open the config file
  {
    if ([tree read :file :name1])      // Read the config file
    {
      [file close];

      printf("Config %s the option Option1 in SectionA.\n",
          ([tree has :"SectionA" :"Option1"] ? "has" : "has not")); // Check for an option

      if ([tree set :"SectionB" :"Option2" :"Value2"])  // Insert an option
        printf("SectionB - Option2 succesfully inserted.\n");
      else
        printf("Could not insert an option for sectionB.\n");

      if ([tree remove :"SectionA" :"Option2"])  // Remove an option
        printf("SectionA - Option2 succesfully removed.\n");
      else
        printf("Could not remove option2 for sectionA.\n");

      if ([file open :name2 :"w"])     // Open the config file for writing
      {
        if ([tree write :file :name2]) // Write the modified config file
          printf("Config tree succesfully written in \"%s\".\n", name2);
        else
          printf("Could not write \"%s\".\n", name2);

        [file close];
      }
      else
        printf("Could not write \"%s\".\n", name2);
    }
    else
    {
      [file close];
      printf("Could not read \"%s\".\n", name1);
    }
  }
  else
    printf("Could not open \"%s\":%d.\n", name1, [file error]);

  [file free];                         // Cleanup
  [tree free];

  return 0;
}
Last modified:
25-Aug-2008 (DConfig.h)

Instance Variables

private DTree *_config
the options in a tree of sections
private DTreeIterator *_iter
the iterator in the config tree

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0