mirror of
https://github.com/1dot13/source.git
synced 2026-08-19 14:20:30 +02:00
*** Merged Code from Multiplayer Branch Revision 2960 ***
- Virtual File System (VFS) by birdflu. This is needed for Multiplayer and is also used for Single Player. Very neat system :-) - Multiplayer Version 1.1 + some additional features and bugfixes * INFO: If you compile a new EXE and want to test, be sure to also use the latest SVN GameDir files in your JA2 install directory * git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2961 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#ifndef _XML_PARSER_H_
|
||||
#define _XML_PARSER_H_
|
||||
|
||||
#include "expat.h"
|
||||
#include "XML.h"
|
||||
|
||||
class IXMLParser
|
||||
{
|
||||
public:
|
||||
const XML_Char* ElementName;
|
||||
public:
|
||||
IXMLParser(const XML_Char *element_name, XML_Parser &parser, IXMLParser* caller=NULL)
|
||||
: _parser(parser), _caller(caller), ElementName(element_name) {};
|
||||
~IXMLParser() {};
|
||||
|
||||
/**
|
||||
* Interface
|
||||
*/
|
||||
static void OnStartCallback(void *userData, const XML_Char* name, const XML_Char** atts)
|
||||
{
|
||||
((IXMLParser*)userData)->OnStartElement(name,atts);
|
||||
}
|
||||
static void OnEndCallback(void *userData, const XML_Char* name)
|
||||
{
|
||||
((IXMLParser*)userData)->OnEndElement(name);
|
||||
// test if we are done here
|
||||
if( ((IXMLParser*)userData)->_caller && (strcmp(name, ((IXMLParser*)userData)->ElementName) == 0) )
|
||||
{
|
||||
((IXMLParser*)userData)->_caller->GrabParser();
|
||||
}
|
||||
}
|
||||
static void OnTextCallback(void *userData, const XML_Char *str, int len)
|
||||
{
|
||||
((IXMLParser*)userData)->OnTextElement(str,len);
|
||||
}
|
||||
void GrabParser()
|
||||
{
|
||||
XML_SetUserData(_parser,this);
|
||||
XML_SetElementHandler(_parser, IXMLParser::OnStartCallback, IXMLParser::OnEndCallback);
|
||||
XML_SetCharacterDataHandler(_parser, IXMLParser::OnTextCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override these methods in your parser
|
||||
*/
|
||||
virtual void OnStartElement(const XML_Char* name, const XML_Char** atts)
|
||||
{};
|
||||
virtual void OnEndElement(const XML_Char* name)
|
||||
{};
|
||||
virtual void OnTextElement(const XML_Char *str, int len)
|
||||
{};
|
||||
protected:
|
||||
XML_Char const* GetAttribute(const XML_Char* attr_name, const XML_Char** atts)
|
||||
{
|
||||
while(*atts)
|
||||
{
|
||||
if(strcmp(*atts++,attr_name) == 0)
|
||||
{
|
||||
return *atts;
|
||||
}
|
||||
atts++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
bool GetAttributeAsInt(const XML_Char* attr_name, const XML_Char** attr, int &value)
|
||||
{
|
||||
XML_Char const* result = GetAttribute(attr_name,attr);
|
||||
if( strcmp(result,"") != 0)
|
||||
{
|
||||
value = (int)atol(result);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool GetAttributeAsFloat(const XML_Char* attr_name, const XML_Char** attr, float &value)
|
||||
{
|
||||
XML_Char const* result = GetAttribute(attr_name,attr);
|
||||
if( strcmp(result,"") != 0)
|
||||
{
|
||||
value = (float)atof(result);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int GetCurrentLineNumber()
|
||||
{
|
||||
return XML_GetCurrentLineNumber(this->_parser);
|
||||
}
|
||||
protected:
|
||||
std::string sCharData;
|
||||
|
||||
XML_Parser& _parser;
|
||||
IXMLParser* _caller;
|
||||
};
|
||||
|
||||
#endif // _XML_PARSER_H_
|
||||
Reference in New Issue
Block a user