Main page

1.0

Introduction

The main purpose of this library is to provide a clean way to navigate through tree based data structures while also keeping the whole code easy to include into existent projects. As an example of implementation, a piece of code is shown in a section below.

Installation

This library can be compiled and installed using autotools (./configure && make && make install), although the whole code can be easily included into an existent project since there is only one source code and header file. All the code resides in it's own namespace.

Usage

Examples

Node creation

 Node Document, * nodePtr = &Document;
 
 nodePtr = nodePtr->AddNode(Node("myApp"));
 nodePtr = nodePtr->AddNode(Node("mainWindow"));
 nodePtr->AddPair(Pair("width", WinObj.m_Width));
 nodePtr->AddPair(Pair("height", WinObj.m_Height));
 
 nodePtr = nodePtr->Parent();
 nodePtr = nodePtr->AddNode(Node("DB"));
 nodePtr->AddPair(Pair("username", DbObj.username));
 nodePtr->AddPair(Pair("password", DbObj.password));

Node creation from file

 Node Document;
 SConfigParser::ParseFile(filePath, Document);

Value access with Path

 std::string width, height;
 
 if (Document.Path("myApp.mainWindow.width", width) && Document.Path("myApp.mainWindow.height", height))
        std::cout << "Window size: " << width << "x" << height << std::endl;

Value access with TPath

 int width, height;
 
 if (Document.TPath("myApp.mainWindow.width", width) && Document.Path("myApp.mainWindow.height", height))
        std::cout << "Window size: " << width << "x" << height << std::endl;

Value access with Handler

 Handler nHandle(&Document);
 if ( (Node * nWidth = nHandle.FirstNode("myApp").FirstNode("mainWindow").FirstPair("width").Get()) &&
 (Node * nHeight = nHandle.FirstNode("myApp").FirstNode("mainWindow").FirstPair("height").Get()) )
        std::cout << "Window size: " << nWidth->Value() << "x" << nHeight->Value() << std::endl;

Value access with manual check

 nodePtr = &Document;
 if ( (nodePtr = nodePtr->FirstNode("myApp")) ) {
        if ( (nodePtr = nodePtr->FirstNode("mainWindow")) ) {
                Pair * Height = nodePtr->FirstPair("height"), * Width = nodePtr->FirstPair("width");
                if (Height && Width)
                        std::cout << "Window size: " << Width.Value() << "x" << Height.Value() << std::endl;
        }
 }

Generated on Fri Apr 3 16:53:53 2009 for libsconfig by  doxygen 1.5.6