EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DestructGenerator.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 #include "eve-xmlpktgen.h"
27 
28 #include "DestructGenerator.h"
29 
31 : Generator( outputFile )
32 {
34 }
35 
37 {
39 
41 }
42 
43 bool ClassDestructGenerator::ProcessElementDef( const TiXmlElement* field )
44 {
45  const char* name = field->Attribute( "name" );
46  if (name == nullptr) {
47  std::cout << std::endl << "ClassDestructGenerator:: <element> at line " << field->Row() << " is missing the name attribute, skipping.";
48  return false;
49  }
50 
51  fprintf( mOutputFile,
52  "%s::~%s()\n"
53  "{\n",
54  name, name
55  );
56 
57  if( !ParseElementChildren( field ) )
58  return false;
59 
60  fprintf( mOutputFile,
61  "}\n"
62  "\n"
63  );
64 
65  return true;
66 }
67 
68 bool ClassDestructGenerator::ProcessElement( const TiXmlElement* field )
69 {
70  return true;
71 }
72 
73 bool ClassDestructGenerator::ProcessElementPtr( const TiXmlElement* field )
74 {
75  const char* name = field->Attribute( "name" );
76  if (name == nullptr) {
77  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
78  return false;
79  }
80 
81  fprintf( mOutputFile,
82  " SafeDelete( %s );\n",
83  name
84  );
85 
86  return true;
87 }
88 
89 bool ClassDestructGenerator::ProcessRaw( const TiXmlElement* field )
90 {
91  const char* name = field->Attribute( "name" );
92  if (name == nullptr) {
93  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
94  return false;
95  }
96 
97  fprintf( mOutputFile,
98  " PySafeDecRef( %s );\n",
99  name
100  );
101 
102  return true;
103 }
104 
105 bool ClassDestructGenerator::ProcessInt( const TiXmlElement* field )
106 {
107  return true;
108 }
109 
110 bool ClassDestructGenerator::ProcessLong( const TiXmlElement* field )
111 {
112  return true;
113 }
114 
115 bool ClassDestructGenerator::ProcessReal( const TiXmlElement* field )
116 {
117  return true;
118 }
119 
120 bool ClassDestructGenerator::ProcessBool( const TiXmlElement* field )
121 {
122  return true;
123 }
124 
125 bool ClassDestructGenerator::ProcessNone( const TiXmlElement* field )
126 {
127  return true;
128 }
129 
130 bool ClassDestructGenerator::ProcessBuffer( const TiXmlElement* field )
131 {
132  const char* name = field->Attribute( "name" );
133  if (name == nullptr) {
134  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
135  return false;
136  }
137 
138  fprintf( mOutputFile,
139  " //PySafeDecRef( %s );\n",
140  name
141  );
142 
143  return true;
144 }
145 
146 bool ClassDestructGenerator::ProcessString( const TiXmlElement* field )
147 {
148  return true;
149 }
150 
151 bool ClassDestructGenerator::ProcessStringInline( const TiXmlElement* field )
152 {
153  return true;
154 }
155 
156 bool ClassDestructGenerator::ProcessWString( const TiXmlElement* field )
157 {
158  return true;
159 }
160 
161 bool ClassDestructGenerator::ProcessWStringInline( const TiXmlElement* field )
162 {
163  return true;
164 }
165 
166 bool ClassDestructGenerator::ProcessToken( const TiXmlElement* field )
167 {
168  const char* name = field->Attribute( "name" );
169  if (name == nullptr) {
170  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
171  return false;
172  }
173 
174  fprintf( mOutputFile,
175  " //PySafeDecRef( %s );\n",
176  name
177  );
178 
179  return true;
180 }
181 
182 bool ClassDestructGenerator::ProcessTokenInline( const TiXmlElement* field )
183 {
184  return true;
185 }
186 
187 bool ClassDestructGenerator::ProcessObject( const TiXmlElement* field )
188 {
189  const char* name = field->Attribute( "name" );
190  if (name == nullptr) {
191  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
192  return false;
193  }
194 
195  fprintf( mOutputFile,
196  " //PySafeDecRef( %s );\n"
197  "\n",
198  name
199  );
200 
201  return true;
202 }
203 
204 bool ClassDestructGenerator::ProcessObjectInline( const TiXmlElement* field )
205 {
206  return ParseElementChildren( field, 2 );
207 }
208 
209 bool ClassDestructGenerator::ProcessObjectEx( const TiXmlElement* field )
210 {
211  const char* name = field->Attribute( "name" );
212  if (name == nullptr) {
213  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
214  return false;
215  }
216 
217  fprintf( mOutputFile,
218  " //PySafeDecRef( %s );\n",
219  name
220  );
221 
222  return true;
223 }
224 
225 bool ClassDestructGenerator::ProcessTuple( const TiXmlElement* field )
226 {
227  const char* name = field->Attribute( "name" );
228  if (name == nullptr) {
229  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
230  return false;
231  }
232 
233  fprintf( mOutputFile,
234  " //PySafeDecRef( %s );\n",
235  name
236  );
237 
238  return true;
239 }
240 
241 bool ClassDestructGenerator::ProcessTupleInline( const TiXmlElement* field )
242 {
243  return ParseElementChildren( field );
244 }
245 
246 bool ClassDestructGenerator::ProcessList( const TiXmlElement* field )
247 {
248  const char* name = field->Attribute( "name" );
249  if (name == nullptr) {
250  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
251  return false;
252  }
253 
254  fprintf( mOutputFile,
255  " //PySafeDecRef( %s );\n",
256  name
257  );
258 
259  return true;
260 }
261 
262 bool ClassDestructGenerator::ProcessListInline( const TiXmlElement* field )
263 {
264  return ParseElementChildren( field );
265 }
266 
267 bool ClassDestructGenerator::ProcessListInt( const TiXmlElement* field )
268 {
269  return true;
270 }
271 
272 bool ClassDestructGenerator::ProcessListLong( const TiXmlElement* field )
273 {
274  return true;
275 }
276 
277 bool ClassDestructGenerator::ProcessListStr( const TiXmlElement* field ) {
278  return true;
279 }
280 
281 bool ClassDestructGenerator::ProcessDict( const TiXmlElement* field )
282 {
283  const char* name = field->Attribute( "name" );
284  if (name == nullptr) {
285  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
286  return false;
287  }
288 
289  fprintf( mOutputFile,
290  " //PySafeDecRef( %s );\n",
291  name
292  );
293 
294  return true;
295 }
296 
297 bool ClassDestructGenerator::ProcessDictInline( const TiXmlElement* field )
298 {
299  return ParseElementChildren( field );
300 }
301 
302 bool ClassDestructGenerator::ProcessDictInlineEntry( const TiXmlElement* field )
303 {
304  //we dont really even care about this...
305  const char* key = field->Attribute( "key" );
306  if (key == nullptr) {
307  std::cout << std::endl << "ClassDestructGenerator:: <dictInlineEntry> at line " << field->Row() << " is missing the key attribute, skipping.";
308  return false;
309  }
310 
311  return ParseElementChildren( field, 1 );
312 }
313 
314 bool ClassDestructGenerator::ProcessDictRaw( const TiXmlElement* field )
315 {
316  return true;
317 }
318 
319 bool ClassDestructGenerator::ProcessDictInt( const TiXmlElement* field )
320 {
321  const char* name = field->Attribute( "name" );
322  if (name == nullptr) {
323  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
324  return false;
325  }
326 
327  fprintf( mOutputFile,
328  " std::map<int32, PyRep*>::const_iterator %s_cur = %s.begin();\n"
329  " for (; %s_cur != %s.end(); %s_cur++)\n"
330  " PyDecRef( %s_cur->second );\n"
331  "\n",
332  name, name,
333  name, name, name,
334  name
335  );
336 
337  return true;
338 }
339 
340 bool ClassDestructGenerator::ProcessDictStr( const TiXmlElement* field )
341 {
342  const char* name = field->Attribute( "name" );
343  if (name == nullptr) {
344  std::cout << std::endl << "ClassDestructGenerator:: field at line " << field->Row() << " is missing the name attribute, skipping.";
345  return false;
346  }
347 
348  fprintf( mOutputFile,
349  " std::map<std::string, PyRep*>::const_iterator %s_cur = %s.begin();\n"
350  " for (; %s_cur != %s.end(); %s_cur++)\n"
351  " PyDecRef( %s_cur->second );\n"
352  "\n",
353  name, name,
354  name, name, name,
355  name
356  );
357 
358  return true;
359 }
360 
361 bool ClassDestructGenerator::ProcessSubStreamInline( const TiXmlElement* field )
362 {
363  return ParseElementChildren( field, 1 );
364 }
365 
366 bool ClassDestructGenerator::ProcessSubStructInline( const TiXmlElement* field )
367 {
368  return ParseElementChildren( field, 1 );
369 }
370 
bool ProcessList(const TiXmlElement *field)
bool ProcessListLong(const TiXmlElement *field)
bool ProcessReal(const TiXmlElement *field)
bool ProcessListStr(const TiXmlElement *field)
bool ProcessTuple(const TiXmlElement *field)
bool ProcessDict(const TiXmlElement *field)
ClassDestructGenerator(FILE *outputFile=NULL)
bool ProcessTokenInline(const TiXmlElement *field)
void RegisterProcessors()
Definition: Generator.cpp:44
bool ProcessObject(const TiXmlElement *field)
bool ProcessListInline(const TiXmlElement *field)
bool ProcessObjectInline(const TiXmlElement *field)
bool ProcessDictRaw(const TiXmlElement *field)
bool ProcessObjectEx(const TiXmlElement *field)
bool ProcessSubStructInline(const TiXmlElement *field)
FILE * mOutputFile
Definition: Generator.h:108
bool ProcessLong(const TiXmlElement *field)
bool ProcessBuffer(const TiXmlElement *field)
bool ProcessSubStreamInline(const TiXmlElement *field)
bool ProcessToken(const TiXmlElement *field)
bool ProcessListInt(const TiXmlElement *field)
bool ProcessDictInlineEntry(const TiXmlElement *field)
bool ProcessInt(const TiXmlElement *field)
bool ProcessTupleInline(const TiXmlElement *field)
Generic class for eve-xmlpktgen's generators.
Definition: Generator.h:37
bool ParseElementChildren(const TiXmlElement *element, size_t max=0) const
Parses element's children using registered parsers.
Definition: XMLParser.cpp:72
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type() key(value)-Send an OnRemoteMessage" ) COMMAND( setbpattr
bool ProcessDictStr(const TiXmlElement *field)
bool ProcessStringInline(const TiXmlElement *field)
bool ProcessBool(const TiXmlElement *field)
bool ProcessRaw(const TiXmlElement *field)
bool ProcessWStringInline(const TiXmlElement *field)
bool ProcessDictInline(const TiXmlElement *field)
bool ProcessElementDef(const TiXmlElement *field)
bool ProcessNone(const TiXmlElement *field)
bool ProcessDictInt(const TiXmlElement *field)
bool ProcessElement(const TiXmlElement *field)
bool ProcessWString(const TiXmlElement *field)
bool ProcessElementPtr(const TiXmlElement *field)
bool ProcessString(const TiXmlElement *field)
void AddMemberParser(const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
Adds a member parser.
Definition: XMLParserEx.h:55