2012-04-26 04:34:15 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Author: Valient Gough <vgough@pobox.com>
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (c) 2012, Valient Gough
|
2012-10-03 07:12:17 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2012-04-26 04:34:15 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2012-10-03 07:12:17 +02:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2012-04-26 04:34:15 +02:00
|
|
|
*
|
2012-10-03 07:12:17 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-04-26 04:34:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _XmlReader_incl_
|
|
|
|
#define _XmlReader_incl_
|
|
|
|
|
|
|
|
#include <string>
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "base/shared_ptr.h"
|
2012-04-26 04:34:15 +02:00
|
|
|
|
|
|
|
class XmlValue;
|
2012-08-22 06:46:36 +02:00
|
|
|
typedef shared_ptr<XmlValue> XmlValuePtr;
|
2012-04-26 04:34:15 +02:00
|
|
|
|
2012-08-26 08:43:01 +02:00
|
|
|
class Interface;
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
class XmlValue
|
|
|
|
{
|
|
|
|
std::string value;
|
|
|
|
public:
|
|
|
|
XmlValue()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlValue(const std::string &value)
|
|
|
|
{
|
|
|
|
this->value = value;
|
|
|
|
}
|
|
|
|
virtual ~XmlValue();
|
|
|
|
|
|
|
|
XmlValuePtr operator[] (const char *path) const;
|
|
|
|
|
|
|
|
const std::string &text() const
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-08-26 08:43:01 +02:00
|
|
|
bool read(const char *path, std::string *out) const;
|
|
|
|
bool readB64(const char *path, unsigned char *out, int length) const;
|
|
|
|
|
|
|
|
bool read(const char *path, int *out) const;
|
|
|
|
bool read(const char *path, long *out) const;
|
|
|
|
bool read(const char *path, double *out) const;
|
|
|
|
bool read(const char *path, bool *out) const;
|
|
|
|
|
|
|
|
bool read(const char *path, Interface *out) const;
|
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
protected:
|
|
|
|
virtual XmlValuePtr find(const char *name) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class XmlReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
XmlReader();
|
|
|
|
~XmlReader();
|
|
|
|
|
|
|
|
bool load(const char *fileName);
|
|
|
|
|
|
|
|
XmlValuePtr operator[](const char *name) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct XmlReaderData;
|
2012-08-22 06:46:36 +02:00
|
|
|
shared_ptr<XmlReaderData> pd;
|
2012-04-26 04:34:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|