source: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp @ 1022

Revision 1022, 19.8 KB checked in by mattausch, 18 years ago (diff)
RevLine 
[508]1// ---------------------------------------------------------------------------
2//  Includes for all the program files to see
3// ---------------------------------------------------------------------------
4#include <string.h>
5#include <stdlib.h>
6#include <iostream>
7using namespace std;
8#include <xercesc/util/PlatformUtils.hpp>
9
10// ---------------------------------------------------------------------------
11//  Includes
12// ---------------------------------------------------------------------------
13#include <xercesc/framework/StdInInputSource.hpp>
14#include <xercesc/parsers/SAXParser.hpp>
15#include <xercesc/util/OutOfMemoryException.hpp>
16
17// ---------------------------------------------------------------------------
18//  Includes
19// ---------------------------------------------------------------------------
20#include <xercesc/sax/AttributeList.hpp>
21#include <xercesc/sax/SAXParseException.hpp>
22#include <xercesc/sax/SAXException.hpp>
23
24#include "ViewCellsParser.h"
25
26#include "ViewCellsParserXerces.h"
27#include "Mesh.h"
28#include "VspBspTree.h"
29#include "ViewCellBsp.h"
30#include "ViewCellsManager.h"
[971]31#include "GzFileInputSource.h"
[1022]32#include "VspOspTree.h"
[508]33
[1022]34
[863]35namespace GtpVisibilityPreprocessor {
[860]36
37
[508]38// ---------------------------------------------------------------------------
39//  Local data
40//
41//  doNamespaces
42//      Indicates whether namespace processing should be enabled or not.
43//      The default is no, but -n overrides that.
44//
45//  doSchema
46//      Indicates whether schema processing should be enabled or not.
47//      The default is no, but -s overrides that.
48//
49//  schemaFullChecking
50//      Indicates whether full schema constraint checking should be enabled or not.
51//      The default is no, but -s overrides that.
52//
53//  valScheme
54//      Indicates what validation scheme to use. It defaults to 'auto', but
55//      can be set via the -v= command.
56// ---------------------------------------------------------------------------
57static bool     doNamespaces       = false;
58static bool     doSchema           = false;
59static bool     schemaFullChecking = false;
60static SAXParser::ValSchemes    valScheme       = SAXParser::Val_Auto;
61
62
63
64
65
66// ---------------------------------------------------------------------------
67//  StdInParseHandlers: Constructors and Destructor
68// ---------------------------------------------------------------------------
[938]69ViewCellsParseHandlers::ViewCellsParseHandlers(ObjectContainer *objects,
[1004]70                                                                                           BoundingBoxConverter *bconverter):
[508]71  mElementCount(0)
72  , mAttrCount(0)
73  , mCharacterCount(0)
74  , mSpaceCount(0)
[577]75  , mViewCellsManager(NULL)
76  , mVspBspTree(NULL)
77  , mBspTree(NULL)
[651]78  , mViewCellsTree(NULL)
79  , mParseViewCells(true)
80  , mCurrentViewCell(NULL)
81  , mCurrentBspNode(NULL)
[931]82  , mObjects(objects)
83  , mBoundingBoxConverter(bconverter)
[975]84{
[508]85}
86
[575]87
[508]88ViewCellsParseHandlers::~ViewCellsParseHandlers()
89{
90}
91
92
93// ---------------------------------------------------------------------------
94//  StdInParseHandlers: Implementation of the SAX DocumentHandler interface
95// ---------------------------------------------------------------------------
96
97
98void ViewCellsParseHandlers::endElement(const XMLCh* const name)
99{
100  StrX lname(name);
101  string element(lname.LocalForm());
[651]102
[508]103  if (element == "ViewCells")
104          EndViewCells();
[651]105
[938]106  if (element == "BoundingBoxes")
107          EndBoundingBoxes();
108
109  // inside the view cell description
[651]110  if (mParseViewCells)
111  {
112          if (element == "Interior")
113                  EndViewCellInterior();
114  }
115  else
116  {
[975]117          if (element == "Interior")
[651]118                  EndBspInterior();
119  }
[508]120}
121
122
[575]123void ViewCellsParseHandlers::EndBspInterior()
[508]124{
125        // go one up in the tree
[590]126        if (mCurrentBspNode->GetParent())
[975]127        {       Debug << "]";
[590]128                mCurrentBspNode = mCurrentBspNode->GetParent();
[508]129        }
130}
131
132
[651]133void ViewCellsParseHandlers::EndViewCellInterior()
134{
135        // go one up in the tree
136        if (mCurrentViewCell->GetParent())
[971]137        {       Debug << "]";
[651]138                mCurrentViewCell = mCurrentViewCell->GetParent();
139        }
140}
141
[931]142
[863]143inline static bool vlt(ViewCell *v1, ViewCell *v2)
[508]144{
145        return v1->mId < v2->mId;
146}
147
148
149void ViewCellsParseHandlers::EndViewCells()
150{
[575]151        // sort view cells to help associating view cells according to their id
[508]152        stable_sort(mViewCells.begin(), mViewCells.end(), vlt);
[975]153        mParseViewCells = false;
[508]154}
155
156
[931]157void ViewCellsParseHandlers::EndBoundingBoxes()
158{
[938]159        // all bounding boxes gathered in this step =>
160        // associate object ids with bounding boxes
[944]161        long startTime = GetTime();
162       
[931]163        if (mBoundingBoxConverter)
164                mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, *mObjects);
[944]165
[975]166        Debug << "\nconverted bounding boxes to objects in "
[944]167                  << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
[931]168}
[575]169
[931]170
[575]171void ViewCellsParseHandlers::StartHierarchy(AttributeList&  attributes)
[508]172{
[575]173        int len = attributes.getLength();
174 
175        for (int i = 0; i < len; ++ i)
176        {
177                string attrName(StrX(attributes.getName(i)).LocalForm());
178               
179                if (attrName == "name")
180                {
181                        StrX attrValue(attributes.getValue(i));
182                       
183                        const char *ptr = attrValue.LocalForm();
184                       
[870]185                        //-- the view cells manager is created here
[575]186                        CreateViewCellsManager(ptr);
187                }
188        }
189}
190
191
192void ViewCellsParseHandlers::startBspElement(string element,
193                                                                                         AttributeList& attributes)
194{
[508]195        if (element == "Interior")
196        {
[971]197                Debug << "[";
[575]198                StartBspInterior(attributes);
[508]199        }
200
201        if (element == "Leaf")
202        {
[971]203                Debug << "l";
[575]204                StartBspLeaf(attributes);
[508]205        }
[575]206}
[508]207
[575]208
209void ViewCellsParseHandlers::startElement(const XMLCh* const name,
210                                                                                  AttributeList& attributes)
[975]211{
[575]212        StrX lname(name);
213        string element(lname.LocalForm());
[971]214
[975]215
[651]216        if (element == "ViewCells")
217        {
[971]218                Debug << "parsing view cells" << endl;
[651]219                mParseViewCells = true;
220        }
221
[975]222        // decides about the view cell hierarchy
223        if (element == "HierarchyType")
224        //if (element == "Hierarchy")
[575]225        {
[975]226                //Debug << "parsing spatial hierarchy" << endl;
227                //mParseViewCells = false;
[575]228                StartHierarchy(attributes);
229        }
[577]230       
231        // decides the used view cell hierarchy
232        if (element == "ViewSpaceBox")
233        {
[971]234                Debug << "v";
[577]235                StartViewSpaceBox(attributes);
236        }
[575]237
[931]238        // decides the used view cell hierarchy
239        if (element == "BoundingBox")
240        {
[971]241                Debug << "b";
[931]242                StartBoundingBox(attributes);
243        }
[577]244
[975]245       
[651]246        if (!mParseViewCells)
[577]247        {
[975]248                //-- use different methods for the given view cell hierarchy types
[651]249                if (mViewCellsManager)
[577]250                {
[651]251                        switch (mViewCellsManager->GetType())
252                        {
253                        case ViewCellsManager::BSP:
254                        case ViewCellsManager::VSP_BSP:
255                                startBspElement(element, attributes);
256                                break;
[575]257       
[651]258                        default:
259                                Debug << "not implemented" << endl;
260                                break;
261                        }
[577]262                }
263        }
[651]264        else
265        {
[975]266                // interiors + leaves interpreted view cells else
[651]267                if (element == "Interior")
268                {
[971]269                        Debug << "[";
[651]270                        StartViewCellInterior(attributes);
271                }
[575]272
[651]273                if (element == "Leaf")
274                {
[971]275                        Debug << "l";
[651]276                        StartViewCellLeaf(attributes);
277                }
278        }
279
[508]280        ++ mElementCount;
281        mAttrCount += attributes.getLength();
282}
283
284
285inline bool ilt(Intersectable *obj1, Intersectable *obj2)
286{
287        return obj1->mId < obj2->mId;
288}
289
290
[651]291void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, AttributeList&  attributes)
[508]292{
293        int len = attributes.getLength();
294        vector<int> objIndices;
[590]295
[508]296        for (int i = 0; i < len; ++ i)
297        {
298                string attrName(StrX(attributes.getName(i)).LocalForm());
299               
300                if (attrName == "pvs")
301                {
302                        StrX attrValue(attributes.getValue(i));
303                       
304                        // handle coordIndex
305                        objIndices.clear();
306                        const char *ptr = attrValue.LocalForm();
307                        char *endptr;
308                       
309                        while (1)
310                        {
311                                int index = strtol(ptr, &endptr, 10);
312
313                                if (ptr == endptr)
314                                        break;
315
316                                objIndices.push_back(index);
317
318                                ptr = endptr;
319                        }
320
321                        //TODO: find objects and add them to pvs
322                        // TODO: get view cell with specified id
323                        MeshInstance dummyInst(NULL);
324
325                        vector<int>::const_iterator it, it_end = objIndices.end();
326                        for (it = objIndices.begin(); it != it_end; ++ it)
327                        {
328                                const int objId = *it; 
329                                dummyInst.SetId(objId);
330
331                                ObjectContainer::iterator oit =
[863]332                                  lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt);
[556]333                               
[880]334                                                       
335                                if ((oit != mObjects->end()) && ((*oit)->GetId() == objId))
[508]336                                {
[880]337                                        // $$JB we should store a float a per object which corresponds
338                                        // to sumof pdfs, i.e. its relative visibility
339                                        // temporarily set to 1.0f
340                                        viewCell->GetPvs().AddSample(*oit, 1.0f);                               
[508]341                                }
342                                else
343                                {
[880]344                                        Debug << "error: object with id " << objId << " does not exist" << endl;
[508]345                                }
346                        }
347                }
348                else if (attrName == "id")
349                {
350                        StrX attrValue(attributes.getValue(i));
351                       
352                        const char *ptr = attrValue.LocalForm();
353                        char *endptr = NULL;
354                        const int id = strtol(ptr, &endptr, 10);
355
356                        viewCell->SetId(id);
357                }
[881]358                /*else if (attrName == "active")
[651]359                {
360                        StrX attrValue(attributes.getValue(i));
361                       
362                        const char *ptr = attrValue.LocalForm();
363                        char *endptr = NULL;
364                        const bool isActive = (bool)strtol(ptr, &endptr, 10);
365
[660]366                        if (isActive)
367                                viewCell->SetActive();
[881]368                }*/
[651]369                else if (attrName == "mergecost")
370                {
371                        StrX attrValue(attributes.getValue(i));
372                       
373                        const char *ptr = attrValue.LocalForm();
374                        char *endptr = NULL;
375                        const float cost = (float)strtod(ptr, &endptr);
376
377                        viewCell->SetMergeCost(cost);
378                }
[508]379        }
380}
381
382
[577]383void ViewCellsParseHandlers::StartViewSpaceBox(AttributeList& attributes)
384{
385        int len = attributes.getLength();
386
387        Vector3 bmin, bmax;
388
389        for (int i = 0; i < len; ++ i)
390        {
391                string attrName(StrX(attributes.getName(i)).LocalForm());
392                StrX attrValue(attributes.getValue(i));
393                const char *ptr = attrValue.LocalForm();
394
395                if (attrName == "min")
396                {
397                        sscanf(ptr, "%f %f %f",
398                                   &bmin.x, &bmin.y, &bmin.z);
399                }
400                else if (attrName == "max")
401                {
402                        sscanf(ptr, "%f %f %f",
403                                   &bmax.x, &bmax.y, &bmax.z);
404                }
405        }
406
407        mViewSpaceBox = AxisAlignedBox3(bmin, bmax);
408
[944]409        Debug << "\nview space box: " << mViewSpaceBox << endl;
[577]410}
411
412
[931]413void ViewCellsParseHandlers::StartBoundingBox(AttributeList& attributes)
414{
415        int len = attributes.getLength();
416
417        Vector3 bmin, bmax;
418        int id;
419
420        for (int i = 0; i < len; ++ i)
421        {
422                string attrName(StrX(attributes.getName(i)).LocalForm());
423                StrX attrValue(attributes.getValue(i));
424                const char *ptr = attrValue.LocalForm();
425
426
427                if (attrName == "id")
428                {
429                        sscanf(ptr, "%d", &id);
430                }
431
432                if (attrName == "min")
433                {
434                        sscanf(ptr, "%f %f %f",
435                                   &bmin.x, &bmin.y, &bmin.z);
436                }
437                else if (attrName == "max")
438                {
439                        sscanf(ptr, "%f %f %f",
440                                   &bmax.x, &bmax.y, &bmax.z);
441                }
442        }
443
444        AxisAlignedBox3 box(bmin, bmax);
445        mIBoundingBoxes.push_back(IndexedBoundingBox(id, box));
446
[944]447        //Debug << "bbox: " << box << endl;
[931]448}
449
450
[575]451void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes)
[508]452{
453        BspLeaf * leaf =
[590]454                new BspLeaf(dynamic_cast<BspInterior *>(mCurrentBspNode), NULL);
[508]455
[590]456        if (mCurrentBspNode) // replace front or (if not NULL) back child
[508]457        {
[590]458                dynamic_cast<BspInterior *>(mCurrentBspNode)->ReplaceChildLink(NULL, leaf);
[508]459        }
460        else
461        {
[575]462                if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
[577]463                {
[575]464                        mBspTree->mRoot = leaf;
[577]465                }
466                else if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP)
467                {
[575]468                        mVspBspTree->mRoot = leaf;
[577]469                }
[508]470        }
471
472        //-- find associated view cell
473        int viewCellId;
474       
475        int len = attributes.getLength();
476         
477        for (int i = 0; i < len; ++ i)
478        {
479                string attrName(StrX(attributes.getName(i)).LocalForm());
480                StrX attrValue(attributes.getValue(i));
481
482                const char *ptr = attrValue.LocalForm();
483                char *endptr = NULL;
484
485                if (attrName == "viewCellId")
486                {
487                        viewCellId = strtol(ptr, &endptr, 10);
488                }
489        }
[654]490
[590]491       
[508]492        if (viewCellId >= 0) // valid view cell
493        {
494                // TODO: get view cell with specified id
[590]495                ViewCellInterior dummyVc;
[508]496                dummyVc.SetId(viewCellId);
497
498                ViewCellContainer::iterator vit =
499                        lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
500                       
[651]501                BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit);
[580]502
[654]503       
[508]504                if (viewCell->GetId() == viewCellId)
505                {
[651]506                        leaf->SetViewCell(viewCell);
507                        viewCell->mLeaf = leaf;
[508]508                }
509                else
510                {
511                        Debug << "error: view cell does not exist" << endl;
512                }
513        }
514        else
515        {
[863]516                // add to invalid view space
[575]517                if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP)
518                {
519                        leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell());
520                        leaf->SetTreeValid(false);
521                        mVspBspTree->PropagateUpValidity(leaf);
522                }
[654]523        }
[508]524}
525
526
[575]527void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes)
[508]528{
529        Plane3 plane;
530        int len = attributes.getLength();
531
532        for (int i = 0; i < len; ++ i)
533        {
534                string attrName(StrX(attributes.getName(i)).LocalForm());
535                StrX attrValue(attributes.getValue(i));
536                const char *ptr = attrValue.LocalForm();
537
538                if (attrName == "plane")
539                {
540                        sscanf(ptr, "%f %f %f %f",
541                                   &plane.mNormal.x, &plane.mNormal.y, &plane.mNormal.z, &plane.mD);
542                }
543        }
544
545        BspInterior* interior = new BspInterior(plane);
546       
[590]547        if (mCurrentBspNode) // replace NULL child of parent with current node
[508]548        {
[590]549                BspInterior *current = dynamic_cast<BspInterior *>(mCurrentBspNode);
[508]550
551                current->ReplaceChildLink(NULL, interior);
552                interior->SetParent(current);
553        }
554        else
555        {
[575]556                if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
[577]557                {
[575]558                        mBspTree->mRoot = interior;
[577]559                }
[575]560                else
[577]561                {
[575]562                        mVspBspTree->mRoot = interior;
[577]563                }
[508]564        }
565
[590]566        mCurrentBspNode = interior;
[508]567}
568
569
[651]570void ViewCellsParseHandlers::StartViewCellLeaf(AttributeList& attributes)
571{
572        BspViewCell *viewCell = new BspViewCell();
[575]573
[651]574        if (mCurrentViewCell) // replace front or (if not NULL) back child
575        {
576                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mCurrentViewCell);
577                interior->SetupChildLink(viewCell);
578        }
579        else // root
580        {
581                mViewCellsTree->SetRoot(viewCell);
582        }
583
584        StartViewCell(viewCell, attributes);
585
586        // collect leaves
587        mViewCells.push_back(viewCell);
588}
589
590
591void ViewCellsParseHandlers::StartViewCellInterior(AttributeList& attributes)
592{
593        ViewCellInterior* interior = new ViewCellInterior();
594       
595        if (mCurrentViewCell) // replace NULL child of parent with current node
596        {
597                ViewCellInterior *current = dynamic_cast<ViewCellInterior *>(mCurrentViewCell);
598
599                current->SetupChildLink(interior);
600        }
601        else
602        {
603                mViewCellsTree->SetRoot(interior);
604        }
605
606        mCurrentViewCell = interior;
607
608        StartViewCell(interior, attributes);
609}
610
611
612
[575]613void ViewCellsParseHandlers::CreateViewCellsManager(const char *name)
614{
615        if (strcmp(name, "bspTree") == 0)
616        {
617                Debug << "view cell type: Bsp" << endl;
618
[577]619                mBspTree = new BspTree();
[590]620                mBspTree->mBox = mViewSpaceBox;
[651]621                //mCurrentBspNode = mBspTree->GetRoot();
[575]622
[1004]623                mViewCellsManager = new BspViewCellsManager(mBspTree);
[575]624        }
[1022]625        else if (strcmp(name, "vspBspTree") == 0) //
[975]626        {
[577]627                Debug << "view cell type: VspBsp" << endl;
628
[575]629                mVspBspTree = new VspBspTree();
[651]630                //mCurrentBspNode = mVspBspTree->GetRoot();
[1004]631                mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
[577]632
[590]633                mVspBspTree->mBox = mViewSpaceBox;
[575]634        }
[1022]635        else if (strcmp(name, "vspOspTree") == 0)
636        {
637                Debug << "view cell type: VspOsp" << endl;
[577]638
[1022]639                mVspTree = new VspTree();
640                mOspTree = new OspTree();
641
642                //mCurrentBspNode = mVspBspTree->GetRoot();
643                mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree);
644
645                mVspTree->mBoundingBox = mViewSpaceBox;
646        }
647
648
[651]649        mViewCellsTree = mViewCellsManager->GetViewCellsTree();
[577]650        mViewCellsManager->SetViewSpaceBox(mViewSpaceBox);
[575]651}
652
653
[508]654void ViewCellsParseHandlers::characters(const XMLCh* const chars,
655                                                                                const unsigned int length)
656{
657        mCharacterCount += length;
658}
659
660
661void ViewCellsParseHandlers::ignorableWhitespace(const XMLCh* const chars,
662                                                                                                 const unsigned int length)
663{
664        mSpaceCount += length;
665}
666
667
668void ViewCellsParseHandlers::resetDocument()
669{
670        mAttrCount = 0;
671        mCharacterCount = 0;
672        mElementCount = 0;
673        mSpaceCount = 0;
674}
675
676
677// ---------------------------------------------------------------------------
678//  StdInParseHandlers: Overrides of the SAX ErrorHandler interface
679// ---------------------------------------------------------------------------
680void
681ViewCellsParseHandlers::error(const SAXParseException& e)
682{
683  XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId())
684                            << ", line " << e.getLineNumber()
685                            << ", char " << e.getColumnNumber()
686                            << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
687}
688
689void
690ViewCellsParseHandlers::fatalError(const SAXParseException& e)
691{
692  XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId())
693                            << ", line " << e.getLineNumber()
694                            << ", char " << e.getColumnNumber()
695                            << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
696}
697
698void
699ViewCellsParseHandlers::warning(const SAXParseException& e)
700{
701  XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId())
702                            << ", line " << e.getLineNumber()
703                            << ", char " << e.getColumnNumber()
704                            << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
705}
706
707
708bool ViewCellsParser::ParseFile(const string filename,
[575]709                                                                ViewCellsManager **viewCells,
[931]710                                                                ObjectContainer *objects,
[1004]711                                                                BoundingBoxConverter *bconverter)
[508]712{
713  // Initialize the XML4C system
714  try {
715    XMLPlatformUtils::Initialize();
716  }
717 
718  catch (const XMLException& toCatch)
719    {
720      XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
721                                << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
722      return false;
723    }
724 
725  //
726  //  Create a SAX parser object. Then, according to what we were told on
727  //  the command line, set the options.
728  //
729  SAXParser* parser = new SAXParser;
730  parser->setValidationScheme(valScheme);
731  parser->setDoNamespaces(doNamespaces);
732  parser->setDoSchema(doSchema);
733  parser->setValidationSchemaFullChecking(schemaFullChecking);
734 
735
736  //
737  //  Create our SAX handler object and install it on the parser, as the
738  //  document and error handler. We are responsible for cleaning them
739  //  up, but since its just stack based here, there's nothing special
740  //  to do.
741  //
[1004]742  ViewCellsParseHandlers handler(objects, bconverter);
[508]743  parser->setDocumentHandler(&handler);
744  parser->setErrorHandler(&handler);
745 
746  unsigned long duration;
747  int errorCount = 0;
748  // create a faux scope so that 'src' destructor is called before
749  // XMLPlatformUtils::Terminate
750  {
751    //
752    //  Kick off the parse and catch any exceptions. Create a standard
753    //  input input source and tell the parser to parse from that.
754    //
755    //    StdInInputSource src;
756    try
757      {
758        const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
[971]759#if ZIPPED_VIEWCELLS
760        XMLCh *myFilePath = XMLString::transcode(filename.c_str());
761       
762        GzFileInputSource isource(myFilePath);
763        parser->parse(isource);
764
765#else
[508]766        parser->parse(filename.c_str());
[971]767#endif
768
[508]769        const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
770        duration = endMillis - startMillis;
771        errorCount = parser->getErrorCount();
772      }
773    catch (const OutOfMemoryException&)
774      {
775        XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
776        errorCount = 2;
777        return false;
778      }
779    catch (const XMLException& e)
780      {
[870]781                        XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n"
[508]782                                  << StrX(e.getMessage())
783                                  << "\n" << XERCES_STD_QUALIFIER endl;
[870]784                        errorCount = 1;
785                        return false;
[508]786      }
787
788   
789    // Print out the stats that we collected and time taken
790    if (!errorCount) {
[870]791                XERCES_STD_QUALIFIER cerr << filename << ": " << duration << " ms ("
[508]792                                << handler.GetElementCount() << " elems, "
793                                << handler.GetAttrCount() << " attrs, "
794                                << handler.GetSpaceCount() << " spaces, "
795                                << handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
796    }
797  }
798 
799  //
800  //  Delete the parser itself.  Must be done prior to calling Terminate, below.
801  //
802  delete parser;
803 
804  XMLPlatformUtils::Terminate();
805 
[931]806  //-- assign new view cells manager
[577]807  *viewCells = handler.mViewCellsManager;
[651]808 
[508]809  if (errorCount > 0)
810    return false;
811  else
812    return true;
[556]813}
[860]814
815}
Note: See TracBrowser for help on using the repository browser.