EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConstructGenerator.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 "ConstructGenerator.h"
29 
31 : Generator( outputFile )
32 {
34 }
35 
37 {
39 
41 }
42 
43 bool ClassConstructGenerator::ProcessElementDef( const TiXmlElement* field )
44 {
45  const char* name = field->Attribute( "name" );
46  if (name == nullptr) {
47  std::cout << std::endl << "ClassConstructGenerator::ProcessElementDef <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  "%s::%s( const %s& oth )\n"
64  "{\n"
65  " *this = oth;\n"
66  "}\n"
67  "\n",
68  name, name, name
69  );
70 
71  return true;
72 }
73 
74 bool ClassConstructGenerator::ProcessElement( const TiXmlElement* field )
75 {
76  return true;
77 }
78 
79 bool ClassConstructGenerator::ProcessElementPtr( const TiXmlElement* field )
80 {
81  const char* name = field->Attribute( "name" );
82  if (name == nullptr) {
83  std::cout << std::endl << "ClassConstructGenerator::ProcessElementPtr field at line " << field->Row() << " is missing the name attribute, skipping.";
84  return false;
85  }
86 
87  fprintf( mOutputFile,
88  " %s = nullptr;\n",
89  name
90  );
91 
92  return true;
93 }
94 
95 bool ClassConstructGenerator::ProcessRaw( const TiXmlElement* field )
96 {
97  const char* name = field->Attribute( "name" );
98  if (name == nullptr) {
99  std::cout << std::endl << "ClassConstructGenerator::ProcessRaw field at line " << field->Row() << " is missing the name attribute, skipping.";
100  return false;
101  }
102 
103  fprintf( mOutputFile,
104  " %s = nullptr;\n",
105  name
106  );
107 
108  return true;
109 }
110 
111 bool ClassConstructGenerator::ProcessInt( const TiXmlElement* field )
112 {
113  const char* name = field->Attribute( "name" );
114  if (name == nullptr) {
115  std::cout << std::endl << "ClassConstructGenerator::ProcessInt field at line " << field->Row() << " is missing the name attribute, skipping.";
116  return false;
117  }
118 
119  const char* def = field->Attribute( "default" );
120  if (def == nullptr)
121  def = "0";
122 
123  fprintf( mOutputFile,
124  " %s = %s;\n",
125  name, def
126  );
127 
128  return true;
129 }
130 
131 bool ClassConstructGenerator::ProcessLong( const TiXmlElement* field )
132 {
133  const char* name = field->Attribute( "name" );
134  if (name == nullptr) {
135  std::cout << std::endl << "ClassConstructGenerator::ProcessLong field at line " << field->Row() << " is missing the name attribute, skipping.";
136  return false;
137  }
138 
139  const char* def = field->Attribute( "default" );
140  if (def == nullptr)
141  def = "0";
142 
143  fprintf( mOutputFile,
144  " %s = %s;\n",
145  name, def
146  );
147 
148  return true;
149 }
150 
151 bool ClassConstructGenerator::ProcessReal( const TiXmlElement* field )
152 {
153  const char* name = field->Attribute( "name" );
154  if (name == nullptr) {
155  std::cout << std::endl << "ClassConstructGenerator::ProcessReal field at line " << field->Row() << " is missing the name attribute, skipping.";
156  return false;
157  }
158 
159  const char* def = field->Attribute( "default" );
160  if (def == nullptr)
161  def = "0.0";
162 
163  fprintf( mOutputFile,
164  " %s = %s;\n",
165  name, def
166  );
167 
168  return true;
169 }
170 
171 bool ClassConstructGenerator::ProcessBool( const TiXmlElement* field )
172 {
173  const char* name = field->Attribute( "name" );
174  if (name == nullptr) {
175  std::cout << std::endl << "ClassConstructGenerator::ProcessBool field at line " << field->Row() << " is missing the name attribute, skipping.";
176  return false;
177  }
178 
179  const char* def = field->Attribute( "default" );
180  if (def == nullptr)
181  def = "false";
182 
183  fprintf( mOutputFile,
184  " %s = %s;\n",
185  name, def
186  );
187 
188  return true;
189 }
190 
191 bool ClassConstructGenerator::ProcessNone( const TiXmlElement* field )
192 {
193  return true;
194 }
195 
196 bool ClassConstructGenerator::ProcessBuffer( const TiXmlElement* field )
197 {
198  const char* name = field->Attribute( "name" );
199  if (name == nullptr) {
200  std::cout << std::endl << "ClassConstructGenerator::ProcessBuffer field at line " << field->Row() << " is missing the name attribute, skipping.";
201  return false;
202  }
203 
204  fprintf( mOutputFile,
205  " %s = nullptr;\n",
206  name
207  );
208 
209  return true;
210 }
211 
212 bool ClassConstructGenerator::ProcessString( const TiXmlElement* field )
213 {
214  const char* name = field->Attribute( "name" );
215  if (name == nullptr) {
216  std::cout << std::endl << "ClassConstructGenerator::ProcessString field at line " << field->Row() << " is missing the name attribute, skipping.";
217  return false;
218  }
219 
220  const char* def = field->Attribute( "default" );
221  if (def == nullptr)
222  def = "";
223 
224  fprintf( mOutputFile,
225  " %s = \"%s\";\n",
226  name, def
227  );
228 
229  return true;
230 }
231 
232 bool ClassConstructGenerator::ProcessStringInline( const TiXmlElement* field )
233 {
234  return true;
235 }
236 
237 bool ClassConstructGenerator::ProcessWString( const TiXmlElement* field )
238 {
239  const char* name = field->Attribute( "name" );
240  if (name == nullptr) {
241  std::cout << std::endl << "ClassConstructGenerator::ProcessWString field at line " << field->Row() << " is missing the name attribute, skipping.";
242  return false;
243  }
244 
245  const char* def = field->Attribute( "default" );
246  if (def == nullptr)
247  def = "";
248 
249  fprintf( mOutputFile,
250  " %s = \"%s\";\n",
251  name, def
252  );
253 
254  return true;
255 }
256 
257 bool ClassConstructGenerator::ProcessWStringInline( const TiXmlElement* field )
258 {
259  return true;
260 }
261 
262 bool ClassConstructGenerator::ProcessToken( const TiXmlElement* field )
263 {
264  const char* name = field->Attribute( "name" );
265  if (name == nullptr) {
266  std::cout << std::endl << "ClassConstructGenerator::ProcessToken field at line " << field->Row() << " is missing the name attribute, skipping.";
267  return false;
268  }
269 
270  fprintf( mOutputFile,
271  " %s = nullptr;\n",
272  name
273  );
274 
275  return true;
276 }
277 
278 bool ClassConstructGenerator::ProcessTokenInline( const TiXmlElement* field )
279 {
280  return true;
281 }
282 
283 bool ClassConstructGenerator::ProcessObject( const TiXmlElement* field )
284 {
285  const char* name = field->Attribute( "name" );
286  if (name == nullptr) {
287  std::cout << std::endl << "ClassConstructGenerator::ProcessObject field at line " << field->Row() << " is missing the name attribute, skipping.";
288  return false;
289  }
290 
291  fprintf( mOutputFile,
292  " %s = nullptr;\n"
293  "\n",
294  name
295  );
296 
297  return true;
298 }
299 
300 bool ClassConstructGenerator::ProcessObjectInline( const TiXmlElement* field )
301 {
302  return ParseElementChildren( field, 2 );
303 }
304 
305 bool ClassConstructGenerator::ProcessObjectEx( const TiXmlElement* field )
306 {
307  const char *name = field->Attribute( "name" );
308  if (name == nullptr) {
309  std::cout << std::endl << "ClassConstructGenerator::ProcessObjectEx field at line " << field->Row() << " is missing the name attribute, skipping.";
310  return false;
311  }
312 
313  fprintf( mOutputFile,
314  " %s = nullptr;\n",
315  name
316  );
317 
318  return true;
319 }
320 
321 bool ClassConstructGenerator::ProcessTuple( const TiXmlElement* field )
322 {
323  const char *name = field->Attribute( "name" );
324  if (name == nullptr) {
325  std::cout << std::endl << "ClassConstructGenerator::ProcessTuple field at line " << field->Row() << " is missing the name attribute, skipping.";
326  return false;
327  }
328 
329  fprintf( mOutputFile,
330  " %s = nullptr;\n",
331  name
332  );
333 
334  return true;
335 }
336 
337 bool ClassConstructGenerator::ProcessTupleInline( const TiXmlElement* field )
338 {
339  return ParseElementChildren( field );
340 }
341 
342 bool ClassConstructGenerator::ProcessList( const TiXmlElement* field )
343 {
344  const char *name = field->Attribute( "name" );
345  if (name == nullptr) {
346  std::cout << std::endl << "ClassConstructGenerator::ProcessList field at line " << field->Row() << " is missing the name attribute, skipping.";
347  return false;
348  }
349 
350  fprintf( mOutputFile,
351  " %s = nullptr;\n",
352  name
353  );
354 
355  return true;
356 }
357 
358 bool ClassConstructGenerator::ProcessListInline( const TiXmlElement* field )
359 {
360  return ParseElementChildren( field );
361 }
362 
363 bool ClassConstructGenerator::ProcessListInt( const TiXmlElement* field )
364 {
365  return true;
366 }
367 
368 bool ClassConstructGenerator::ProcessListLong( const TiXmlElement* field )
369 {
370  return true;
371 }
372 
373 bool ClassConstructGenerator::ProcessListStr( const TiXmlElement* field )
374 {
375  return true;
376 }
377 
378 bool ClassConstructGenerator::ProcessDict( const TiXmlElement* field )
379 {
380  const char *name = field->Attribute( "name" );
381  if (name == nullptr) {
382  std::cout << std::endl << "ClassConstructGenerator::ProcessDict field at line " << field->Row() << " is missing the name attribute, skipping.";
383  return false;
384  }
385 
386  fprintf( mOutputFile,
387  " %s = nullptr;\n",
388  name
389  );
390 
391  return true;
392 }
393 
394 bool ClassConstructGenerator::ProcessDictInline( const TiXmlElement* field )
395 {
396  return ParseElementChildren( field );
397 }
398 
399 bool ClassConstructGenerator::ProcessDictInlineEntry( const TiXmlElement* field )
400 {
401  //we dont really even care about this...
402  const char* key = field->Attribute( "key" );
403  if (key == nullptr) {
404  std::cout << std::endl << "ClassConstructGenerator::ProcessDictInlineEntry field at line " << field->Row() << " is missing the name attribute, skipping.";
405  return false;
406  }
407 
408  return ParseElementChildren( field, 1 );
409 }
410 
411 bool ClassConstructGenerator::ProcessDictRaw( const TiXmlElement* field )
412 {
413  return true;
414 }
415 
416 bool ClassConstructGenerator::ProcessDictInt( const TiXmlElement* field )
417 {
418  return true;
419 }
420 
421 bool ClassConstructGenerator::ProcessDictStr( const TiXmlElement* field )
422 {
423  return true;
424 }
425 
426 bool ClassConstructGenerator::ProcessSubStreamInline( const TiXmlElement* field )
427 {
428  return ParseElementChildren( field, 1 );
429 }
430 
431 bool ClassConstructGenerator::ProcessSubStructInline( const TiXmlElement* field )
432 {
433  return ParseElementChildren( field, 1 );
434 }
bool ProcessTuple(const TiXmlElement *field)
bool ProcessTupleInline(const TiXmlElement *field)
bool ProcessListInt(const TiXmlElement *field)
bool ProcessDictStr(const TiXmlElement *field)
bool ProcessTokenInline(const TiXmlElement *field)
bool ProcessDict(const TiXmlElement *field)
bool ProcessNone(const TiXmlElement *field)
void RegisterProcessors()
Definition: Generator.cpp:44
bool ProcessObjectInline(const TiXmlElement *field)
bool ProcessBuffer(const TiXmlElement *field)
bool ProcessBool(const TiXmlElement *field)
bool ProcessSubStreamInline(const TiXmlElement *field)
bool ProcessToken(const TiXmlElement *field)
bool ProcessString(const TiXmlElement *field)
bool ProcessWStringInline(const TiXmlElement *field)
bool ProcessDictInt(const TiXmlElement *field)
bool ProcessElement(const TiXmlElement *field)
bool ProcessLong(const TiXmlElement *field)
FILE * mOutputFile
Definition: Generator.h:108
bool ProcessSubStructInline(const TiXmlElement *field)
bool ProcessObject(const TiXmlElement *field)
bool ProcessDictInline(const TiXmlElement *field)
bool ProcessRaw(const TiXmlElement *field)
bool ProcessListStr(const TiXmlElement *field)
bool ProcessDictInlineEntry(const TiXmlElement *field)
bool ProcessList(const TiXmlElement *field)
bool ProcessListInline(const TiXmlElement *field)
bool ProcessElementPtr(const TiXmlElement *field)
bool ProcessReal(const TiXmlElement *field)
bool ProcessListLong(const TiXmlElement *field)
ClassConstructGenerator(FILE *outputFile=NULL)
Generic class for eve-xmlpktgen's generators.
Definition: Generator.h:37
bool ProcessDictRaw(const TiXmlElement *field)
bool ProcessElementDef(const TiXmlElement *field)
bool ParseElementChildren(const TiXmlElement *element, size_t max=0) const
Parses element's children using registered parsers.
Definition: XMLParser.cpp:72
bool ProcessInt(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 ProcessObjectEx(const TiXmlElement *field)
bool ProcessWString(const TiXmlElement *field)
bool ProcessStringInline(const TiXmlElement *field)
void AddMemberParser(const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
Adds a member parser.
Definition: XMLParserEx.h:55