EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CloneGenerator.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 #include "CloneGenerator.h"
28 
30 : Generator( outputFile )
31 {
33 }
34 
36 {
38 
40 }
41 
42 bool ClassCloneGenerator::ProcessElementDef( const TiXmlElement* field )
43 {
44  const char* name = field->Attribute( "name" );
45  if (name == nullptr) {
46  std::cout << std::endl << "ClassCloneGenerator:: <element> at line " << field->Row() << " is missing the name attribute, skipping.";
47  return false;
48  }
49 
50  fprintf( mOutputFile,
51  "%s& %s::operator=( const %s& oth )\n"
52  "{\n",
53  name, name, name
54  );
55 
56  if( !ParseElementChildren( field ) )
57  return false;
58 
59  fprintf( mOutputFile,
60  " return *this;\n"
61  "}\n"
62  "\n"
63  );
64 
65  return true;
66 }
67 
68 bool ClassCloneGenerator::ProcessElement( const TiXmlElement* field )
69 {
70  const char* name = field->Attribute( "name" );
71  if (name == nullptr) {
72  std::cout << std::endl << "ClassCloneGenerator::ProcessElement field at line " << field->Row() << " is missing the name attribute, skipping.";
73  return false;
74  }
75  const char* type = field->Attribute( "type" );
76  if (type == nullptr) {
77  std::cout << std::endl << "ClassCloneGenerator::ProcessElement field at line " << field->Row() << " is missing the type attribute, skipping.";
78  return false;
79  }
80 
81  fprintf( mOutputFile,
82  " %s = oth.%s;\n"
83  "\n",
84  name, name
85  );
86 
87  return true;
88 }
89 
90 bool ClassCloneGenerator::ProcessElementPtr( const TiXmlElement* field )
91 {
92  const char* name = field->Attribute( "name" );
93  if (name == nullptr) {
94  std::cout << std::endl << "ClassCloneGenerator::ProcessElementPtr field at line " << field->Row() << " is missing the name attribute, skipping.";
95  return false;
96  }
97  const char* type = field->Attribute( "type" );
98  if (type == nullptr) {
99  std::cout << std::endl << "ClassCloneGenerator::ProcessElementPtr field at line " << field->Row() << " is missing the type attribute, skipping.";
100  return false;
101  }
102 
103  fprintf( mOutputFile,
104  " SafeDelete(%s);\n"
105  " if (oth.%s == nullptr) {\n"
106  " %s = nullptr;\n"
107  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
108  " } else\n"
109  " %s = new %s(*oth.%s);\n"
110  "\n",
111  name,
112  name,
113  name,
114  name, name,
115  name, type, name
116  );
117 
118  return true;
119 }
120 
121 bool ClassCloneGenerator::ProcessRaw( const TiXmlElement* field )
122 {
123  const char* name = field->Attribute( "name" );
124  if (name == nullptr) {
125  std::cout << std::endl << "ClassCloneGenerator::ProcessRaw field at line " << field->Row() << " is missing the name attribute, skipping.";
126  return false;
127  }
128 
129  fprintf( mOutputFile,
130  " PySafeDecRef(%s);\n"
131  " if (oth.%s == nullptr) {\n"
132  " %s = nullptr;\n"
133  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
134  " } else\n"
135  " %s = oth.%s->Clone();\n"
136  "\n",
137  name,
138  name,
139  name,
140  name, name,
141  name, name
142  );
143 
144  return true;
145 }
146 
147 bool ClassCloneGenerator::ProcessInt( const TiXmlElement* field )
148 {
149  const char* name = field->Attribute( "name" );
150  if (name == nullptr) {
151  std::cout << std::endl << "ClassCloneGenerator::ProcessInt field at line " << field->Row() << " is missing the name attribute, skipping.";
152  return false;
153  }
154 
155  fprintf( mOutputFile,
156  " %s = oth.%s;\n"
157  "\n",
158  name, name
159  );
160 
161  return true;
162 }
163 
164 bool ClassCloneGenerator::ProcessLong( const TiXmlElement* field )
165 {
166  const char* name = field->Attribute( "name" );
167  if (name == nullptr) {
168  std::cout << std::endl << "ClassCloneGenerator::ProcessLong field at line " << field->Row() << " is missing the name attribute, skipping.";
169  return false;
170  }
171 
172  fprintf( mOutputFile,
173  " %s = oth.%s;\n"
174  "\n",
175  name, name
176  );
177 
178  return true;
179 }
180 
181 bool ClassCloneGenerator::ProcessReal( const TiXmlElement* field )
182 {
183  const char* name = field->Attribute( "name" );
184  if (name == nullptr) {
185  std::cout << std::endl << "ClassCloneGenerator::ProcessReal field at line " << field->Row() << " is missing the name attribute, skipping.";
186  return false;
187  }
188 
189  fprintf( mOutputFile,
190  " %s = oth.%s;\n"
191  "\n",
192  name, name
193  );
194 
195  return true;
196 }
197 
198 bool ClassCloneGenerator::ProcessBool( const TiXmlElement* field )
199 {
200  const char* name = field->Attribute( "name" );
201  if (name == nullptr) {
202  std::cout << std::endl << "ClassCloneGenerator::ProcessBool field at line " << field->Row() << " is missing the name attribute, skipping.";
203  return false;
204  }
205 
206  fprintf( mOutputFile,
207  " %s = oth.%s;\n"
208  "\n",
209  name, name
210  );
211 
212  return true;
213 }
214 
215 bool ClassCloneGenerator::ProcessNone( const TiXmlElement* field )
216 {
217  return true;
218 }
219 
220 bool ClassCloneGenerator::ProcessBuffer( const TiXmlElement* field )
221 {
222  const char* name = field->Attribute( "name" );
223  if (name == nullptr) {
224  std::cout << std::endl << "ClassCloneGenerator::ProcessBuffer field at line " << field->Row() << " is missing the name attribute, skipping.";
225  return false;
226  }
227 
228  fprintf( mOutputFile,
229  " PySafeDecRef(%s);\n"
230  " if (oth.%s == nullptr) {\n"
231  " %s = nullptr;\n"
232  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
233  " } else\n"
234  " %s = new PyBuffer(*oth.%s);\n"
235  "\n",
236  name,
237  name,
238  name,
239  name, name,
240  name, name
241  );
242 
243  return true;
244 }
245 
246 bool ClassCloneGenerator::ProcessString( const TiXmlElement* field )
247 {
248  const char* name = field->Attribute( "name" );
249  if (name == nullptr) {
250  std::cout << std::endl << "ClassCloneGenerator::ProcessString field at line " << field->Row() << " is missing the name attribute, skipping.";
251  return false;
252  }
253 
254  fprintf( mOutputFile,
255  " %s = oth.%s;\n"
256  "\n",
257  name, name
258  );
259 
260  return true;
261 }
262 
263 bool ClassCloneGenerator::ProcessStringInline( const TiXmlElement* field )
264 {
265  return true;
266 }
267 
268 bool ClassCloneGenerator::ProcessWString( const TiXmlElement* field )
269 {
270  const char* name = field->Attribute( "name" );
271  if (name == nullptr) {
272  std::cout << std::endl << "ClassCloneGenerator::ProcessWString field at line " << field->Row() << " is missing the name attribute, skipping.";
273  return false;
274  }
275 
276  fprintf( mOutputFile,
277  " %s = oth.%s;\n"
278  "\n",
279  name, name
280  );
281 
282  return true;
283 }
284 
285 bool ClassCloneGenerator::ProcessWStringInline( const TiXmlElement* field )
286 {
287  return true;
288 }
289 
290 bool ClassCloneGenerator::ProcessToken( const TiXmlElement* field )
291 {
292  const char* name = field->Attribute( "name" );
293  if (name == nullptr) {
294  std::cout << std::endl << "ClassCloneGenerator::ProcessToken field at line " << field->Row() << " is missing the name attribute, skipping.";
295  return false;
296  }
297 
298  fprintf( mOutputFile,
299  " PySafeDecRef(%s);\n"
300  " if (oth.%s == nullptr) {\n"
301  " %s = nullptr;\n"
302  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
303  " } else\n"
304  " %s = oth.%s->Clone();\n"
305  "\n",
306  name,
307  name,
308  name,
309  name, name,
310  name, name
311  );
312 
313  return true;
314 }
315 
316 bool ClassCloneGenerator::ProcessTokenInline( const TiXmlElement* field )
317 {
318  return true;
319 }
320 
321 bool ClassCloneGenerator::ProcessObject( const TiXmlElement* field )
322 {
323  const char* name = field->Attribute( "name" );
324  if (name == nullptr) {
325  std::cout << std::endl << "ClassCloneGenerator::ProcessObject field at line " << field->Row() << " is missing the name attribute, skipping.";
326  return false;
327  }
328 
329  fprintf( mOutputFile,
330  " PySafeDecRef(%s);\n"
331  " if (oth.%s == nullptr) {\n"
332  " %s = nullptr;\n"
333  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
334  " } else\n"
335  " %s = new PyObject(*oth.%s);\n"
336  "\n",
337  name,
338  name,
339  name,
340  name, name,
341  name, name
342  );
343 
344  return true;
345 }
346 
347 bool ClassCloneGenerator::ProcessObjectInline( const TiXmlElement* field )
348 {
349  return ParseElementChildren( field, 2 );
350 }
351 
352 bool ClassCloneGenerator::ProcessObjectEx( const TiXmlElement* field )
353 {
354  const char* name = field->Attribute( "name" );
355  if (name == nullptr) {
356  std::cout << std::endl << "ClassCloneGenerator::ProcessObjectEx field at line " << field->Row() << " is missing the name attribute, skipping.";
357  return false;
358  }
359  const char* type = field->Attribute( "type" );
360  if (type == nullptr) {
361  std::cout << std::endl << "ClassCloneGenerator::ProcessObjectEx field at line " << field->Row() << " is missing the type attribute, skipping.";
362  return false;
363  }
364 
365  fprintf( mOutputFile,
366  " PySafeDecRef(%s);\n"
367  " if (oth.%s == nullptr) {\n"
368  " %s = nullptr;\n"
369  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
370  " } else\n"
371  " %s = new %s(*oth.%s);\n",
372  name,
373  name,
374  name,
375  name, name,
376  name, type, name
377  );
378 
379  return true;
380 }
381 
382 bool ClassCloneGenerator::ProcessTuple( const TiXmlElement* field )
383 {
384  const char* name = field->Attribute( "name" );
385  if (name == nullptr) {
386  std::cout << std::endl << "ClassCloneGenerator::ProcessTuple field at line " << field->Row() << " is missing the name attribute, skipping.";
387  return false;
388  }
389 
390  fprintf( mOutputFile,
391  " PySafeDecRef(%s);\n"
392  " if (oth.%s == nullptr) {\n"
393  " %s = nullptr;\n"
394  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
395  " } else\n"
396  " %s = new PyTuple(*oth.%s);\n"
397  "\n",
398  name,
399  name,
400  name,
401  name, name,
402  name, name
403  );
404 
405  return true;
406 }
407 
408 bool ClassCloneGenerator::ProcessTupleInline( const TiXmlElement* field )
409 {
410  return ParseElementChildren( field );
411 }
412 
413 bool ClassCloneGenerator::ProcessList( const TiXmlElement* field )
414 {
415  const char* name = field->Attribute( "name" );
416  if (name == nullptr) {
417  std::cout << std::endl << "ClassCloneGenerator::ProcessList field at line " << field->Row() << " is missing the name attribute, skipping.";
418  return false;
419  }
420 
421  fprintf( mOutputFile,
422  " PySafeDecRef(%s);\n"
423  " if (oth.%s == nullptr) {\n"
424  " %s = nullptr;\n"
425  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
426  " } else\n"
427  " %s = new PyList(*oth.%s);\n"
428  "\n",
429  name,
430  name,
431  name,
432  name, name,
433  name, name
434  );
435 
436  return true;
437 }
438 
439 bool ClassCloneGenerator::ProcessListInline( const TiXmlElement* field )
440 {
441  return ParseElementChildren( field );
442 }
443 
444 bool ClassCloneGenerator::ProcessListInt( const TiXmlElement* field )
445 {
446  const char* name = field->Attribute( "name" );
447  if (name == nullptr) {
448  std::cout << std::endl << "ClassCloneGenerator::ProcessListInt field at line " << field->Row() << " is missing the name attribute, skipping.";
449  return false;
450  }
451 
452  fprintf( mOutputFile,
453  " %s = oth.%s;\n"
454  "\n",
455  name, name
456  );
457 
458  return true;
459 }
460 
461 bool ClassCloneGenerator::ProcessListLong( const TiXmlElement* field )
462 {
463  const char* name = field->Attribute( "name" );
464  if (name == nullptr) {
465  std::cout << std::endl << "ClassCloneGenerator::ProcessListLong field at line " << field->Row() << " is missing the name attribute, skipping.";
466  return false;
467  }
468 
469  fprintf( mOutputFile,
470  " %s = oth.%s;\n"
471  "\n",
472  name, name
473  );
474 
475  return true;
476 }
477 
478 bool ClassCloneGenerator::ProcessListStr( const TiXmlElement* field )
479 {
480  const char* name = field->Attribute( "name" );
481  if (name == nullptr) {
482  std::cout << std::endl << "ClassCloneGenerator::ProcessListStr field at line " << field->Row() << " is missing the name attribute, skipping.";
483  return false;
484  }
485 
486  fprintf( mOutputFile,
487  " %s = oth.%s;\n"
488  "\n",
489  name, name
490  );
491 
492  return true;
493 }
494 
495 bool ClassCloneGenerator::ProcessDict( const TiXmlElement* field )
496 {
497  const char* name = field->Attribute( "name" );
498  if (name == nullptr) {
499  std::cout << std::endl << "ClassCloneGenerator::ProcessDict field at line " << field->Row() << " is missing the name attribute, skipping.";
500  return false;
501  }
502 
503  fprintf(mOutputFile,
504  " PySafeDecRef(%s);\n"
505  " if (oth.%s == nullptr) {\n"
506  " %s = nullptr;\n"
507  " _log(NET__PACKET_WARNING, \"oth.%s is null. %s = nullptr \");\n"
508  " } else\n"
509  " %s = new PyDict(*oth.%s);\n"
510  "\n",
511  name,
512  name,
513  name,
514  name, name,
515 
516  name, name
517  );
518 
519  return true;
520 }
521 
522 bool ClassCloneGenerator::ProcessDictInline( const TiXmlElement* field )
523 {
524  return ParseElementChildren( field );
525 }
526 
527 bool ClassCloneGenerator::ProcessDictInlineEntry( const TiXmlElement* field )
528 {
529  //we dont really even care about this...
530  const char* key = field->Attribute( "key" );
531  if (key == nullptr) {
532  std::cout << std::endl << "ClassCloneGenerator::ProcessDictInlineEntry <dictInlineEntry> at line " << field->Row() << " is missing the key attribute, skipping.";
533  return false;
534  }
535 
536  return ParseElementChildren( field, 1 );
537 }
538 
539 bool ClassCloneGenerator::ProcessDictRaw( const TiXmlElement* field )
540 {
541  const char* name = field->Attribute( "name" );
542  if (name == nullptr) {
543  std::cout << std::endl << "ClassCloneGenerator::ProcessDictRaw field at line " << field->Row() << " is missing the name attribute, skipping.";
544  return false;
545  }
546 
547  fprintf( mOutputFile,
548  " %s = oth.%s;\n"
549  "\n",
550  name, name
551  );
552 
553  return true;
554 }
555 
556 bool ClassCloneGenerator::ProcessDictInt( const TiXmlElement* field )
557 {
558  const char* name = field->Attribute( "name" );
559 
560  if (name == nullptr) {
561  std::cout << std::endl << "ClassCloneGenerator::ProcessDictInt field at line " << field->Row() << " is missing the name attribute, skipping.";
562  return false;
563  }
564 
565  fprintf( mOutputFile,
566  " std::map<int32, PyRep*>::const_iterator %s_cur = %s.begin();\n"
567  " //free any existing elements first\n"
568  " for (; %s_cur != %s.end(); %s_cur++)\n"
569  " PyDecRef( %s_cur->second );\n"
570  " %s.clear();\n"
571  "\n"
572  " //now we can copy in the new ones...\n"
573  " for (%s_cur = oth.%s.begin(); %s_cur != oth.%s.end(); %s_cur++)\n"
574  " %s[ %s_cur->first ] = %s_cur->second->Clone();\n"
575  "\n",
576  name, name,
577  name, name, name,
578  name,
579  name,
580  name, name, name, name, name,
581  name, name, name
582  );
583 
584  return true;
585 }
586 
587 bool ClassCloneGenerator::ProcessDictStr( const TiXmlElement* field )
588 {
589  const char* name = field->Attribute( "name" );
590  if (name == nullptr) {
591  std::cout << std::endl << "ClassCloneGenerator::ProcessDictStr field at line " << field->Row() << " is missing the name attribute, skipping.";
592  return false;
593  }
594 
595  fprintf( mOutputFile,
596  " std::map<std::string, PyRep*>::const_iterator %s_cur = %s.begin();\n"
597  " //free any existing elements first\n"
598  " for (; %s_cur != %s.end(); %s_cur++)\n"
599  " PyDecRef( %s_cur->second );\n"
600  " %s.clear();\n"
601  "\n"
602  " //now we can copy in the new ones...\n"
603  " for (%s_cur = oth.%s.begin(); %s_cur != oth.%s.end(); %s_cur++)\n"
604  " %s[ %s_cur->first ] = %s_cur->second->Clone();\n"
605  "\n",
606  name, name,
607  name, name, name,
608  name,
609  name,
610  name, name, name, name, name,
611  name, name, name
612  );
613 
614  return true;
615 }
616 
617 bool ClassCloneGenerator::ProcessSubStreamInline( const TiXmlElement* field )
618 {
619  return ParseElementChildren( field, 1 );
620 }
621 
622 bool ClassCloneGenerator::ProcessSubStructInline( const TiXmlElement* field )
623 {
624  return ParseElementChildren( field, 1 );
625 }
626 
bool ProcessTupleInline(const TiXmlElement *field)
bool ProcessListLong(const TiXmlElement *field)
bool ProcessDictStr(const TiXmlElement *field)
bool ProcessTokenInline(const TiXmlElement *field)
void RegisterProcessors()
Definition: Generator.cpp:44
bool ProcessListInline(const TiXmlElement *field)
bool ProcessList(const TiXmlElement *field)
bool ProcessDictInlineEntry(const TiXmlElement *field)
bool ProcessReal(const TiXmlElement *field)
bool ProcessNone(const TiXmlElement *field)
bool ProcessListStr(const TiXmlElement *field)
bool ProcessBool(const TiXmlElement *field)
bool ProcessDict(const TiXmlElement *field)
bool ProcessStringInline(const TiXmlElement *field)
bool ProcessBuffer(const TiXmlElement *field)
bool ProcessString(const TiXmlElement *field)
bool ProcessToken(const TiXmlElement *field)
FILE * mOutputFile
Definition: Generator.h:108
bool ProcessElement(const TiXmlElement *field)
bool ProcessInt(const TiXmlElement *field)
bool ProcessObjectEx(const TiXmlElement *field)
bool ProcessObjectInline(const TiXmlElement *field)
bool ProcessLong(const TiXmlElement *field)
bool ProcessRaw(const TiXmlElement *field)
bool ProcessObject(const TiXmlElement *field)
bool ProcessElementDef(const TiXmlElement *field)
bool ProcessDictInline(const TiXmlElement *field)
bool ProcessDictRaw(const TiXmlElement *field)
ClassCloneGenerator(FILE *outputFile=NULL)
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
bool ProcessTuple(const TiXmlElement *field)
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 ProcessSubStructInline(const TiXmlElement *field)
bool ProcessWString(const TiXmlElement *field)
bool ProcessElementPtr(const TiXmlElement *field)
bool ProcessWStringInline(const TiXmlElement *field)
bool ProcessDictInt(const TiXmlElement *field)
bool ProcessSubStreamInline(const TiXmlElement *field)
bool ProcessListInt(const TiXmlElement *field)
void AddMemberParser(const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
Adds a member parser.
Definition: XMLParserEx.h:55