Main page
1.0
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.
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.
- There are two primary object types: Nodes and Pairs.
- Nodes contain children (Nodes) and Pairs.
- Navigation is done using First, Previous and Next pointers. Path() and Handler() make Node and Pair access very easy and secure.
- SConfigParser has methods to convert text (and text files) into Node documents.
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 Document;
SConfigParser::ParseFile(filePath, Document);
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;
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;
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;
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;
}
}