mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-30 08:07:46 +00:00
remove old xmlconfig class
This commit is contained in:
parent
d8896bf53e
commit
a322e81a53
2 changed files with 0 additions and 108 deletions
|
@ -1,35 +0,0 @@
|
||||||
#include "XMLConfig.h"
|
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
|
||||||
#include <boost/property_tree/xml_parser.hpp>
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
// instanciate and load a config
|
|
||||||
XMLConfig::XMLConfig()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
XMLConfig::~XMLConfig()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
using boost::property_tree::ptree;
|
|
||||||
const ptree& empty_ptree()
|
|
||||||
{
|
|
||||||
static ptree t;
|
|
||||||
return t;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool XMLConfig::loadConfig( const std::string& fileName )
|
|
||||||
{
|
|
||||||
|
|
||||||
boost::property_tree::read_xml( fileName, m_propTree );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
#ifndef __XMLCONFIG_H
|
|
||||||
#define __XMLCONFIG_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
// very simple XML parser class
|
|
||||||
// this hasn't gotten much attention yet as it works good as it is.
|
|
||||||
class XMLConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef std::map<std::string, std::string> SettingMap;
|
|
||||||
typedef std::map<std::string, SettingMap> CategoryMap;
|
|
||||||
|
|
||||||
// instanciate and load a config
|
|
||||||
XMLConfig();
|
|
||||||
|
|
||||||
~XMLConfig();
|
|
||||||
|
|
||||||
// load a config file
|
|
||||||
bool loadConfig( const std::string& fileName );
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
T getValue( const std::string& name, T defaultValue = T() )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return m_propTree.get< T >( name );
|
|
||||||
}
|
|
||||||
catch( ... )
|
|
||||||
{
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
void setValue( const std::string& name, T defaultValue = T() )
|
|
||||||
{
|
|
||||||
m_propTree.put( name, defaultValue );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
T getAttrValue( boost::property_tree::ptree node, const std::string& name, T defaultValue = T() )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
T outVal = node.get< T >( "<xmlattr>." + name );
|
|
||||||
return outVal;
|
|
||||||
}
|
|
||||||
catch( const std::runtime_error& )
|
|
||||||
{
|
|
||||||
T outVal = defaultValue;
|
|
||||||
return outVal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::property_tree::ptree getChild( const std::string& name )
|
|
||||||
{
|
|
||||||
auto val = m_propTree.get_child( name );
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
boost::property_tree::ptree m_propTree;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
Loading…
Add table
Reference in a new issue