[wpdev-commits] wolfpack definitions.cpp,1.21,1.22 definitions.h,1.5,1.6
Brought to you by:
rip,
thiagocorrea
From: Correa <thi...@us...> - 2004-10-11 07:58:13
|
Update of /cvsroot/wpdev/wolfpack In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13664 Modified Files: definitions.cpp definitions.h Log Message: Definitions are now loaded recursively. The <include> tag can now be used to include child elements into another element. -- HellRaider Index: definitions.cpp =================================================================== RCS file: /cvsroot/wpdev/wolfpack/definitions.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** definitions.cpp 9 Oct 2004 14:28:59 -0000 1.21 --- definitions.cpp 11 Oct 2004 07:58:00 -0000 1.22 *************** *** 31,34 **** --- 31,35 ---- #include <qptrstack.h> #include <qregexp.h> + #include <qvaluestack.h> #include <qstringlist.h> #include <qvaluevector.h> *************** *** 105,140 **** private: cDefManagerPrivate* impl; ! QPtrStack<cElement> stack; ! QString filename; ! QXmlLocator* locator; public: ! cXmlHandler( cDefManagerPrivate* impl, const QString& filename ) { this->impl = impl; ! this->filename = filename; ! }; ! virtual ~cXmlHandler() { ! while ( stack.count() > 1 ) ! stack.pop(); // The parent node should take care of deleting the children ! if ( stack.count() == 1 ) ! delete stack.pop(); } ! void setDocumentLocator( QXmlLocator* locator ) { ! this->locator = locator; } ! bool endDocument() { ! while ( stack.count() > 1 ) ! stack.pop(); // The parent node should take care of deleting the children ! if ( stack.count() == 1 ) ! delete stack.pop(); return true; } --- 106,178 ---- private: cDefManagerPrivate* impl; ! // Element level within the current file ! QValueStack<int> levels; ! // Holds all read elements. ! QPtrStack<cElement> elements; ! // Files stack (each <include> pushes a file) ! QValueStack<QString> filenames; ! // Locators associated to each document ! QPtrStack<QXmlLocator> locators; public: ! cXmlHandler( cDefManagerPrivate* impl ) { this->impl = impl; ! } ! virtual ~cXmlHandler() ! { ! while( !elements.isEmpty() ) ! { ! cElement *parent; ! while( elements.current() != NULL ) ! { ! parent = elements.pop(); ! } ! delete parent; ! while( elements.current() == NULL ) ! elements.pop(); ! } } ! void load( const QString &filename ) { ! QFile file( filename ); ! ! if( !file.open( IO_ReadOnly ) ) ! { ! Console::instance()->send( tr("Unable to open %1!\n").arg( filename ) ); ! return; ! } ! ! filenames.push( filename ); ! ! QXmlInputSource input( &file ); ! QXmlSimpleReader reader; ! reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); ! ! reader.setContentHandler( this ); ! reader.setErrorHandler( this ); ! reader.parse( &input, false ); ! ! filenames.pop(); } ! void setDocumentLocator( QXmlLocator* locator ) { ! locators.push( locator ); ! } ! bool startDocument() ! { ! levels.push( 0 ); ! return true; ! } + bool endDocument() + { + levels.pop(); + locators.pop(); return true; } *************** *** 142,158 **** bool startElement( const QString& /*namespaceURI*/, const QString& localName, const QString& qName, const QXmlAttributes& atts ) { ! // Some Parent Elements have special meanings ! if ( stack.isEmpty() ) ! { ! if ( qName == "definitions" ) ! return true; ! // Include another file ! if ( qName == "include" ) { ! QString value = atts.value( "file" ); ! impl->imports.push_back( value ); ! return true; } } --- 180,214 ---- bool startElement( const QString& /*namespaceURI*/, const QString& localName, const QString& qName, const QXmlAttributes& atts ) { ! levels.top()++; ! // Ignore document root ! if( levels.top() == 1 ) ! { ! if( levels.isEmpty() ) { ! // Top level ! elements.push( NULL ); } + else + { + // Within an include + elements.push( elements.current() ); + } + return true; + } + + if( qName == "acl" ) + { + int i = 0; + } + + // Include another file + if( qName == "include" ) + { + QString value = atts.value( "file" ); + load( value ); + + elements.push( elements.current() ); + return true; } *************** *** 161,173 **** element->copyAttributes( atts ); ! // Child Element ? ! if ( stack.count() > 0 ) { ! cElement* parent = stack.current(); // Pop the potential parent parent->addChild( element ); // Add the child to it's parent element->setParent( parent ); } ! stack.push( element ); // Push our element (there may be children) return true; } --- 217,230 ---- element->copyAttributes( atts ); ! // Child Element? ! if( elements.current() != NULL ) { ! cElement* parent = elements.current(); // Pop the potential parent parent->addChild( element ); // Add the child to it's parent element->setParent( parent ); } ! elements.push( element ); // Push our element (there may be children) ! return true; } *************** *** 175,187 **** bool endElement( const QString& /*namespaceURI*/, const QString& /*localName*/, const QString& /*qName*/ ) { ! if ( stack.isEmpty() ) { return true; } ! cElement* element = stack.pop(); // Did we complete a parent node? ! if ( stack.isEmpty() ) { // Find a category node --- 232,250 ---- bool endElement( const QString& /*namespaceURI*/, const QString& /*localName*/, const QString& /*qName*/ ) { ! cElement* element = elements.pop(); ! if( --( levels.top() ) == 0 ) { + // Ignore root return true; } ! if( element == elements.current() ) ! { ! // Ignore include ! return true; ! } // Did we complete a parent node? ! if( elements.current() == NULL ) { // Find a category node *************** *** 200,204 **** if ( impl->unique[categories[i].key].contains( tagId ) && !Config::instance()->overwriteDefinitions() ) { ! Console::instance()->log( LOG_WARNING, tr( "Duplicate %1: %2\n[File: %3, Line: %4]\n" ).arg( element->name() ).arg( tagId ).arg( filename ).arg( locator->lineNumber() ) ); delete element; } --- 263,268 ---- if ( impl->unique[categories[i].key].contains( tagId ) && !Config::instance()->overwriteDefinitions() ) { ! Console::instance()->log( LOG_WARNING, tr( "Duplicate %1: %2\n[File: %3, Line: %4]\n" ) ! .arg( element->name() ).arg( tagId ).arg( filenames.top() ).arg( locators.current()->lineNumber() ) ); delete element; } *************** *** 218,222 **** } ! Console::instance()->log( LOG_WARNING, tr( "Unknown element: %1\n[File: %2, Line: %3]\n" ).arg( element->name() ).arg( filename ).arg( locator->lineNumber() ) ); delete element; } --- 282,287 ---- } ! Console::instance()->log( LOG_WARNING, tr( "Unknown element: %1\n[File: %2, Line: %3]\n" ) ! .arg( element->name() ).arg( filenames.top() ).arg( locators.current()->lineNumber() ) ); delete element; } *************** *** 227,235 **** bool characters( const QString& ch ) { ! if ( !stack.isEmpty() ) { ! cElement* element = stack.pop(); ! element->setText( element->text() + ch ); ! stack.push( element ); } --- 292,300 ---- bool characters( const QString& ch ) { ! if( !elements.isEmpty() ) { ! cElement *element = elements.current(); ! if( element ) ! element->setText( element->text() + ch ); } *************** *** 240,282 **** bool warning( const QXmlParseException& exception ) { ! Console::instance()->log( LOG_WARNING, tr( "%1\n[File: %2, Line: %3, Column: %4" ).arg( exception.message(), filename ).arg( exception.lineNumber() ).arg( exception.columnNumber() ) ); return true; // continue } bool error( const QXmlParseException& exception ) { ! Console::instance()->log( LOG_ERROR, tr( "%1\n[File: %2, Line: %3, Column: %4" ).arg( exception.message(), filename ).arg( exception.lineNumber() ).arg( exception.columnNumber() ) ); return true; // continue } bool fatalError( const QXmlParseException& exception ) { ! Console::instance()->log( LOG_ERROR, tr( "%1\n[File: %2, Line: %3, Column: %4" ).arg( exception.message(), filename ).arg( exception.lineNumber() ).arg( exception.columnNumber() ) ); return true; // continue } }; - // Recursive Function for Importing Script Sections - bool cDefinitions::ImportSections( const QString& FileName ) - { - QFile File( FileName ); - - if ( !File.open( IO_ReadOnly ) ) - { - Console::instance()->send( tr("Unable to open %1!\n").arg(FileName) ); - return false; - } - - QXmlInputSource input( &File ); - QXmlSimpleReader reader; - reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); - - cXmlHandler handler( impl, FileName ); - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - reader.parse( &input, false ); - - File.close(); - return true; - } - void cDefinitions::unload() { --- 305,326 ---- bool warning( const QXmlParseException& exception ) { ! Console::instance()->log( LOG_WARNING, tr( "%1\n[File: %2, Line: %3, Column: %4" ) ! .arg( exception.message(), filenames.top() ).arg( exception.lineNumber() ).arg( exception.columnNumber() ) ); return true; // continue } bool error( const QXmlParseException& exception ) { ! Console::instance()->log( LOG_ERROR, tr( "%1\n[File: %2, Line: %3, Column: %4" ) ! .arg( exception.message(), filenames.top() ).arg( exception.lineNumber() ).arg( exception.columnNumber() ) ); return true; // continue } bool fatalError( const QXmlParseException& exception ) { ! Console::instance()->log( LOG_ERROR, tr( "%1\n[File: %2, Line: %3, Column: %4" ) ! .arg( exception.message(), filenames.top() ).arg( exception.lineNumber() ).arg( exception.columnNumber() ) ); return true; // continue } }; void cDefinitions::unload() { *************** *** 326,336 **** void cDefinitions::load( void ) { - unsigned int i = 0; impl->imports = QStringList::split( ";", Config::instance()->getString( "General", "Definitions", "definitions/index.xml", true ) ); ! while ( i < impl->imports.size() ) { ! ImportSections( impl->imports[i] ); ! ++i; } --- 370,379 ---- void cDefinitions::load( void ) { impl->imports = QStringList::split( ";", Config::instance()->getString( "General", "Definitions", "definitions/index.xml", true ) ); ! for( unsigned int i = 0; i < impl->imports.size(); ++i ) { ! cXmlHandler handler( impl ); ! handler.load( impl->imports[i] ); } Index: definitions.h =================================================================== RCS file: /cvsroot/wpdev/wolfpack/definitions.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** definitions.h 1 Oct 2004 19:43:56 -0000 1.5 --- definitions.h 11 Oct 2004 07:58:00 -0000 1.6 *************** *** 142,146 **** void unload( void ); - bool ImportSections( const QString& FileName ); const cElement* getDefinition( eDefCategory Type, const QString& id ) const; const QValueVector<cElement*>& getDefinitions( eDefCategory Type ) const; --- 142,145 ---- |