Class DPropertyTree

Inherits from:
Object
Conforms to:
DXMLHandler
Declared in:
DPropertyTree.h

Class Hierarchy

    Object
      |
      +---DPropertyTree

Class Description

The DPropertyTree class implements methods for storing and retrieving properties in a xml file. There are methods for adding, removing, importing and exporting properties.

Example:
#include <stdio.h>
#include "ofc/DPropertyTree.h"
#include "ofc/DFile.h"
#include "ofc/DText.h"
#include "ofc/DInt.h"
#include "ofc/DBool.h"

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

  DText         *stringValue = [DText new];  // Property value destinations
  DInt          *intValue    = [DInt  new];
  DBool         *boolValue   = [DBool new];

  char           name[]      = "property.xml";
                                             // Build the property tree
  printf("Building the property tree.\n");
  group = [tree group :nil :"Example"];      //   First: Add a group to the root

  [stringValue set :"ExampleString"];        //   Set defaults to the values
  [intValue    set :10];
  [boolValue   set :YES];
                                             //   Second: Add the properties to the group
  [tree property :group :"string" :stringValue];
  [tree property :group :"int"    :intValue   ];
  [tree property :group :"bool"   :boolValue  ];
                                             // Write the defaults to a property file
  printf("Saving property tree to \"%s\".\n", name);
  if ([file open :name :"w"])
  {
    if (![tree write :file :name])
      printf("Could not write \"%s\".\n", name);

    [file close];
  }
  else
    printf("Could \"%s\" not open for writing:%d\n", name, [file error]);

                                       // Test: reset the properties
  printf("Reset the properties.\n");
  [stringValue set :""];
  [intValue    set :0 ];
  [boolValue   set :NO];
                                       // Read the property file
  printf("Read the properties back from \"%s\".\n", name);
  if ([file open :name :"r"])
  {
    if (![tree read :file :name])
      printf("Could not read \"%s\".\n", name);

    [file close];
  }
  else
    printf("Could \"%s\" not open for reading:%d\n", name, [file error]);

  printf("Property \"string\":%s\n", [stringValue cstring]);
  printf("Property \"int\"   :%d\n", [intValue get]);
  printf("Property \"bool\"  :%d\n", [boolValue get]);

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

  return 0;
}
Last modified:
16-Aug-2008 (DPropertyTree.h)

Instance Variables

private DTree *_properties
the property tree
private DTreeIterator *_iter
the property tree iterator
private DProperty *_root
the root of the properties
private DXMLReader *_reader
the xml reader

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0