Adapted to recent changes of %build_linklib.
[AROS-Contrib.git] / FryingPan / framework / Generic / ConfigParser.cpp
blob5eb51812ad54c63550cf4b3af6a9818dee894ac0
1 /*
2 * Amiga Generic Set - set of libraries and includes to ease sw development for all Amiga platforms
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "ConfigParser.h"
21 using namespace GenNS;
23 ConfigParser::~ConfigParser()
27 ConfigParser::ConfigParser(ConfigParser *pParent, String sName, long lID)
29 sElemName = sName; // set element name
30 this->pParent = pParent; // set parent element
31 pElement = 0;
32 this->lID = lID;
33 locateElement();
36 const char *ConfigParser::getValue(const char* sName, const char *sDefault)
38 if (0 == pElement)
39 return sDefault;
41 XMLElement *pElem = pElement->FindChild(const_cast<char*>(sName));
42 if (0 == pElem)
43 return sDefault;
45 return pElem->GetValue().Data();
48 long ConfigParser::getValue(const char* sName, long lDefault)
50 if (0 == pElement)
51 return lDefault;
53 XMLElement *pElem = pElement->FindChild(const_cast<char*>(sName));
54 if (0 == pElem)
55 return lDefault;
57 return pElem->GetValue().ToLong();
60 void ConfigParser::setValue(const char* sName, const char* sValue)
62 if (0 == pElement)
63 return;
65 XMLElement *pElem = pElement->FindChild(const_cast<char*>(sName));
66 if (0 == pElem)
68 pElem = pElement->AddChild(const_cast<char*>(sName), "");
71 pElem->SetValue(sValue);
74 void ConfigParser::setValue(const char* sName, long sValue)
76 if (0 == pElement)
77 return;
79 XMLElement *pElem = pElement->FindChild(const_cast<char*>(sName));
80 if (0 == pElem)
82 pElem = pElement->AddChild(const_cast<char*>(sName), "");
85 pElem->SetValue(sValue);
88 XMLElement *ConfigParser::addChild(const char* sElemName)
90 if (0 == pElement)
91 return 0;
93 return pElement->AddChild(const_cast<char*>(sElemName), "");
96 void ConfigParser::locateElement()
98 if (pParent != 0)
100 for (int i=0; i<pParent->pElement->GetChildrenCount(); i++)
102 XMLElement *pElem = pParent->pElement->GetChild(i);
103 if (pElem->GetName().Equals(sElemName))
105 if (lID == -1)
107 pElement = pElem;
108 return;
110 else
112 XMLAttribute *pAttr = pElem->FindAttribute("id");
113 if (pAttr)
115 if (pAttr->GetValue().ToLong() == lID)
117 pElement = pElem;
118 return;
125 pElement = pParent->addChild(sElemName);
126 if (-1 != lID)
128 pElement->AddAttribute("id", lID);
133 XMLElement *ConfigParser::getElement()
135 return pElement;