Class DConfigReader

Inherits from:
Object
Declared in:
DConfig.h

Class Hierarchy

    Object
      |
      +---DConfigReader

Class Description

The DConfigReader class implements methods for parsing a config file.

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

@interface MyHandler : Object <DConfigHandler>  // MyHander implements the DConfigHander interface
{
}
- (BOOL) startConfig;
- (BOOL) endConfig;
- (BOOL) section :(const char *) name;
- (BOOL) option :(const char *) section :(const char *) name :(const char *) value;
- (BOOL) comment :(const char *) comment;
- (void) error :(int) number :(const char *) name :(int) lineNumber :(int) columnNumber;
@end

@implementation MyHandler

- (BOOL) startConfig
{
  return YES;                          // No interrest in startConfig..
}

- (BOOL) endConfig
{
  return YES;                          // No interest in endConfig..
}

- (BOOL) section :(const char *) name
{
  return YES;                          // No interest in (start of) section
}

- (BOOL) option :(const char *) section :(const char *) name :(const char *) value
{
  printf("Section:%s Name:%s Value:%s\n", section, name, value);
  return YES;
}

- (BOOL) comment :(const char *) comment
{
  return YES;                          // No interest in comment
}

- (void) error :(int) number :(const char *) name :(int) lineNumber :(int) columnNumber
{
  printf("Error:%d in %s on line %d and column %d.\n", number, name, lineNumber, columnNumber);
}

@end


int main(int argc, char *argv[])
{
  MyHandler     *hdlr = [MyHandler     new];  // Config handler
  DConfigReader *rdr  = [DConfigReader new];  // Config reader
  DFile         *file = [DFile         new];

  if ([file open :"example.ini" :"r"]) // Open the config file
  {
    if (![rdr parse :file :"example.ini" :hdlr]) // Parse the config file, calling the config handler methods
    {
      printf("File \"example.ini\" could not be parsed.\n");
    }

    [file close];
  }

  [hdlr free];                         // Cleanup
  [file free];
  [rdr  free];

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

Instance Variables

private DLexer *_lexer
the lexer used to parse the file

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0