// --------------------------------------------------------------------------- // Includes for all the program files to see // --------------------------------------------------------------------------- #include #include #include using namespace std; #include // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- #include #include #include // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- #include #include #include #include "ViewCellsParser.h" #include "ViewCellsParserXerces.h" #include "Mesh.h" #include "VspBspTree.h" #include "ViewCellBsp.h" #include "ViewCellsManager.h" #include "GzFileInputSource.h" #include "OspTree.h" #include "VspTree.h" #include "KdTree.h" #include "BvHierarchy.h" #include "HierarchyManager.h" namespace GtpVisibilityPreprocessor { // --------------------------------------------------------------------------- // Local data // // doNamespaces // Indicates whether namespace processing should be enabled or not. // The default is no, but -n overrides that. // // doSchema // Indicates whether schema processing should be enabled or not. // The default is no, but -s overrides that. // // schemaFullChecking // Indicates whether full schema constraint checking should be enabled or not. // The default is no, but -s overrides that. // // valScheme // Indicates what validation scheme to use. It defaults to 'auto', but // can be set via the -v= command. // --------------------------------------------------------------------------- static bool doNamespaces = false; static bool doSchema = false; static bool schemaFullChecking = false; static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto; inline static bool ilt(Intersectable *obj1, Intersectable *obj2) { return obj1->mId < obj2->mId; } // --------------------------------------------------------------------------- // StdInParseHandlers: Constructors and Destructor // --------------------------------------------------------------------------- ViewCellsParseHandlers::ViewCellsParseHandlers(ObjectContainer *objects, BoundingBoxConverter *bconverter): mElementCount(0) , mAttrCount(0) , mCharacterCount(0) , mSpaceCount(0) , mViewCellsManager(NULL) , mVspBspTree(NULL) , mBspTree(NULL) , mViewCellsTree(NULL) , mCurrentState(PARSE_OPTIONS) , mCurrentViewCell(NULL) , mCurrentBspNode(NULL) , mCurrentVspNode(NULL) , mCurrentKdNode(NULL) , mObjects(objects) , mBoundingBoxConverter(bconverter) , mHierarchyManager(NULL) { std::stable_sort(mObjects->begin(), mObjects->end(), ilt); } ViewCellsParseHandlers::~ViewCellsParseHandlers() { } // --------------------------------------------------------------------------- // StdInParseHandlers: Implementation of the SAX DocumentHandler interface // --------------------------------------------------------------------------- void ViewCellsParseHandlers::endElement(const XMLCh* const name) { StrX lname(name); string element(lname.LocalForm()); if (element == "BoundingBoxes") EndBoundingBoxes(); if (element == "ViewCells") EndViewCells(); // inside the view cell description if (mCurrentState == PARSE_VIEWCELLS) { if (element == "Interior") EndViewCellInterior(); } else { if (element == "Interior") EndBspInterior(); } // finished, create view cells manager if (element == "VisibilitySolution") CreateViewCellsManager(); } void ViewCellsParseHandlers::EndBspInterior() { // go one up in the tree if (mCurrentBspNode->GetParent()) { cout << "]"; mCurrentBspNode = mCurrentBspNode->GetParent(); } } void ViewCellsParseHandlers::EndVspInterior() { // go one up in the tree if (mCurrentVspNode->GetParent()) { cout << "]"; mCurrentVspNode = mCurrentVspNode->GetParent(); } } void ViewCellsParseHandlers::EndViewCellInterior() { // go one up in the tree if (mCurrentViewCell->GetParent()) { cout << "]"; mCurrentViewCell = mCurrentViewCell->GetParent(); } } inline static bool vlt(ViewCell *v1, ViewCell *v2) { return v1->mId < v2->mId; } void ViewCellsParseHandlers::EndViewCells() { // sort view cells to help associating view cells according to their id stable_sort(mViewCells.begin(), mViewCells.end(), vlt); // not parsing view cells anymore mCurrentState = PARSE_OPTIONS; } void ViewCellsParseHandlers::EndBoundingBoxes() { // all bounding boxes gathered in this step => // associate object ids with bounding boxes long startTime = GetTime(); if (mBoundingBoxConverter) mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, *mObjects); Debug << "\nconverted bounding boxes to objects in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; } void ViewCellsParseHandlers::StartHierarchy(AttributeList& attributes) { int len = attributes.getLength(); for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); if (attrName == "name") { StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); // the view cells manager is created here //CreateViewCellsManager(ptr); } } } void ViewCellsParseHandlers::StartBspElement(string element, AttributeList& attributes) { if (element == "Interior") { cout << "["; StartBspInterior(attributes); } if (element == "Leaf") { cout << "l"; StartBspLeaf(attributes); } } void ViewCellsParseHandlers::StartVspElement(string element, AttributeList& attributes) { if (element == "Interior") { cout << "["; StartVspInterior(attributes); } if (element == "Leaf") { cout << "l"; StartVspLeaf(attributes); } } void ViewCellsParseHandlers::StartOspElement(string element, AttributeList& attributes) { if (element == "Interior") { cout << "["; StartOspInterior(attributes); } if (element == "Leaf") { cout << "l"; StartOspLeaf(attributes); } } void ViewCellsParseHandlers::StartBvhElement(string element, AttributeList& attributes) { if (element == "Interior") { cout << "["; StartBvhInterior(attributes); } if (element == "Leaf") { cout << "l"; StartBvhLeaf(attributes); } } void ViewCellsParseHandlers::StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes) { //if (!mViewCellsManager)return; //-- use cell type according to the chosen method switch (mViewSpaceHierarchyType) { case BSP: StartBspElement(element, attributes); break; case VSP: StartVspElement(element, attributes); break; default: Debug << "not implemented" << endl; break; } } void ViewCellsParseHandlers::StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes) { //if (!mViewCellsManager)return; //-- use cell type according to the chosen method switch (mObjectSpaceHierarchyType) { case OSP: StartOspElement(element, attributes); break; case BVH: StartBvhElement(element, attributes); break; default: Debug << "not implemented" << endl; break; } } void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes) { // interiors + leaves interpreted view cells else if (element == "Interior") { Debug << "["; StartViewCellInterior(attributes); } if (element == "Leaf") { Debug << "l"; StartViewCellLeaf(attributes); } } void ViewCellsParseHandlers::startElement(const XMLCh* const name, AttributeList& attributes) { StrX lname(name); string element(lname.LocalForm()); if (element == "ViewCells") { cout << "\nparsing view cells" << endl; mCurrentState = PARSE_VIEWCELLS; // create new view cells hierarchy mViewCellsTree = new ViewCellsTree(); } // decides about the view cells manager type if (element == "Hierarchy") { cout << "parsing view cells manager type" << endl; StartHierarchy(attributes); } // decides about the view cell hierarchy if (element == "ViewSpaceHierarchy") { cout << "\nparsing view space hierarchy" << endl; mCurrentState = PARSE_VIEWSPACE_HIERARCHY; StartViewSpaceHierarchy(attributes); } // decides about the view cell hierarchy if (element == "ObjectSpaceHierarchy") { cout << "\nparsing object space hierarchy" << endl; mCurrentState = PARSE_OBJECTSPACE_HIERARCHY; StartObjectSpaceHierarchy(attributes); } // decides the used view cell hierarchy if (element == "BoundingBox") { Debug << "b"; StartBoundingBox(attributes); } // parse view space hierarchy switch (mCurrentState) { case PARSE_VIEWSPACE_HIERARCHY: StartViewSpaceHierarchyElement(element, attributes); break; case PARSE_OBJECTSPACE_HIERARCHY: StartObjectSpaceHierarchyElement(element, attributes); break; case PARSE_VIEWCELLS: StartViewCellHierarchyElement(element, attributes); break; default: break; } ++ mElementCount; mAttrCount += attributes.getLength(); } void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, AttributeList& attributes) { int len = attributes.getLength(); vector objIndices; for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); if (attrName == "pvs") { StrX attrValue(attributes.getValue(i)); // handle coordIndex objIndices.clear(); const char *ptr = attrValue.LocalForm(); char *endptr; while (1) { int index = strtol(ptr, &endptr, 10); if (ptr == endptr) break; objIndices.push_back(index); ptr = endptr; } //TODO: find objects and add them to pvs // TODO: get view cell with specified id MeshInstance dummyInst(NULL); vector::const_iterator it, it_end = objIndices.end(); for (it = objIndices.begin(); it != it_end; ++ it) { const int objId = *it; dummyInst.SetId(objId); ObjectContainer::iterator oit = lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) { // $$JB we should store a float a per object which corresponds // to sumof pdfs, i.e. its relative visibility // temporarily set to 1.0f viewCell->GetPvs().AddSample(*oit, 1.0f); } else { Debug << "error: object with id " << objId << " does not exist" << endl; } } } else if (attrName == "id") { StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); char *endptr = NULL; const int id = strtol(ptr, &endptr, 10); viewCell->SetId(id); } /*else if (attrName == "active") { StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); char *endptr = NULL; const bool isActive = (bool)strtol(ptr, &endptr, 10); if (isActive) viewCell->SetActive(); }*/ else if (attrName == "mergecost") { StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); char *endptr = NULL; const float cost = (float)strtod(ptr, &endptr); viewCell->SetMergeCost(cost); } } } void ViewCellsParseHandlers::StartViewSpaceHierarchy(AttributeList& attributes) { int len = attributes.getLength(); Vector3 bmin, bmax; for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); // hierarchy type if (attrName == "type") { if (strcmp(ptr, "bsp") == 0) { cout << "view space hierarchy: Bsp" << endl; mViewSpaceHierarchyType = BSP; } else if (strcmp(ptr, "vsp") == 0) { Debug << "view space hierarchy: Vsp" << endl; mViewSpaceHierarchyType = VSP; } } else if (attrName == "min") // the view space extent { sscanf(ptr, "%f %f %f", &bmin.x, &bmin.y, &bmin.z); } else if (attrName == "max") { sscanf(ptr, "%f %f %f", &bmax.x, &bmax.y, &bmax.z); } } mViewSpaceBox = AxisAlignedBox3(bmin, bmax); // create the hierarchy based on this information CreateViewSpaceHierarchy(); } void ViewCellsParseHandlers::StartObjectSpaceHierarchy(AttributeList& attributes) { int len = attributes.getLength(); Vector3 bmin, bmax; for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); // hierarchy type if (attrName == "type") { if (strcmp(ptr, "osp") == 0) { Debug << "object space hierarchy: Osp" << endl; mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); } else if (strcmp(ptr, "bvh") == 0) { Debug << "object space hierarchy: Bvh" << endl; mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV); } } } } void ViewCellsParseHandlers::StartBoundingBox(AttributeList& attributes) { int len = attributes.getLength(); Vector3 bmin, bmax; int id; for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); if (attrName == "id") { sscanf(ptr, "%d", &id); } if (attrName == "min") { sscanf(ptr, "%f %f %f", &bmin.x, &bmin.y, &bmin.z); } else if (attrName == "max") { sscanf(ptr, "%f %f %f", &bmax.x, &bmax.y, &bmax.z); } } AxisAlignedBox3 box(bmin, bmax); mIBoundingBoxes.push_back(IndexedBoundingBox(id, box)); //cout << "bbox: " << box << endl; } void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes) { BspLeaf * leaf = new BspLeaf(dynamic_cast(mCurrentBspNode), NULL); if (mCurrentBspNode) // replace front or (if not NULL) back child { dynamic_cast(mCurrentBspNode)->ReplaceChildLink(NULL, leaf); } else { mVspBspTree->mRoot = leaf; } //-- find associated view cell int viewCellId; int len = attributes.getLength(); for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); char *endptr = NULL; if (attrName == "viewCellId") { viewCellId = strtol(ptr, &endptr, 10); } } if (viewCellId >= 0) // valid view cell found { // TODO: get view cell with specified id ViewCellInterior dummyVc; dummyVc.SetId(viewCellId); ViewCellContainer::iterator vit = lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); BspViewCell *viewCell = dynamic_cast(*vit); if (viewCell->GetId() == viewCellId) { leaf->SetViewCell(viewCell); viewCell->mLeaf = leaf; } else { Debug << "error: view cell does not exist" << endl; } } else { // add to invalid view space if (mViewSpaceHierarchyType== ViewCellsManager::VSP_BSP) { leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); leaf->SetTreeValid(false); mVspBspTree->PropagateUpValidity(leaf); } } } void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes) { Plane3 plane; int len = attributes.getLength(); for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); if (attrName == "plane") { sscanf(ptr, "%f %f %f %f", &plane.mNormal.x, &plane.mNormal.y, &plane.mNormal.z, &plane.mD); } } BspInterior* interior = new BspInterior(plane); if (mCurrentBspNode) // replace NULL child of parent with current node { BspInterior *current = dynamic_cast(mCurrentBspNode); current->ReplaceChildLink(NULL, interior); interior->SetParent(current); } else { mVspBspTree->mRoot = interior; } mCurrentBspNode = interior; } void ViewCellsParseHandlers::StartViewCellLeaf(AttributeList& attributes) { BspViewCell *viewCell = new BspViewCell(); if (mCurrentViewCell) // replace front or (if not NULL) back child { ViewCellInterior *interior = dynamic_cast(mCurrentViewCell); interior->SetupChildLink(viewCell); } else // root { mViewCellsTree->SetRoot(viewCell); } StartViewCell(viewCell, attributes); // collect leaves mViewCells.push_back(viewCell); } void ViewCellsParseHandlers::StartViewCellInterior(AttributeList& attributes) { ViewCellInterior* interior = new ViewCellInterior(); if (mCurrentViewCell) // replace NULL child of parent with current node { ViewCellInterior *current = dynamic_cast(mCurrentViewCell); current->SetupChildLink(interior); } else { mViewCellsTree->SetRoot(interior); } mCurrentViewCell = interior; StartViewCell(interior, attributes); } void ViewCellsParseHandlers::CreateViewSpaceHierarchy() { if (mViewSpaceHierarchyType == BSP) { cout << "hierarchy type: Bsp" << endl; mVspBspTree = new VspBspTree(); // set view space box mVspBspTree->mBox = mViewSpaceBox; } else if (mViewSpaceHierarchyType == VSP) { cout << "hierarchy type: Vsp" << endl; mVspTree = new VspTree(); // set view space box mVspTree->mBoundingBox = mViewSpaceBox; // object space hierarchy already constructed if (mHierarchyManager) { mHierarchyManager->mVspTree = mVspTree; mVspTree->mHierarchyManager = mHierarchyManager; } } cout << "\nview space box: " << mViewSpaceBox << endl; } void ViewCellsParseHandlers::CreateViewCellsManager(/*const char *name*/) { if (mViewSpaceHierarchyType == BSP) // { Debug << "creating view cells manager: VspBsp" << endl; //mVspBspTree = new VspBspTree(); mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree); } else if (mViewSpaceHierarchyType == VSP) { Debug << "creating view cells manager: VspOsp" << endl; // hack mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager); } mViewCellsManager->SetViewSpaceBox(mViewSpaceBox); } void ViewCellsParseHandlers::characters(const XMLCh* const chars, const unsigned int length) { mCharacterCount += length; } void ViewCellsParseHandlers::ignorableWhitespace(const XMLCh* const chars, const unsigned int length) { mSpaceCount += length; } void ViewCellsParseHandlers::resetDocument() { mAttrCount = 0; mCharacterCount = 0; mElementCount = 0; mSpaceCount = 0; } void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes) { VspLeaf * leaf = new VspLeaf(dynamic_cast(mCurrentVspNode), NULL); if (mCurrentVspNode) // replace front or (if not NULL) back child { dynamic_cast(mCurrentVspNode)->ReplaceChildLink(NULL, leaf); } else { mVspTree->mRoot = leaf; } //-- find associated view cell int viewCellId; int len = attributes.getLength(); for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); char *endptr = NULL; if (attrName == "viewCellId") { viewCellId = strtol(ptr, &endptr, 10); } } if (viewCellId >= 0) // valid view cell { // TODO: get view cell with specified id ViewCellInterior dummyVc; dummyVc.SetId(viewCellId); ViewCellContainer::iterator vit = lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); VspViewCell *viewCell = dynamic_cast(*vit); if (viewCell->GetId() == viewCellId) { leaf->SetViewCell(viewCell); viewCell->mLeaf = leaf; } else { Debug << "error: view cell does not exist" << endl; } } else { // add to invalid view space leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell()); leaf->SetTreeValid(false); mVspTree->PropagateUpValidity(leaf); } } void ViewCellsParseHandlers::StartVspInterior(AttributeList& attributes) { AxisAlignedPlane plane; int len = attributes.getLength(); for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); if (attrName == "plane") { sscanf(ptr, "%d %f", &plane.mAxis, &plane.mPosition); } } VspInterior* interior = new VspInterior(plane); if (mCurrentVspNode) // replace NULL child of parent with current node { VspInterior *current = dynamic_cast(mCurrentVspNode); current->ReplaceChildLink(NULL, interior); interior->SetParent(current); } else { mVspTree->mRoot = interior; } mCurrentVspNode = interior; } void ViewCellsParseHandlers::StartOspInterior(AttributeList& attributes) { AxisAlignedPlane plane; int len = attributes.getLength(); for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); if (attrName == "plane") { sscanf(ptr, "%d %f", &plane.mAxis, &plane.mPosition); } } KdInterior* interior = new KdInterior(NULL); interior->mAxis = plane.mAxis; interior->mPosition = plane.mPosition; if (mCurrentKdNode) // replace NULL child of parent with current node { KdInterior *parent = dynamic_cast(mCurrentKdNode); parent->ReplaceChildLink(NULL, interior); interior->mParent = parent; } else { mHierarchyManager->mOspTree->mRoot = interior; } mCurrentKdNode = interior; } void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes) { KdLeaf * leaf = new KdLeaf(dynamic_cast(mCurrentKdNode), NULL); if (mCurrentKdNode) // replace front or (if not NULL) back child { dynamic_cast(mCurrentKdNode)->ReplaceChildLink(NULL, leaf); } else { mHierarchyManager->mOspTree->mRoot = leaf; } } void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes) {/* KdLeaf * leaf = new KdLeaf(dynamic_cast(mCurrentKdNode), NULL); if (mCurrentKdNode) // replace front or (if not NULL) back child { dynamic_cast(mCurrentKdNode)->ReplaceChildLink(NULL, leaf); } else { mHierarchyManager->mBvHierarchy->mRoot = leaf; }*/ } void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes) {/* AxisAlignedPlane plane; int len = attributes.getLength(); for (int i = 0; i < len; ++ i) { string attrName(StrX(attributes.getName(i)).LocalForm()); StrX attrValue(attributes.getValue(i)); const char *ptr = attrValue.LocalForm(); if (attrName == "plane") { sscanf(ptr, "%d %f", &plane.mAxis, &plane.mPosition); } } KdInterior* interior = new KdInterior(NULL); interior->mAxis = plane.mAxis; interior->mPosition = plane.mPosition; if (mCurrentKdNode) // replace NULL child of parent with current node { KdInterior *parent = dynamic_cast(mCurrentKdNode); parent->ReplaceChildLink(NULL, interior); interior->mParent = parent; } else { mOspTree->mRoot = interior; } mCurrentKdNode = interior;*/ } // --------------------------------------------------------------------------- // StdInParseHandlers: Overrides of the SAX ErrorHandler interface // --------------------------------------------------------------------------- void ViewCellsParseHandlers::error(const SAXParseException& e) { XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId()) << ", line " << e.getLineNumber() << ", char " << e.getColumnNumber() << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; } void ViewCellsParseHandlers::fatalError(const SAXParseException& e) { XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId()) << ", line " << e.getLineNumber() << ", char " << e.getColumnNumber() << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; } void ViewCellsParseHandlers::warning(const SAXParseException& e) { XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId()) << ", line " << e.getLineNumber() << ", char " << e.getColumnNumber() << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; } bool ViewCellsParser::ParseViewCellsFile(const string filename, ViewCellsManager **viewCells, ObjectContainer *objects, BoundingBoxConverter *bconverter) { // Initialize the XML4C system try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; return false; } // // Create a SAX parser object. Then, according to what we were told on // the command line, set the options. // SAXParser* parser = new SAXParser; parser->setValidationScheme(valScheme); parser->setDoNamespaces(doNamespaces); parser->setDoSchema(doSchema); parser->setValidationSchemaFullChecking(schemaFullChecking); // // Create our SAX handler object and install it on the parser, as the // document and error handler. We are responsible for cleaning them // up, but since its just stack based here, there's nothing special // to do. // ViewCellsParseHandlers handler(objects, bconverter); parser->setDocumentHandler(&handler); parser->setErrorHandler(&handler); unsigned long duration; int errorCount = 0; // create a faux scope so that 'src' destructor is called before // XMLPlatformUtils::Terminate { // // Kick off the parse and catch any exceptions. Create a standard // input input source and tell the parser to parse from that. // // StdInInputSource src; try { const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); #if USE_GZLIB XMLCh *myFilePath = XMLString::transcode(filename.c_str()); GzFileInputSource isource(myFilePath); parser->parse(isource); #else parser->parse(filename.c_str()); #endif const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); duration = endMillis - startMillis; errorCount = parser->getErrorCount(); } catch (const OutOfMemoryException&) { XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; errorCount = 2; return false; } catch (const XMLException& e) { XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n" << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl; errorCount = 1; return false; } // Print out the stats that we collected and time taken if (!errorCount) { XERCES_STD_QUALIFIER cerr << filename << ": " << duration << " ms (" << handler.GetElementCount() << " elems, " << handler.GetAttrCount() << " attrs, " << handler.GetSpaceCount() << " spaces, " << handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; } } // // Delete the parser itself. Must be done prior to calling Terminate, below. // delete parser; XMLPlatformUtils::Terminate(); //-- assign new view cells manager *viewCells = handler.mViewCellsManager; if (errorCount > 0) return false; else return true; } }