From b074be2fe92b7e722ebb8a3ea3477dbb88c2bda2 Mon Sep 17 00:00:00 2001 From: stv Date: Wed, 19 Oct 2005 11:53:13 +0000 Subject: [PATCH] Compilation problems on Windows platform --- src/Qtx/QtxResourceMgr.cxx | 15 +- src/Qtx/QtxResourceMgr.h | 374 ++++++++++++++++++++----------------- 2 files changed, 215 insertions(+), 174 deletions(-) diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 75f1bd0fe..fde678959 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -1448,10 +1448,13 @@ void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList& QTranslator* trans = 0; ResListIterator it( myResources ); it.toLast(); - for ( ; it.current(); --it ) { - for ( QStringList::const_iterator itr = translators.begin(); itr != translators.end(); ++itr ) { + for ( ; it.current(); --it ) + { + for ( QStringList::const_iterator itr = translators.begin(); itr != translators.end(); ++itr ) + { trans = it.current()->loadTranslator( resSection(), prefix, *itr ); - if ( trans ) { + if ( trans ) + { if ( !myTranslator[prefix].contains( trans ) ) myTranslator[prefix].append( trans ); qApp->installTranslator( trans ); @@ -1467,9 +1470,11 @@ void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name QTranslator* trans = 0; ResListIterator it( myResources ); it.toLast(); - for ( ; it.current(); --it ) { + for ( ; it.current(); --it ) + { trans = it.current()->loadTranslator( resSection(), prefix, name ); - if ( trans ) { + if ( trans ) + { if ( !myTranslator[prefix].contains( trans ) ) myTranslator[prefix].append( trans ); qApp->installTranslator( trans ); diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 692c61bb1..7b0855d08 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -17,183 +17,24 @@ class QPixmap; #pragma warning( disable:4251 ) #endif +/*! + Class: QtxResourceMgr +*/ + class QTX_EXPORT QtxResourceMgr { class IniFormat; class XmlFormat; class Resources; - template class IMap; - template class IMapConstIterator; - template class IMapIterator - { - private: - IMap* myMap; - int myIndex; - - public: - IMapIterator() : myMap( 0 ), myIndex( 0 ) { init(); } - IMapIterator( const IMap* m ) : myMap( const_cast< IMap* >( m ) ), myIndex( 0 ) { init(); } - IMapIterator( const IMapIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); } - - bool operator==( const IMapIterator& i ) { return !operator!=( i ); } - bool operator!=( const IMapIterator& i ) { return !myMap || myMap != i.myMap || myIndex != i.myIndex; } - - operator bool() const { return myIndex >= 0; } - - const Key& key() const { return myMap->key( myIndex ); } - Value& data() { return myMap->value( myIndex ); } - const Value& data() const { return myMap->value( myIndex ); } - - Value& operator*() { return data(); } - - IMapIterator& operator++() { myIndex++; init(); return *this; } - IMapIterator operator++( int ) { IMapIterator i = *this; myIndex++; init(); return i; } - IMapIterator& operator--() { myIndex--; init(); return *this; } - IMapIterator operator--( int ) { IMapIterator i = *this; myIndex--; init(); return i; } - - private: - IMapIterator( const IMap* m, const int index ) : myMap( const_cast< IMap* >( m ) ), myIndex( index ) { init(); } - void init() { if ( !myMap || myIndex >= myMap->count() ) myIndex = -1; } - - friend class IMap; - friend class IMapConstIterator; - }; - - template class IMapConstIterator - { - private: - IMap* myMap; - int myIndex; - - public: - IMapConstIterator() : myMap( 0 ), myIndex( 0 ) { init(); } - IMapConstIterator( const IMap* m ) : myMap( const_cast< IMap* >( m ) ), myIndex( 0 ) { init(); } - IMapConstIterator( const IMapConstIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); } - IMapConstIterator( const IMapIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); } - - bool operator==( const IMapConstIterator& i ) { return !operator!=( i ); } - bool operator!=( const IMapConstIterator& i ) { return !myMap || myMap != i.myMap || myIndex != i.myIndex; } - - operator bool() const { return myIndex >= 0; } - - const Key& key() const { return myMap->key( myIndex ); } - const Value& data () const { return myMap->value( myIndex ); } - - const Value& operator*() const { return data(); } - - IMapConstIterator& operator++() { myIndex++; init(); return *this; } - IMapConstIterator operator++( int ) { IMapConstIterator i = *this; myIndex++; init(); return i; } - IMapConstIterator& operator--() { myIndex--; init(); return *this; } - IMapConstIterator operator--( int ) { IMapConstIterator i = *this; myIndex--; init(); return i; } - - private: - IMapConstIterator( const IMap* m, const int index ): myMap( const_cast< IMap* >( m ) ), myIndex( index ) { init(); } - void init() { if ( !myMap || myIndex >= myMap->count() ) myIndex = -1; } - - friend class IMap; - }; - - template class IMap - { - private: - QValueList myKeys; - QMap myData; - Key dummyKey; - Value dummyValue; - - public: - typedef IMapIterator Iterator; - typedef IMapConstIterator ConstIterator; - friend class IMap::Iterator; - friend class IMap::ConstIterator; - - IMap() {} - IMap( const IMap& m ) : myKeys( m.myKeys ), myData( m.myData ) {} - IMap& operator=( const IMap& m ) { myKeys = m.myKeys; myData = m.myData; return *this; } - - int count() const { return myData.count(); } - int size() const { return myData.count(); } - bool empty() const { return myData.empty(); } - bool isEmpty() const { return myData.empty(); } - - void clear() { myKeys.clear(); myData.clear(); } - - QValueList keys() const { return myKeys; } - QValueList values() const { QValueList l; for ( int i = 0; i < count(); i++ ) l.append( value( i ) ); return l; } - bool contains ( const Key& key ) const { return myData.contains( key ); } - - Iterator begin() { return Iterator( this ); } - Iterator end() { return Iterator( this, count() ); } - ConstIterator begin() const { return ConstIterator( this ); } - ConstIterator end() const { return ConstIterator( this, count() ); } - - Iterator insert( const Key& key, const Value& value, bool overwrite = true ) - { - if ( myData.find( key ) == myData.end() || overwrite ) { - if ( myData.find( key ) != myData.end() && overwrite ) - myKeys.remove( myKeys.find( key ) ); - myKeys.append( key ); - myData[ key ] = value; - } - return Iterator( this, index( key ) ); - } - Iterator replace( const Key& key, const Value& value ) - { - if ( myData.find( key ) == myData.end() ) - myKeys.append( key ); - myData[ key ] = value; - return Iterator( this, index( key ) ); - } - - int index( const Key& key ) const { return myKeys.findIndex( key ); } - Iterator at( const int index ) { return Iterator( this, index ); } - ConstIterator at( const int index ) const { return ConstIterator( this, index ); } - - Key& key( const int index ) - { - if( index < 0 || index >= myKeys.count() ) - return dummyKey; - return myKeys[index]; - } - Value& value( const int index ) - { - if( index < 0 || index >= myKeys.count() ) - return dummyValue; - return myData[ myKeys[index] ]; - } - Value& operator[]( const Key& key ) - { - if ( myData.find( key ) == myData.end() ) - insert( key, Value() ); - return myData[ key ]; - } - const Value& operator[]( const Key& key ) const - { - if ( myData.find( key ) == myData.end() ) - return dummyValue; - return myData[ key ]; - } - - void erase( Iterator it ) { remove( it ); } - void erase( const Key& key ) { remove( key ); } - void erase( const int index ) { remove( index ); } - void remove( Iterator it ) { if ( it.myMap != this ) return; remove( it.myIndex ); } - void remove( const Key& key ) { remove( index( key ) ); } - void remove( const int index ) - { - if( index >= 0 && index < myKeys.count() ) { - myData.remove( myKeys[ index ] ); - myKeys.remove( myKeys.at( index ) ); - } - } - }; - public: - class Format; -#if defined(QTX_NO_INDEXED_MAP) + template class IMap; + template class IMapIterator; + template class IMapConstIterator; + +#ifdef QTX_NO_INDEXED_MAP typedef QMap Section; #else typedef IMap Section; @@ -308,6 +149,10 @@ private: QPixmap myDefaultPix; }; +/*! + Class: QtxResourceMgr::Format +*/ + class QTX_EXPORT QtxResourceMgr::Format { public: @@ -332,6 +177,10 @@ private: QMap myOpt; }; +/*! + Class: QtxResourceMgr::Resources +*/ + class QtxResourceMgr::Resources { public: @@ -370,10 +219,197 @@ private: QString fileName( const QString&, const QString&, const QString& ) const; private: - QMap mySections; + typedef QMap SectionMap; + +private: + SectionMap mySections; QString myFileName; friend class QtxResourceMgr::Format; }; +/*! + Class: QtxResourceMgr::IMapIterator +*/ + +template class QtxResourceMgr::IMapIterator +{ +public: + IMapIterator() : myMap( 0 ), myIndex( 0 ) { init(); } + IMapIterator( const IMap* m ) : myMap( const_cast< IMap* >( m ) ), myIndex( 0 ) { init(); } + IMapIterator( const IMapIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); } + + bool operator==( const IMapIterator& i ) { return !operator!=( i ); } + bool operator!=( const IMapIterator& i ) { return !myMap || myMap != i.myMap || myIndex != i.myIndex; } + + operator bool() const { return myIndex >= 0; } + + const Key& key() const { return myMap->key( myIndex ); } + Value& data() { return myMap->value( myIndex ); } + const Value& data() const { return myMap->value( myIndex ); } + + Value& operator*() { return data(); } + + IMapIterator& operator++() { myIndex++; init(); return *this; } + IMapIterator operator++( int ) { IMapIterator i = *this; myIndex++; init(); return i; } + IMapIterator& operator--() { myIndex--; init(); return *this; } + IMapIterator operator--( int ) { IMapIterator i = *this; myIndex--; init(); return i; } + +private: + IMapIterator( const IMap* m, const int index ) : myMap( const_cast< IMap* >( m ) ), myIndex( index ) { init(); } + void init() { if ( !myMap || myIndex >= myMap->count() ) myIndex = -1; } + +private: + IMap* myMap; + int myIndex; + + friend class IMap; + friend class IMapConstIterator; +}; + +/*! + Class: QtxResourceMgr::IMapConstIterator +*/ + +template class QtxResourceMgr::IMapConstIterator +{ +public: + IMapConstIterator() : myMap( 0 ), myIndex( 0 ) { init(); } + IMapConstIterator( const IMap* m ) : myMap( const_cast< IMap* >( m ) ), myIndex( 0 ) { init(); } + IMapConstIterator( const IMapConstIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); } + IMapConstIterator( const IMapIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); } + + bool operator==( const IMapConstIterator& i ) { return !operator!=( i ); } + bool operator!=( const IMapConstIterator& i ) { return !myMap || myMap != i.myMap || myIndex != i.myIndex; } + + operator bool() const { return myIndex >= 0; } + + const Key& key() const { return myMap->key( myIndex ); } + const Value& data() const { return myMap->value( myIndex ); } + + const Value& operator*() const { return data(); } + + IMapConstIterator& operator++() { myIndex++; init(); return *this; } + IMapConstIterator operator++( int ) { IMapConstIterator i = *this; myIndex++; init(); return i; } + IMapConstIterator& operator--() { myIndex--; init(); return *this; } + IMapConstIterator operator--( int ) { IMapConstIterator i = *this; myIndex--; init(); return i; } + +private: + IMapConstIterator( const IMap* m, const int index ): myMap( const_cast< IMap* >( m ) ), myIndex( index ) { init(); } + void init() { if ( !myMap || myIndex >= myMap->count() ) myIndex = -1; } + +private: + IMap* myMap; + int myIndex; + + friend class IMap; +}; + +/*! + Class: QtxResourceMgr::IMap +*/ + +template class QtxResourceMgr::IMap +{ +public: + typedef IMapIterator Iterator; + typedef IMapConstIterator ConstIterator; + +public: + IMap() {} + IMap( const IMap& m ) : myKeys( m.myKeys ), myData( m.myData ) {} + IMap& operator=( const IMap& m ) { myKeys = m.myKeys; myData = m.myData; return *this; } + + int count() const { return myData.count(); } + int size() const { return myData.count(); } + bool empty() const { return myData.empty(); } + bool isEmpty() const { return myData.empty(); } + + void clear() { myKeys.clear(); myData.clear(); } + + QValueList keys() const { return myKeys; } + QValueList values() const { QValueList l; for ( int i = 0; i < count(); i++ ) l.append( value( i ) ); return l; } + bool contains ( const Key& key ) const { return myData.contains( key ); } + + Iterator begin() { return Iterator( this ); } + Iterator end() { return Iterator( this, count() ); } + ConstIterator begin() const { return ConstIterator( this ); } + ConstIterator end() const { return ConstIterator( this, count() ); } + + Iterator insert( const Key& key, const Value& value, bool overwrite = true ) + { + if ( myData.find( key ) == myData.end() || overwrite ) + { + if ( myData.find( key ) != myData.end() && overwrite ) + myKeys.remove( myKeys.find( key ) ); + myKeys.append( key ); + myData[key] = value; + } + return Iterator( this, index( key ) ); + } + + Iterator replace( const Key& key, const Value& value ) + { + if ( myData.find( key ) == myData.end() ) + myKeys.append( key ); + myData[ key ] = value; + return Iterator( this, index( key ) ); + } + + int index( const Key& key ) const { return myKeys.findIndex( key ); } + Iterator at( const int index ) { return Iterator( this, index ); } + ConstIterator at( const int index ) const { return ConstIterator( this, index ); } + + Key& key( const int index ) + { + if ( index < 0 || index >= (int)myKeys.count() ) + return dummyKey; + return myKeys[index]; + } + + Value& value( const int index ) + { + if ( index < 0 || index >= (int)myKeys.count() ) + return dummyValue; + return myData[ myKeys[index] ]; + } + + Value& operator[]( const Key& key ) + { + if ( myData.find( key ) == myData.end() ) + insert( key, Value() ); + return myData[ key ]; + } + + const Value& operator[]( const Key& key ) const + { + if ( myData.find( key ) == myData.end() ) + return dummyValue; + return myData[ key ]; + } + + void erase( Iterator it ) { remove( it ); } + void erase( const Key& key ) { remove( key ); } + void erase( const int index ) { remove( index ); } + void remove( Iterator it ) { if ( it.myMap != this ) return; remove( it.myIndex ); } + void remove( const Key& key ) { remove( index( key ) ); } + void remove( const int index ) + { + if ( index >= 0 && index < (int)myKeys.count() ) + { + myData.remove( myKeys[ index ] ); + myKeys.remove( myKeys.at( index ) ); + } + } + +private: + QValueList myKeys; + QMap myData; + Key dummyKey; + Value dummyValue; + + friend class IMapIterator; + friend class IMapConstIterator; +}; + #endif -- 2.39.2