aboutsummaryrefslogtreecommitdiff
path: root/src/configmanagerbase.cpp
blob: 6c239f8b4a0ab7c81fd42b3d5086dea6a379fe65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdlib.h>
#include <string.h>
#include "xmlnode.h"
#include "xmlfilereader.h"
#include "configmanagerbase.h"

ConfigManagerBase::ConfigManager()
{
}

ConfigManagerBase::~ConfigManager()
{
}

void ConfigManagerBase::addSearchPath( const std::string &sPath )
{
	lSearchPath.push_back( sPath );
}

void ConfigManagerBase::loadConfig( const char *lpProfile )
{
	// Try a few locations...
	std::list<std::string>::const_iterator i;
	for( i = lSearchPath.begin(); i != lSearchPath.end(); i++ )
	{
		if( parseConfig( (*i).c_str(), lpProfile ) )
		{
			break;
		}
	}
}

bool ConfigManagerBase::parseConfig( const char *lpFileName, const char *lpProfile )
{
	XmlNode *pRoot, *pCur;
	XmlFileReader doc( lpFileName );

	pRoot = doc.getRoot();
	if( pRoot == NULL )
	{
		return false;
	}

	if( strcmp("config", pRoot->getName() ) )
	{
		return false;
	}

	for( int j = 0;; j++ )
	{
		pCur = pRoot->getChild( "profile", j );
		if( pCur == NULL )
			return false;

		if( !strcmp( pCur->getProperty("id"), lpProfile ) )
		{
			return processProfile( pCur );
		}
	}

	return false;
}