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

XML Packet Generator class. More...

#include "XMLPacketGen.h"

Inheritance diagram for XMLPacketGen:
Collaboration diagram for XMLPacketGen:

Public Member Functions

 XMLPacketGen (const char *header="", const char *source="")
 Primary constructor. More...
 
 ~XMLPacketGen ()
 Destructory; closes output files. More...
 
void SetHeaderFile (const char *header)
 Sets header file. More...
 
void SetSourceFile (const char *source)
 Sets source file. More...
 
- Public Member Functions inherited from XMLParserEx
template<typename T >
void AddMemberParser (const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
 Adds a member parser. More...
 
template<typename T >
void AddValueParser (const char *name, T &value)
 Adds a value parser. More...
 
- Public Member Functions inherited from XMLParser
 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...
 

Protected Member Functions

bool ParseElements (const TiXmlElement *field)
 
bool ParseInclude (const TiXmlElement *field)
 
bool ParseElementDef (const TiXmlElement *field)
 
- Protected Member Functions inherited from XMLParserEx
template<typename T >
void AddMemberParser (const char *name, bool(T::*method)(const TiXmlElement *))
 Adds a member parser, assuming that instance is this. More...
 

Private Member Functions

bool OpenFiles ()
 Opens output files. More...
 

Static Private Member Functions

static std::string FNameToDef (const char *buf)
 

Private Attributes

FILE * mHeaderFile
 
std::string mHeaderFileName
 
FILE * mSourceFile
 
std::string mSourceFileName
 
ClassCloneGenerator mClone
 
ClassConstructGenerator mConstruct
 
ClassDecodeGenerator mDecode
 
ClassDestructGenerator mDestruct
 
ClassDumpGenerator mDump
 
ClassEncodeGenerator mEncode
 
ClassHeaderGenerator mHeader
 

Static Private Attributes

static const char *const smGenFileComment
 

Additional Inherited Members

- Public Attributes inherited from XMLParser
std::unique_ptr< TiXmlDocument > m_pXML_Document
 

Detailed Description

XML Packet Generator class.

Top-level class, controls the generation.

Author
Zhur, Bloody.Rabbit

Definition at line 45 of file XMLPacketGen.h.

Constructor & Destructor Documentation

XMLPacketGen::XMLPacketGen ( const char *  header = "",
const char *  source = "" 
)

Primary constructor.

Parameters
[in]headerHeader file to be generated.
[in]sourceSource file to be generated.

Definition at line 62 of file XMLPacketGen.cpp.

References XMLParserEx::AddMemberParser(), ParseElementDef(), ParseElements(), and ParseInclude().

63 : mHeaderFile( NULL ),
64  mHeaderFileName( header ),
65  mSourceFile( NULL ),
66  mSourceFileName( source )
67 {
71 }
bool ParseElementDef(const TiXmlElement *field)
bool ParseInclude(const TiXmlElement *field)
FILE * mSourceFile
Definition: XMLPacketGen.h:91
std::string mHeaderFileName
Definition: XMLPacketGen.h:90
std::string mSourceFileName
Definition: XMLPacketGen.h:92
void AddMemberParser(const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
Adds a member parser.
Definition: XMLParserEx.h:55
FILE * mHeaderFile
Definition: XMLPacketGen.h:89
bool ParseElements(const TiXmlElement *field)

Here is the call graph for this function:

XMLPacketGen::~XMLPacketGen ( )

Destructory; closes output files.

Definition at line 73 of file XMLPacketGen.cpp.

References SetHeaderFile(), and SetSourceFile().

74 {
75  // Close the files
76  SetHeaderFile( "" );
77  SetSourceFile( "" );
78 }
void SetHeaderFile(const char *header)
Sets header file.
void SetSourceFile(const char *source)
Sets source file.

Here is the call graph for this function:

Member Function Documentation

std::string XMLPacketGen::FNameToDef ( const char *  buf)
staticprivate

Definition at line 235 of file XMLPacketGen.cpp.

References IsPrintable().

Referenced by ParseElements().

236 {
237  std::string res;
238  res += "__";
239 
240  for(; '\0' != *buf; ++buf )
241  {
242  if( !IsPrintable( *buf ) || *buf == '/' || *buf == '\\' || *buf == ':' || *buf == '.' || *buf == '-' )
243  res += '_';
244  else
245  res += (char)toupper( *buf );
246  }
247 
248  res += "__";
249  return res;
250 }
bool IsPrintable(const PyString *str)
Checks whether string is printable.
Definition: EVEUtils.cpp:31

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLPacketGen::OpenFiles ( )
private

Opens output files.

Return values
trueOpen succeeded.
falseOpen failed.

Definition at line 197 of file XMLPacketGen.cpp.

References mClone, mConstruct, mDecode, mDestruct, mDump, mEncode, mHeader, mHeaderFile, mHeaderFileName, mSourceFile, mSourceFileName, and Generator::SetOutputFile().

Referenced by ParseElements().

198 {
199  bool res = true;
200 
201  if( !mHeaderFileName.empty() && ( NULL == mHeaderFile ) )
202  {
203  mHeaderFile = fopen( mHeaderFileName.c_str(), "w" );
204 
205  if( NULL == mHeaderFile )
206  res = false;
207  else
208  {
209  // propagate the change to the generators
211  }
212  }
213 
214  if( !mSourceFileName.empty() && ( NULL == mSourceFile ) )
215  {
216  mSourceFile = fopen( mSourceFileName.c_str(), "w" );
217 
218  if( NULL == mSourceFile )
219  res = false;
220  else
221  {
222  // propagate the change to the generators
229  }
230  }
231 
232  return res;
233 }
FILE * mSourceFile
Definition: XMLPacketGen.h:91
ClassCloneGenerator mClone
Definition: XMLPacketGen.h:94
std::string mHeaderFileName
Definition: XMLPacketGen.h:90
void SetOutputFile(FILE *outputFile)
Sets output file.
Definition: Generator.h:53
ClassDumpGenerator mDump
Definition: XMLPacketGen.h:98
ClassConstructGenerator mConstruct
Definition: XMLPacketGen.h:95
ClassDecodeGenerator mDecode
Definition: XMLPacketGen.h:96
ClassDestructGenerator mDestruct
Definition: XMLPacketGen.h:97
ClassHeaderGenerator mHeader
Definition: XMLPacketGen.h:100
ClassEncodeGenerator mEncode
Definition: XMLPacketGen.h:99
std::string mSourceFileName
Definition: XMLPacketGen.h:92
FILE * mHeaderFile
Definition: XMLPacketGen.h:89

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLPacketGen::ParseElementDef ( const TiXmlElement *  field)
protected

Definition at line 145 of file XMLPacketGen.cpp.

References mClone, mConstruct, mDecode, mDestruct, mDump, mEncode, mHeader, and XMLParser::ParseElement().

Referenced by XMLPacketGen().

146 {
147  bool res = ( mClone.ParseElement( field )
148  && mConstruct.ParseElement( field )
149  && mDecode.ParseElement( field )
150  && mDestruct.ParseElement( field )
151  && mDump.ParseElement( field )
152  && mEncode.ParseElement( field )
153  && mHeader.ParseElement( field ) );
154 
155  return res;
156 }
bool ParseElement(const TiXmlElement *element) const
Parses element using registered parsers.
Definition: XMLParser.cpp:61
ClassCloneGenerator mClone
Definition: XMLPacketGen.h:94
ClassDumpGenerator mDump
Definition: XMLPacketGen.h:98
ClassConstructGenerator mConstruct
Definition: XMLPacketGen.h:95
ClassDecodeGenerator mDecode
Definition: XMLPacketGen.h:96
ClassDestructGenerator mDestruct
Definition: XMLPacketGen.h:97
ClassHeaderGenerator mHeader
Definition: XMLPacketGen.h:100
ClassEncodeGenerator mEncode
Definition: XMLPacketGen.h:99

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLPacketGen::ParseElements ( const TiXmlElement *  field)
protected

Definition at line 80 of file XMLPacketGen.cpp.

References FNameToDef(), mHeaderFile, mHeaderFileName, mSourceFile, OpenFiles(), XMLParser::ParseElementChildren(), sLog, and smGenFileComment.

Referenced by XMLPacketGen().

81 {
82  if( !OpenFiles() )
83  {
84  sLog.Error( "XMLPacketGen", "Unable to open output files: %s.", strerror( errno ) );
85  return false;
86  }
87 
88  const std::string def = FNameToDef( mHeaderFileName.c_str() );
89 
90  //headers:
91  fprintf( mHeaderFile,
92  "%s\n"
93  "\n"
94  "#ifndef %s\n"
95  "#define %s\n"
96  "\n"
97  "#include \"python/PyVisitor.h\"\n"
98  "#include \"python/PyRep.h\"\n"
99  "\n",
101  def.c_str(),
102  def.c_str()
103  );
104  fprintf( mSourceFile,
105  "%s\n"
106  "\n"
107  "#include \"eve-common.h\"\n"
108  "\n"
109  "#include \"%s\"\n"
110  "\n",
112  mHeaderFileName.c_str()
113  );
114 
115  //content
116  bool res = ParseElementChildren( field );
117 
118  //footers:
119  fprintf( mHeaderFile,
120  "#endif /* !%s */\n"
121  "\n",
122  def.c_str()
123  );
124 
125  return res;
126 }
static const char *const smGenFileComment
Definition: XMLPacketGen.h:104
FILE * mSourceFile
Definition: XMLPacketGen.h:91
std::string mHeaderFileName
Definition: XMLPacketGen.h:90
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
static std::string FNameToDef(const char *buf)
bool OpenFiles()
Opens output files.
bool ParseElementChildren(const TiXmlElement *element, size_t max=0) const
Parses element's children using registered parsers.
Definition: XMLParser.cpp:72
FILE * mHeaderFile
Definition: XMLPacketGen.h:89

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLPacketGen::ParseInclude ( const TiXmlElement *  field)
protected

Definition at line 128 of file XMLPacketGen.cpp.

References _log, and mHeaderFile.

Referenced by XMLPacketGen().

129 {
130  const char* file = field->Attribute( "file" );
131  if( file == NULL )
132  {
133  _log( COMMON__ERROR, "field at line %d is missing the file attribute, skipping.", field->Row() );
134  return false;
135  }
136 
137  fprintf( mHeaderFile,
138  "#include \"%s\"\n"
139  "\n",
140  file
141  );
142  return true;
143 }
#define _log(type, fmt,...)
Definition: logsys.h:124
FILE * mHeaderFile
Definition: XMLPacketGen.h:89

Here is the caller graph for this function:

void XMLPacketGen::SetHeaderFile ( const char *  header)

Sets header file.

Parameters
[in]headerHeader file to be generated.

Definition at line 158 of file XMLPacketGen.cpp.

References mHeader, mHeaderFile, mHeaderFileName, and Generator::SetOutputFile().

Referenced by main(), and ~XMLPacketGen().

159 {
160  if( mHeaderFileName != header )
161  {
162  if( NULL != mHeaderFile )
163  {
164  fclose( mHeaderFile );
165  mHeaderFile = NULL;
166 
167  // propagate the change to the generators
168  mHeader.SetOutputFile( NULL );
169  }
170 
171  mHeaderFileName = header;
172  }
173 }
std::string mHeaderFileName
Definition: XMLPacketGen.h:90
void SetOutputFile(FILE *outputFile)
Sets output file.
Definition: Generator.h:53
ClassHeaderGenerator mHeader
Definition: XMLPacketGen.h:100
FILE * mHeaderFile
Definition: XMLPacketGen.h:89

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLPacketGen::SetSourceFile ( const char *  source)

Sets source file.

Parameters
[in]sourceSource file to be generated.

Definition at line 175 of file XMLPacketGen.cpp.

References mClone, mConstruct, mDecode, mDestruct, mDump, mEncode, mSourceFile, mSourceFileName, and Generator::SetOutputFile().

Referenced by main(), and ~XMLPacketGen().

176 {
177  if( mSourceFileName != source )
178  {
179  if( NULL != mSourceFile )
180  {
181  fclose( mSourceFile );
182  mSourceFile = NULL;
183 
184  // propagate the change to the generators
185  mClone.SetOutputFile( NULL );
186  mConstruct.SetOutputFile( NULL );
187  mDecode.SetOutputFile( NULL );
188  mDestruct.SetOutputFile( NULL );
189  mDump.SetOutputFile( NULL );
190  mEncode.SetOutputFile( NULL );
191  }
192 
193  mSourceFileName = source;
194  }
195 }
FILE * mSourceFile
Definition: XMLPacketGen.h:91
ClassCloneGenerator mClone
Definition: XMLPacketGen.h:94
void SetOutputFile(FILE *outputFile)
Sets output file.
Definition: Generator.h:53
ClassDumpGenerator mDump
Definition: XMLPacketGen.h:98
ClassConstructGenerator mConstruct
Definition: XMLPacketGen.h:95
ClassDecodeGenerator mDecode
Definition: XMLPacketGen.h:96
ClassDestructGenerator mDestruct
Definition: XMLPacketGen.h:97
ClassEncodeGenerator mEncode
Definition: XMLPacketGen.h:99
std::string mSourceFileName
Definition: XMLPacketGen.h:92

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

ClassCloneGenerator XMLPacketGen::mClone
private

Definition at line 94 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElementDef(), and SetSourceFile().

ClassConstructGenerator XMLPacketGen::mConstruct
private

Definition at line 95 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElementDef(), and SetSourceFile().

ClassDecodeGenerator XMLPacketGen::mDecode
private

Definition at line 96 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElementDef(), and SetSourceFile().

ClassDestructGenerator XMLPacketGen::mDestruct
private

Definition at line 97 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElementDef(), and SetSourceFile().

ClassDumpGenerator XMLPacketGen::mDump
private

Definition at line 98 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElementDef(), and SetSourceFile().

ClassEncodeGenerator XMLPacketGen::mEncode
private

Definition at line 99 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElementDef(), and SetSourceFile().

ClassHeaderGenerator XMLPacketGen::mHeader
private

Definition at line 100 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElementDef(), and SetHeaderFile().

FILE* XMLPacketGen::mHeaderFile
private

Definition at line 89 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElements(), ParseInclude(), and SetHeaderFile().

std::string XMLPacketGen::mHeaderFileName
private

Definition at line 90 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElements(), and SetHeaderFile().

FILE* XMLPacketGen::mSourceFile
private

Definition at line 91 of file XMLPacketGen.h.

Referenced by OpenFiles(), ParseElements(), and SetSourceFile().

std::string XMLPacketGen::mSourceFileName
private

Definition at line 92 of file XMLPacketGen.h.

Referenced by OpenFiles(), and SetSourceFile().

const char *const XMLPacketGen::smGenFileComment
staticprivate
Initial value:
=
"/* EVEmu: EVE Online Server Emulator\n"
" \n"
" **************************************************************\n"
" This file is automatically generated, DO NOT EDIT IT DIRECTLY.\n"
" **************************************************************\n"
" \n"
" (If you need to customize an object, you must copy that object\n"
" into another source file, and give up the ability to generate it)\n"
" \n"
" \n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; version 2 of the License.\n"
" \n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY except by those people which sell it, which\n"
" are required to give you total support for your newly bought product;\n"
" without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n"
" A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n"
" \n"
" You should have received a copy of the GNU General Public License\n"
" along with this program; if not, write to the Free Software\n"
" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
" \n\n"
" Updated by Allan, 2016 - 2020"
" \n"
"*/"

Definition at line 104 of file XMLPacketGen.h.

Referenced by ParseElements().


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