Torque3D Documentation / _generateds / consoleXMLExport.cpp

consoleXMLExport.cpp

Engine/source/console/consoleXMLExport.cpp

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "console/consoleInternal.h"
 25#include "console/engineAPI.h"
 26#include "console/consoleObject.h"
 27#include "console/SimXMLDocument.h"
 28
 29#include "console/consoleXMLExport.h"
 30
 31
 32#if 0
 33
 34namespace Con {
 35
 36   XMLExport::XMLExport()
 37   {
 38      mXML = NULL;
 39   }
 40
 41   XMLExport::~XMLExport()
 42   {
 43   }
 44
 45   void XMLExport::exportBaseTypes()
 46   {
 47      mXML->pushNewElement("BaseTypes");
 48
 49      ConsoleBaseType::getListHead();
 50      while( walk != NULL )
 51      {
 52         mXML->pushNewElement("BaseType");
 53
 54         mXML->getTypeName());
 55         mXML->getTypeID()));
 56         mXML->getTypeSize()));
 57         mXML->getDocString() : "" );
 58
 59         mXML->popElement(); // Basetype
 60
 61         walk = walk->getListNext();
 62      }
 63
 64      mXML->popElement(); // Basetypes
 65
 66   }
 67
 68   void XMLExport::exportEntryTypes()
 69   {
 70
 71      const char *typeNames [] = { 
 72         "ScriptCallbackType", "GroupMarker", "OverloadMarker", "InvalidFunctionType",
 73         "ConsoleFunctionType", "StringCallbackType", "IntCallbackType", "FloatCallbackType",
 74         "VoidCallbackType", "BoolCallbackType"
 75      };
 76
 77      S32 typeIds [] =  {
 78         Namespace::Entry::InvalidFunctionType,
 79         Namespace::Entry::FloatCallbackType,
 80         Namespace::Entry::BoolCallbackType
 81      };
 82
 83      mXML->pushNewElement("EntryTypes");
 84
 85      S32);
 86
 87      for (i++)
 88      {
 89         mXML->pushNewElement("EntryType");
 90         mXML->i]);
 91         mXML->i]));
 92         mXML->popElement();
 93      }
 94
 95      mXML->popElement(); // EntryTypes
 96   }
 97
 98   void XMLExport::exportNamespaces()
 99   {
100
101      // keep track of which enumTables are in use
102      Vector < const EnumTable*> enumTables;
103
104      mXML->pushNewElement("Namespaces");
105
106      for (Namespace::mNamespaceList; walk; walk = walk->mNext)
107      {
108
109         if ( walk->mName && !walk->isClass() )
110            continue;
111
112         const char *name = walk->mName ? walk->mName : "";
113
114         mXML->pushNewElement("Namespace");
115         mXML->setAttribute("name", name);
116
117         Namespace *p = walk->mParent;
118
119         mXML->pushNewElement("Parents");
120
121         while (p)
122         {
123            if (p->mName == walk->mName)
124            {
125               p = p->mParent;
126               continue;
127            }
128
129            const char* pname = p->mName : "";
130
131            mXML->pushNewElement("Parent");
132            mXML->setAttribute("name", pname);
133            mXML->popElement(); // Parent
134
135            p = p->mParent;
136         }
137
138         mXML->popElement(); // Parents
139
140         // Entries (Engine/Script Methods/Functions)
141
142         mXML->pushNewElement("Entries");
143
144         Namespace::Entry *entry;
145         VectorPtr<Namespace::Entry *> vec;
146
147         walk->getEntryList(&vec);
148
149         for( end(); compItr++ )
150         {
151
152            entry = *compItr;
153
154            if (entry->mNamespace != walk)
155               continue;
156
157            if (entry->mName != walk->mName)
158               continue;
159
160            mXML->pushNewElement("Entry");
161
162            //consistently name functions
163            char functionName[512];
164            mFunctionName);
165            functionName[0] = dTolower(functionName[0]);
166
167            mMinArgs;
168            mMaxArgs;
169
170            if (maxArgs < minArgs)
171               maxArgs = minArgs;
172
173            mXML->setAttribute("name", functionName);
174            mXML->avar("%i", minArgs));
175            mXML->avar("%i", maxArgs));
176
177            const char* usage = "";
178            if (entry->mUsage[0])
179               usage = entry->mUsage;
180            mXML->setAttribute("usage", usage);
181            mXML->mPackage : "");
182            mXML->mType));
183
184            mXML->popElement(); // Entry
185
186         }
187
188         mXML->popElement(); // Entries
189
190         // Fields
191
192         mXML->pushNewElement("Fields");
193
194         AbstractClassRep *rep = walk->mClassRep;
195         Vector<U32> classFields;
196
197         if (rep)
198         {
199            getParentClass();
200
201            const mFieldList;
202
203            for(i++)
204            {
205               if (parentRep)
206               {
207                  if (parentRep->i].pFieldname))
208                     continue;
209
210               }
211               classFields.i);
212            }
213
214            for(i++)
215            {
216               i];
217
218               char fieldName[256];
219
220               dSprintf(fieldName, 256, flist[index].pFieldname);
221
222               //consistently name fields
223               fieldName[0] = dToupper(fieldName[0]);
224
225               mXML->pushNewElement("Field");
226
227               mXML->setAttribute("name", fieldName);
228               mXML->avar("%i", flist[index].type));
229
230// RD: temporarily deactivated; TypeEnum is no more; need to sync this up
231//               if (flist[index].type == TypeEnum  && flist[index].table && dStrlen(flist[index].table->name))
232//               {
233//                  if (!enumTables.contains(flist[index].table))
234//                     enumTables.push_back(flist[index].table);
235//
236//                  mXML->setAttribute("enumTable", flist[index].table->name);
237//
238//               }
239
240               const char* pFieldDocs = "";
241               if (flist[index].pFieldDocs && flist[index].pFieldDocs[0])
242                  pFieldDocs = flist[index].pFieldDocs;
243
244               mXML->setAttribute("docs", pFieldDocs);
245               mXML->avar("%i", flist[index].elementCount));
246
247               mXML->popElement(); // Field
248            }
249         }
250
251         mXML->popElement(); // Fields
252         mXML->popElement(); // Namespace
253      }
254
255      mXML->popElement(); // Namespaces
256
257      mXML->pushNewElement("EnumTables");
258
259      // write out the used EnumTables
260      for (i++)
261      {
262         mXML->pushNewElement("EnumTable");
263
264         const i];
265
266         mXML->setAttribute("name", table->name);
267         mXML->avar("%i", table->firstFlag));
268         mXML->avar("%i", table->mask));
269
270         mXML->pushNewElement("Enums");
271
272         for (S32 j = 0; j < table->size; j++)
273         {
274            mXML->pushNewElement("Enum");
275
276            mXML->setAttribute("name", table->table[j].label);
277            mXML->avar("%i", table->table[j].index));
278
279            mXML->popElement(); // Enum
280
281         }
282
283         mXML->popElement(); //Enums
284
285         mXML->popElement(); // EnumTable
286      }
287
288      mXML->popElement(); // EnumTables
289      
290   }
291
292   void String& str)
293   {
294      mXML = new SimXMLDocument();
295      mXML->registerObject();
296
297      mXML->addHeader();
298
299      mXML->pushNewElement("ConsoleXML");
300
301      exportBaseTypes();
302      exportEntryTypes();
303      exportNamespaces();
304
305      mXML->popElement(); // TorqueConsole
306
307      mXML->saveToString(str);
308
309      // If you're having trouble with the generated XML, you can dump to a file and inspect
310      // mXML->saveFile("ConsoleExport.xml");
311
312      mXML->deleteObject();
313   }
314
315}; // namespace Con
316
317
318DefineEngineFunction( consoleExportXML, const char*, (), ,"Exports console definition XML representation" )
319{
320   Con::XMLExport xmlExport;
321   String xml;
322   xmlExport.exportXML(xml);
323   char* ret = size());
324   size());
325   return ret;
326}
327
328#endif
329