EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
XMLParser Class Reference

Utility for parsing XML files. More...

#include "XMLParser.h"

Inheritance diagram for XMLParser:
Collaboration diagram for XMLParser:

Classes

class  ElementParser
 This virtual interface must be implemented by all parsers. More...
 

Public Member Functions

 XMLParser ()
 Primary constructor. More...
 
virtual ~XMLParser ()
 A destructor. More...
 
bool ParseFile (const char *file)
 Parses file using registered parsers. More...
 
bool ParseElement (const TiXmlElement *element) const
 Parses element using registered parsers. More...
 
bool ParseElementChildren (const TiXmlElement *element, size_t max=0) const
 Parses element's children using registered parsers. More...
 
void AddParser (const char *name, ElementParser *parser)
 Adds a parser. More...
 
void RemoveParser (const char *name)
 Removes a parser. More...
 
void ClearParsers ()
 Clears all parsers. More...
 

Public Attributes

std::unique_ptr< TiXmlDocument > m_pXML_Document
 

Private Attributes

std::map< std::string,
ElementParser * > 
mParsers
 

Detailed Description

Utility for parsing XML files.

Author
Zhur, Bloody.Rabbit

Definition at line 34 of file XMLParser.h.

Constructor & Destructor Documentation

XMLParser::XMLParser ( )

Primary constructor.

Definition at line 35 of file XMLParser.cpp.

36 {
37 }
XMLParser::~XMLParser ( )
virtual

A destructor.

Definition at line 39 of file XMLParser.cpp.

References ClearParsers().

40 {
41  ClearParsers();
42 }
void ClearParsers()
Clears all parsers.
Definition: XMLParser.cpp:115

Here is the call graph for this function:

Member Function Documentation

void XMLParser::AddParser ( const char *  name,
ElementParser parser 
)

Adds a parser.

Parameters
[in]nameName of element to be parsed by the parser.
[in]parserThe parser itself.

Definition at line 101 of file XMLParser.cpp.

References mParsers.

Referenced by XMLParserEx::AddMemberParser(), and XMLParserEx::AddValueParser().

102 {
103  mParsers[ name ] = parser;
104 }
std::map< std::string, ElementParser * > mParsers
Definition: XMLParser.h:117

Here is the caller graph for this function:

void XMLParser::ClearParsers ( )

Clears all parsers.

Definition at line 115 of file XMLParser.cpp.

References mParsers, and SafeDelete().

Referenced by ~XMLParser().

115  {
116  for (auto cur : mParsers)
117  SafeDelete(cur.second);
118 
119  mParsers.clear();
120 }
std::map< std::string, ElementParser * > mParsers
Definition: XMLParser.h:117
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLParser::ParseElement ( const TiXmlElement *  element) const

Parses element using registered parsers.

Parameters
[in]elementElement to be parsed.
Return values
trueParsing successful.
falseError occurred during parsing.

Definition at line 61 of file XMLParser.cpp.

References mParsers, and sLog.

Referenced by ParseElementChildren(), XMLPacketGen::ParseElementDef(), ParseFile(), ClassDecodeGenerator::ProcessElementDef(), ClassEncodeGenerator::ProcessElementDef(), and ClassHeaderGenerator::ProcessElementDef().

62 {
63  std::map<std::string, ElementParser*>::const_iterator res = mParsers.find( element->Value() );
64  if (res == mParsers.end()) {
65  sLog.Error( "XMLParser", "Unknown element '%s' at line %d.", element->Value(), element->Row() );
66  return true; // Ignore any unanticipated XML tags and structures and continue parsing the rest of the XML
67  }
68 
69  return res->second->Parse( element );
70 }
std::map< std::string, ElementParser * > mParsers
Definition: XMLParser.h:117
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250

Here is the caller graph for this function:

bool XMLParser::ParseElementChildren ( const TiXmlElement *  element,
size_t  max = 0 
) const

Parses element's children using registered parsers.

Parameters
[in]elementElement the children of which should be parsed.
[in]maxThe maximal count of children to be processed; 0 means all.
Return values
trueParsing successful.
falseError occurred during parsing.

Definition at line 72 of file XMLParser.cpp.

References ParseElement(), and sLog.

Referenced by XMLPacketGen::ParseElements(), EVEServerConfig::ProcessAccount(), MarketBotConf::ProcessBotConf(), EVEServerConfig::ProcessBPTimes(), MarketBotConf::ProcessBuy(), EVEServerConfig::ProcessCharacter(), EVEServerConfig::ProcessChat(), EVEServerConfig::ProcessCosmic(), EVEServerConfig::ProcessCrime(), EVEServerConfig::ProcessDatabase(), EVEServerConfig::ProcessDebug(), ClassCloneGenerator::ProcessDictInline(), ClassConstructGenerator::ProcessDictInline(), ClassDestructGenerator::ProcessDictInline(), ClassDumpGenerator::ProcessDictInline(), ClassDecodeGenerator::ProcessDictInline(), ClassEncodeGenerator::ProcessDictInline(), ClassHeaderGenerator::ProcessDictInline(), ClassCloneGenerator::ProcessDictInlineEntry(), ClassConstructGenerator::ProcessDictInlineEntry(), ClassDestructGenerator::ProcessDictInlineEntry(), ClassDumpGenerator::ProcessDictInlineEntry(), ClassHeaderGenerator::ProcessDictInlineEntry(), ClassConstructGenerator::ProcessElementDef(), ClassDestructGenerator::ProcessElementDef(), ClassCloneGenerator::ProcessElementDef(), ClassDumpGenerator::ProcessElementDef(), EVEServerConfig::ProcessEveServer(), EVEServerConfig::ProcessExploring(), EVEServerConfig::ProcessFiles(), ClassConstructGenerator::ProcessListInline(), ClassDestructGenerator::ProcessListInline(), ClassDumpGenerator::ProcessListInline(), ClassCloneGenerator::ProcessListInline(), ClassDecodeGenerator::ProcessListInline(), ClassEncodeGenerator::ProcessListInline(), ClassHeaderGenerator::ProcessListInline(), MarketBotConf::ProcessMain(), EVEServerConfig::ProcessMarket(), EVEServerConfig::ProcessNet(), EVEServerConfig::ProcessNPC(), NPCMarket::ProcessNPCOrders(), ClassConstructGenerator::ProcessObjectInline(), ClassDestructGenerator::ProcessObjectInline(), ClassDumpGenerator::ProcessObjectInline(), ClassCloneGenerator::ProcessObjectInline(), ClassDecodeGenerator::ProcessObjectInline(), ClassEncodeGenerator::ProcessObjectInline(), ClassHeaderGenerator::ProcessObjectInline(), NPCMarket::ProcessOrder(), EVEServerConfig::ProcessRates(), MarketBotConf::ProcessSell(), EVEServerConfig::ProcessServer(), EVEServerConfig::ProcessStandings(), NPCMarket::ProcessStation(), ClassDumpGenerator::ProcessSubStreamInline(), ClassConstructGenerator::ProcessSubStreamInline(), ClassCloneGenerator::ProcessSubStreamInline(), ClassDestructGenerator::ProcessSubStreamInline(), ClassDecodeGenerator::ProcessSubStreamInline(), ClassEncodeGenerator::ProcessSubStreamInline(), ClassHeaderGenerator::ProcessSubStreamInline(), ClassDumpGenerator::ProcessSubStructInline(), ClassDestructGenerator::ProcessSubStructInline(), ClassConstructGenerator::ProcessSubStructInline(), ClassCloneGenerator::ProcessSubStructInline(), ClassDecodeGenerator::ProcessSubStructInline(), ClassEncodeGenerator::ProcessSubStructInline(), ClassHeaderGenerator::ProcessSubStructInline(), EVEServerConfig::ProcessTesting(), EVEServerConfig::ProcessThreads(), ClassConstructGenerator::ProcessTupleInline(), ClassCloneGenerator::ProcessTupleInline(), ClassDumpGenerator::ProcessTupleInline(), ClassDestructGenerator::ProcessTupleInline(), ClassDecodeGenerator::ProcessTupleInline(), ClassHeaderGenerator::ProcessTupleInline(), ClassEncodeGenerator::ProcessTupleInline(), and EVEServerConfig::ProcessWorld().

73 {
74  const TiXmlNode* child = nullptr;
75 
76  size_t count = 0;
77  while ((child = element->IterateChildren(child))) {
78  if (child->Type() == TiXmlNode::TINYXML_ELEMENT) {
79  const TiXmlElement* childElement = child->ToElement();
80  if ((max > 0) && (max <= count)) {
81  sLog.Error( "XMLParser", "Maximal children count %lu exceeded"
82  " in element '%s' at line %d"
83  " by element '%s' at line %d.",
84  max,
85  element->Value(), element->Row(),
86  childElement->Value(), childElement->Row() );
87 
88  return false;
89  }
90 
91  if (!ParseElement(childElement))
92  return false;
93 
94  ++count;
95  }
96  }
97 
98  return true;
99 }
bool ParseElement(const TiXmlElement *element) const
Parses element using registered parsers.
Definition: XMLParser.cpp:61
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
int64 max(int64 x, int64 y=0)
Definition: misc.h:103

Here is the call graph for this function:

bool XMLParser::ParseFile ( const char *  file)

Parses file using registered parsers.

Parameters
[in]fileFile to parse.
Return values
trueParsing successful.
falseError occurred during parsing.

Definition at line 44 of file XMLParser.cpp.

References m_pXML_Document, ParseElement(), and sLog.

Referenced by NPCMarket::CreateNPCMarketFromFile(), and main().

45 {
46  m_pXML_Document = make_unique<TiXmlDocument>(file);
47  if (!m_pXML_Document->LoadFile()) {
48  sLog.Error( "XMLParser", "Unable to load '%s': %s.", file, m_pXML_Document->ErrorDesc() );
49  return false;
50  }
51 
52  TiXmlElement* root = m_pXML_Document->RootElement();
53  if (root == nullptr) {
54  sLog.Error( "XMLParser", "Unable to find root in '%s'.", file );
55  return false;
56  }
57 
58  return ParseElement( root );
59 }
bool ParseElement(const TiXmlElement *element) const
Parses element using registered parsers.
Definition: XMLParser.cpp:61
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
std::unique_ptr< TiXmlDocument > m_pXML_Document
Definition: XMLParser.h:113

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLParser::RemoveParser ( const char *  name)

Member Data Documentation

std::unique_ptr<TiXmlDocument> XMLParser::m_pXML_Document

Definition at line 113 of file XMLParser.h.

Referenced by ParseFile().

std::map<std::string, ElementParser*> XMLParser::mParsers
private

Parser storage.

Definition at line 117 of file XMLParser.h.

Referenced by AddParser(), ClearParsers(), ParseElement(), and RemoveParser().


The documentation for this class was generated from the following files: