40 mName = field->Attribute(
"name" );
41 if (
mName ==
nullptr) {
42 std::cout << std::endl <<
"ClassEncodeGenerator:: <element> at line " << field->Row() <<
" is missing the name attribute, skipping.";
46 const TiXmlElement*
main = field->FirstChildElement();
47 if (main->NextSiblingElement() !=
nullptr) {
48 std::cout << std::endl <<
"ClassEncodeGenerator:: <element> at line " << field->Row() <<
" contains more than one root element, skipping.";
54 "%s* %s::Encode() const\n"
56 " %s* res(nullptr);\n"
80 const char* name = field->Attribute(
"name" );
81 if (name ==
nullptr) {
82 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
87 " %s = %s.Encode();\n"
98 const char* name = field->Attribute(
"name" );
99 if (name ==
nullptr) {
100 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
104 const char* v =
top();
106 " if (%s != nullptr)\n"
107 " %s = %s->Encode();\n"
109 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding a PyNone\");\n"
110 " %s = PyStatic.NewNone();\n"
123 const char* name = field->Attribute(
"name" );
124 if (name ==
nullptr) {
125 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
129 const char* v =
top();
131 " if (%s != nullptr) {\n"
135 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding a PyNone\");\n"
136 " %s = PyStatic.NewNone();\n"
152 const char* name = field->Attribute(
"name" );
153 if (name ==
nullptr) {
154 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
158 const char* none_marker = field->Attribute(
"none_marker" );
159 const char* v =
top();
160 if (none_marker !=
nullptr)
163 " %s = PyStatic.NewNone();\n"
170 " %s = new PyInt( %s );\n",
180 const char* name = field->Attribute(
"name" );
181 if (name ==
nullptr) {
182 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
186 const char* none_marker = field->Attribute(
"none_marker" );
187 const char* v =
top();
188 if (none_marker !=
nullptr )
191 " %s = PyStatic.NewNone();\n"
198 " %s = new PyLong( %s );\n",
208 const char* name = field->Attribute(
"name" );
209 if (name ==
nullptr) {
210 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
214 const char* none_marker = field->Attribute(
"none_marker" );
215 const char* v =
top();
216 if (none_marker !=
nullptr )
219 " %s = PyStatic.NewNone();\n"
226 " %s = new PyFloat( %s );\n",
236 const char* name = field->Attribute(
"name" );
237 if (name ==
nullptr) {
238 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
243 " %s = new PyBool( %s );\n",
254 " %s = PyStatic.NewNone();\n",
264 const char* name = field->Attribute(
"name" );
265 if (name ==
nullptr) {
266 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
270 const char* v =
top();
272 " if (%s != nullptr) {\n"
276 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding an empty buffer.\");\n"
277 " %s = new PyBuffer( 0 );\n"
293 const char* name = field->Attribute(
"name" );
294 if (name ==
nullptr) {
295 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
299 const char* none_marker = field->Attribute(
"none_marker" );
300 const char* v =
top();
301 if (none_marker !=
nullptr )
303 " if (%s == \"%s\" )\n"
304 " %s = PyStatic.NewNone();\n"
311 " %s = new PyString( %s );\n",
321 const char* value = field->Attribute(
"value" );
322 if (value ==
nullptr) {
323 std::cout << std::endl <<
"ClassEncodeGenerator:: String element at line " << field->Row() <<
" has no value attribute, skipping.";
327 const char* v =
top();
329 " %s = new PyString( \"%s\" );\n",
339 const char* name = field->Attribute(
"name" );
340 if (name ==
nullptr) {
341 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
344 const char* none_marker = field->Attribute(
"none_marker" );
345 const char* v =
top();
346 if (none_marker !=
nullptr )
348 " if (%s == \"%s\" )\n"
349 " %s = PyStatic.NewNone();\n"
356 " %s = new PyWString( %s );\n",
366 const char* value = field->Attribute(
"value" );
367 if (value ==
nullptr) {
368 std::cout << std::endl <<
"ClassEncodeGenerator:: WString element at line " << field->Row() <<
" has no value attribute, skipping.";
372 const char* v =
top();
374 " %s = new PyWString( \"%s\", %zu );\n",
375 v, value, strlen( value )
384 const char* name = field->Attribute(
"name" );
385 if (name ==
nullptr) {
386 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
390 bool optional =
false;
391 const char* optional_str = field->Attribute(
"optional");
392 if (optional_str !=
nullptr )
395 const char* v =
top();
398 " if (%s == nullptr)\n"
399 " %s = PyStatic.NewNone();\n"
406 " if (%s == nullptr) {\n"
407 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding a PyNone\");\n"
408 " %s = PyStatic.NewNone();\n"
431 const char* value = field->Attribute(
"value" );
432 if (value ==
nullptr) {
433 std::cout << std::endl <<
"ClassEncodeGenerator:: Token element at line " << field->Row() <<
" has no type attribute, skipping.";
437 const char* v =
top();
439 " %s = new PyToken( \"%s\" );\n",
449 const char* name = field->Attribute(
"name" );
450 if (name ==
nullptr) {
451 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessObject field at line " << field->Row() <<
" is missing the name attribute, skipping.";
455 bool optional =
false;
456 const char* optional_str = field->Attribute(
"optional" );
457 if (optional_str !=
nullptr )
460 const char* v =
top();
463 " if (%s == nullptr)\n"
464 " %s = PyStatic.NewNone();\n"
471 " if (%s == nullptr) {\n"
472 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding a PyNone\");\n"
473 " %s = PyStatic.NewNone();\n"
499 snprintf( tname,
sizeof( tname ),
"obj%u_type", num );
502 snprintf( aname,
sizeof( aname ),
"obj%u_args", num );
505 " PyString* %s(nullptr);\n"
506 " PyRep* %s(nullptr);\n"
518 const char* v =
top();
520 " %s = new PyObject(%s, %s);\n",
530 const char* name = field->Attribute(
"name" );
531 if (name ==
nullptr) {
532 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessObjectEx field at line " << field->Row() <<
" is missing the name attribute, skipping.";
535 const char* type = field->Attribute(
"type" );
536 if (type ==
nullptr) {
537 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessObjectEx field at line " << field->Row() <<
" is missing the type attribute, skipping.";
541 bool optional =
false;
542 const char* optional_str = field->Attribute(
"optional" );
543 if (optional_str !=
nullptr)
546 const char *v =
top();
549 " if (%s == nullptr)\n"
550 " %s = PyStatic.NewNone();\n"
557 " if (%s == nullptr) {\n"
558 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding a PyNone\");\n"
559 " %s = PyStatic.NewNone();\n"
582 const char* name = field->Attribute(
"name" );
583 if (name ==
nullptr) {
584 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessTuple field at line " << field->Row() <<
" is missing the name attribute, skipping.";
588 bool optional =
false;
589 const char* optional_str = field->Attribute(
"optional");
590 if (optional_str !=
nullptr )
593 const char* v =
top();
595 " if (%s == nullptr) {\n"
596 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding an empty tuple.\");\n"
597 " %s = new PyTuple( 0 );\n"
606 " if (%s->empty())\n"
607 " %s = PyStatic.NewNone();\n"
630 const TiXmlNode* i =
nullptr;
633 while( ( i = field->IterateChildren( i ) ) )
635 if (i->Type() == TiXmlNode::TINYXML_ELEMENT )
644 " PyTuple* %s = new PyTuple( %u );\n",
653 snprintf( varname,
sizeof( varname ),
"%s->items[ %u ]", iname, count );
673 const char* name = field->Attribute(
"name" );
674 if (name ==
nullptr) {
675 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessList field at line " << field->Row() <<
" is missing the name attribute, skipping.";
679 bool optional =
false;
680 const char* optional_str = field->Attribute(
"optional" );
681 if (optional_str !=
nullptr )
684 const char* v =
top();
686 " if (%s == nullptr) {\n"
687 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding an empty list.\");\n"
688 " %s = new PyList();\n"
697 " if (%s->empty())\n"
698 " %s = PyStatic.NewNone();\n"
721 const TiXmlNode* i =
nullptr;
724 while( ( i = field->IterateChildren( i ) ) )
726 if (i->Type() == TiXmlNode::TINYXML_ELEMENT )
735 " PyList* %s = new PyList( %u );\n",
744 snprintf( varname,
sizeof( varname ),
"%s->items[ %u ]", iname, count );
763 const char* name = field->Attribute(
"name" );
764 if (name ==
nullptr) {
765 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
773 " PyList* %s = new PyList();\n"
774 " for (auto cur : %s)\n"
775 " %s->AddItemInt(cur);\n"
788 const char* name = field->Attribute(
"name" );
789 if (name ==
nullptr) {
790 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
798 " PyList *%s = new PyList();\n"
799 " for (auto cur : %s)\n"
800 " %s->AddItemLong(cur);\n"
814 const char* name = field->Attribute(
"name" );
815 if (name ==
nullptr) {
816 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
824 " PyList *%s = new PyList();\n"
825 " for (auto cur : %s)\n"
826 " %s->AddItemString(cur.c_str());\n"
840 const char* name = field->Attribute(
"name" );
841 if (name ==
nullptr) {
842 std::cout << std::endl <<
"ClassEncodeGenerator:: field at line " << field->Row() <<
" is missing the name attribute, skipping.";
846 bool optional =
false;
847 const char* optional_str = field->Attribute(
"optional");
848 if (optional_str !=
nullptr )
851 const char* v =
top();
853 " if (%s == nullptr) {\n"
854 " _log(NET__PACKET_WARNING, \"Encode %s: %s is null. Encoding an empty dict.\");\n"
855 " %s = new PyDict();\n"
864 " if (%s->empty())\n"
865 " %s = PyStatic.NewNone();\n"
892 " PyDict* %s = new PyDict();\n",
897 const TiXmlNode* i =
nullptr;
900 while ((i = field->IterateChildren(i))) {
901 if (i->Type() == TiXmlNode::TINYXML_ELEMENT) {
902 const TiXmlElement* ele = i->ToElement();
905 if (strcmp( ele->Value(),
"dictInlineEntry" ) != 0 ) {
906 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictInline non-dictInlineEntry in <dictInline> at line " << field->Row() <<
", ignoring.";
909 const char*
key = ele->Attribute(
"key" );
910 if (key ==
nullptr) {
911 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictInline <dictInlineEntry> at line " << field->Row() <<
" is missing the key attribute, skipping.";
915 bool keyTypeInt =
false, keyTypeLong =
false;
916 const char* keyType = ele->Attribute(
"key_type" );
917 if (keyType !=
nullptr) {
918 keyTypeInt = ( strcmp( keyType,
"int" ) == 0 );
919 keyTypeLong = ( strcmp( keyType,
"long" ) == 0 );
923 snprintf( vname,
sizeof( vname ),
"%s_%u", iname, count );
927 " PyRep* %s(nullptr);\n",
940 " %s->SetItem(new PyInt( %s ), %s);\n"
945 else if (keyTypeLong )
947 " %s->SetItem(new PyLong( %s ), %s);\n"
954 " %s->SetItemString(\"%s\", %s);\n"
974 const char* name = field->Attribute(
"name" );
975 if (name ==
nullptr) {
976 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictRaw field at line " << field->Row() <<
" is missing the name attribute, skipping.";
979 const char*
key = field->Attribute(
"key" );
980 if (key ==
nullptr) {
981 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictRaw field at line " << field->Row() <<
" is missing the key attribute, skipping.";
984 const char* pykey = field->Attribute(
"pykey" );
985 if (pykey ==
nullptr) {
986 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictRaw field at line " << field->Row() <<
" is missing the pykey attribute, skipping.";
989 const char* value = field->Attribute(
"value" );
990 if (value ==
nullptr) {
991 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictRaw field at line " << field->Row() <<
" is missing the value attribute, skipping.";
994 const char* pyvalue = field->Attribute(
"pyvalue" );
995 if (pyvalue ==
nullptr) {
996 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictRaw field at line " << field->Row() <<
" is missing the pyvalue attribute, skipping.";
1004 " PyDict* %s = new PyDict();\n"
1005 " for (auto cur : %s) \n"
1006 " %s->SetItem(new Py%s(cur.first), new Py%s(cur.second));\n"
1011 rname, pykey, pyvalue,
1021 const char* name = field->Attribute(
"name" );
1022 if (name ==
nullptr) {
1023 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictInt field at line " << field->Row() <<
" is missing the name attribute, skipping.";
1031 " PyDict* %s = new PyDict();\n"
1032 " for (auto cur : %s) {\n"
1033 " %s->SetItem(new PyInt(cur.first ), cur.second);\n"
1034 " PyIncRef(cur.second);\n"
1051 const char* name = field->Attribute(
"name" );
1052 if (name ==
nullptr) {
1053 std::cout << std::endl <<
"ClassEncodeGenerator::ProcessDictStr field at line " << field->Row() <<
" is missing the name attribute, skipping.";
1061 " PyDict* %s = new PyDict();\n"
1062 " for (auto cur : %s) {\n"
1063 " %s->SetItemString(cur.first.c_str(), cur.second);\n"
1064 " PyIncRef(cur.second);\n"
1096 " %s = new PySubStream( %s );\n",
1121 " %s = new PySubStruct( %s );\n",
bool ParseElement(const TiXmlElement *element) const
Parses element using registered parsers.
bool ProcessObject(const TiXmlElement *field)
bool ProcessToken(const TiXmlElement *field)
bool ProcessTupleInline(const TiXmlElement *field)
bool ProcessListInt(const TiXmlElement *field)
bool ProcessWStringInline(const TiXmlElement *field)
bool ProcessDictInt(const TiXmlElement *field)
void RegisterProcessors()
bool ProcessElementPtr(const TiXmlElement *field)
bool ProcessRaw(const TiXmlElement *field)
bool ProcessStringInline(const TiXmlElement *field)
bool ProcessSubStructInline(const TiXmlElement *field)
bool ProcessDictInline(const TiXmlElement *field)
bool ProcessListLong(const TiXmlElement *field)
bool ProcessInt(const TiXmlElement *field)
bool ProcessReal(const TiXmlElement *field)
bool ProcessTuple(const TiXmlElement *field)
bool ProcessListInline(const TiXmlElement *field)
bool str2< bool >(const char *str)
Converts string to boolean.
bool ProcessList(const TiXmlElement *field)
bool ProcessTokenInline(const TiXmlElement *field)
bool ProcessObjectInline(const TiXmlElement *field)
bool ProcessListStr(const TiXmlElement *field)
bool ProcessString(const TiXmlElement *field)
bool ProcessDictStr(const TiXmlElement *field)
static const char * GetEncodeType(const TiXmlElement *element)
Obtains encode type of given element.
int main(int argc, char *argv[])
ClassEncodeGenerator(FILE *outputFile=NULL)
Generic class for eve-xmlpktgen's generators.
bool ProcessLong(const TiXmlElement *field)
bool ProcessDictRaw(const TiXmlElement *field)
bool ParseElementChildren(const TiXmlElement *element, size_t max=0) const
Parses element's children using registered parsers.
bool ProcessWString(const TiXmlElement *field)
bool ProcessElement(const TiXmlElement *field)
bool ProcessElementDef(const TiXmlElement *field)
bool ProcessNone(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 ProcessSubStreamInline(const TiXmlElement *field)
bool ProcessObjectEx(const TiXmlElement *field)
bool ProcessBool(const TiXmlElement *field)
bool ProcessDict(const TiXmlElement *field)
bool ProcessBuffer(const TiXmlElement *field)