diff --git a/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.C b/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.C index 33d7fd3723255e24f6aa7207db3e678b309fdc93..b6e52f46860ae265acae8ce0eef7040fd5b8a394 100644 --- a/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.C +++ b/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.C @@ -28,22 +28,15 @@ Description #include "Dictionary.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Null constructor template<class T> -Dictionary<T>::Dictionary() +Foam::Dictionary<T>::Dictionary() {} -// Copy constructor template<class T> -Dictionary<T>::Dictionary(const Dictionary& dict) +Foam::Dictionary<T>::Dictionary(const Dictionary& dict) : DictionaryBase<IDLList<T>, T>(dict) {} @@ -52,10 +45,10 @@ Dictionary<T>::Dictionary(const Dictionary& dict) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class T> -bool Dictionary<T>::erase(const word& Keyword) +bool Foam::Dictionary<T>::erase(const word& keyword) { T* tPtr; - if ((tPtr = this->remove(Keyword))) + if (tPtr = this->remove(keyword)) { delete tPtr; return true; @@ -69,6 +62,4 @@ bool Dictionary<T>::erase(const word& Keyword) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.H b/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.H index 3b985482e7bdbec929388d8d4dd62c9efbb10094..90af1383f4a485307b002ee9fcd71c32e4ea9eeb 100644 --- a/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.H +++ b/src/OpenFOAM/containers/Dictionaries/Dictionary/Dictionary.H @@ -27,8 +27,10 @@ Class Description Gerneral purpose template dictionary class which manages the storage - associated with it. It is derived from DictionaryBase instantiated on - a memory managed form of intrusive doubly-linked list of \<T\>. + associated with it. + + It is derived from DictionaryBase instantiated on a memory managed form + of intrusive doubly-linked list of \<T\>. SourceFiles Dictionary.C @@ -47,7 +49,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class Dictionary Declaration + Class Dictionary Declaration \*---------------------------------------------------------------------------*/ template<class T> @@ -69,11 +71,9 @@ public: // Member functions - // Editing - - //- Remove an entry specified by keyword from the dictionary - // and delete it - bool erase(const word& keyword); + //- Remove an entry specified by keyword and delete the pointer. + // Returns true if the keyword was found + bool erase(const word& keyword); }; diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C index 4349973c3ce236f4077046a70a95ee50639534dc..b8ce241f094d4b2422dde90d878414b39f220d8b 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C @@ -26,15 +26,10 @@ License #include "DictionaryBase.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template<class IDLListType, class T> -void DictionaryBase<IDLListType, T>::addEntries() +void Foam::DictionaryBase<IDLListType, T>::addEntries() { for ( @@ -51,12 +46,15 @@ void DictionaryBase<IDLListType, T>::addEntries() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class IDLListType, class T> -DictionaryBase<IDLListType, T>::DictionaryBase() +Foam::DictionaryBase<IDLListType, T>::DictionaryBase() {} template<class IDLListType, class T> -DictionaryBase<IDLListType, T>::DictionaryBase(const DictionaryBase& dict) +Foam::DictionaryBase<IDLListType, T>::DictionaryBase +( + const DictionaryBase& dict +) : IDLListType(dict) { @@ -66,17 +64,20 @@ DictionaryBase<IDLListType, T>::DictionaryBase(const DictionaryBase& dict) template<class IDLListType, class T> template<class INew> -DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is, const INew& inewt) +Foam::DictionaryBase<IDLListType, T>::DictionaryBase +( + Istream& is, + const INew& iNew +) : - IDLListType(is, inewt) + IDLListType(is, iNew) { addEntries(); } -// Istream constructor template<class IDLListType, class T> -DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is) +Foam::DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is) : IDLListType(is) { @@ -88,25 +89,60 @@ DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is) // Find and return T template<class IDLListType, class T> -bool DictionaryBase<IDLListType, T>::found(const word& keyword) const +bool Foam::DictionaryBase<IDLListType, T>::found(const word& keyword) const { return hashedTs_.found(keyword); } -// Find and return T* +// Find and return T*, return NULL if not found +template<class IDLListType, class T> +const T* Foam::DictionaryBase<IDLListType, T>::lookupPtr +( + const word& keyword +) const +{ + typename HashTable<T*>::const_iterator iter = hashedTs_.find(keyword); + + if (iter != hashedTs_.end()) + { + return *iter; + } + else + { + return NULL; + } +} + + +// Find and return T*, return NULL if not found +template<class IDLListType, class T> +T* Foam::DictionaryBase<IDLListType, T>::lookupPtr(const word& keyword) +{ + typename HashTable<T*>::iterator iter = hashedTs_.find(keyword); + + if (iter != hashedTs_.end()) + { + return *iter; + } + else + { + return NULL; + } +} + + +// Find and return T*, FatalError if keyword not found template<class IDLListType, class T> -const T* DictionaryBase<IDLListType, T>::lookup(const word& keyword) const +const T* Foam::DictionaryBase<IDLListType, T>::lookup(const word& keyword) const { typename HashTable<T*>::const_iterator iter = hashedTs_.find(keyword); if (iter == hashedTs_.end()) { - // If keyword not found print error message ... FatalErrorIn ( - "DictionaryBase<IDLListType, T>::" - "lookup(const word& keyword) const" + "DictionaryBase<IDLListType, T>::lookup(const word&) const" ) << keyword << " is undefined" << exit(FatalError); } @@ -115,18 +151,17 @@ const T* DictionaryBase<IDLListType, T>::lookup(const word& keyword) const } -// Find and return T* +// Find and return T*, FatalError if keyword not found template<class IDLListType, class T> -T* DictionaryBase<IDLListType, T>::lookup(const word& keyword) +T* Foam::DictionaryBase<IDLListType, T>::lookup(const word& keyword) { typename HashTable<T*>::iterator iter = hashedTs_.find(keyword); if (iter == hashedTs_.end()) { - // If keyword not found print error message ... FatalErrorIn ( - "DictionaryBase<IDLListType, T>::lookup(const word& keyword)" + "DictionaryBase<IDLListType, T>::lookup(const word&)" ) << keyword << " is undefined" << exit(FatalError); } @@ -137,7 +172,7 @@ T* DictionaryBase<IDLListType, T>::lookup(const word& keyword) // Return the table of contents template<class IDLListType, class T> -wordList DictionaryBase<IDLListType, T>::toc() const +Foam::wordList Foam::DictionaryBase<IDLListType, T>::toc() const { wordList keywords(this->size()); @@ -158,26 +193,28 @@ wordList DictionaryBase<IDLListType, T>::toc() const // Add at head of dictionary template<class IDLListType, class T> -void DictionaryBase<IDLListType, T>::insert(const word& keyword, T* tPtr) +void Foam::DictionaryBase<IDLListType, T>::insert(const word& keyword, T* tPtr) { - IDLListType::insert(tPtr); + // NOTE: we should probably check that HashTable::insert actually worked hashedTs_.insert(keyword, tPtr); + IDLListType::insert(tPtr); } // Add at tail of dictionary template<class IDLListType, class T> -void DictionaryBase<IDLListType, T>::append(const word& keyword, T* tPtr) +void Foam::DictionaryBase<IDLListType, T>::append(const word& keyword, T* tPtr) { - IDLListType::append(tPtr); + // NOTE: we should probably check that HashTable::insert actually worked hashedTs_.insert(keyword, tPtr); + IDLListType::append(tPtr); } template<class IDLListType, class T> -T* DictionaryBase<IDLListType, T>::remove(const word& Keyword) +T* Foam::DictionaryBase<IDLListType, T>::remove(const word& keyword) { - typename HashTable<T*>::iterator iter = hashedTs_.find(Keyword); + typename HashTable<T*>::iterator iter = hashedTs_.find(keyword); if (iter != hashedTs_.end()) { @@ -192,9 +229,8 @@ T* DictionaryBase<IDLListType, T>::remove(const word& Keyword) } -//- Clear the dictionary template<class IDLListType, class T> -void DictionaryBase<IDLListType, T>::clear() +void Foam::DictionaryBase<IDLListType, T>::clear() { IDLListType::clear(); hashedTs_.clear(); @@ -204,7 +240,7 @@ void DictionaryBase<IDLListType, T>::clear() // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class IDLListType, class T> -void DictionaryBase<IDLListType, T>::operator= +void Foam::DictionaryBase<IDLListType, T>::operator= ( const DictionaryBase<IDLListType, T>& dict ) @@ -218,25 +254,11 @@ void DictionaryBase<IDLListType, T>::operator= } IDLListType::operator=(dict); - this->hashedTs_.clear(); - - for - ( - typename IDLListType::iterator iter = this->begin(); - iter != this->end(); - ++iter - ) - { - this->hashedTs_.insert((*iter).keyword(), &(*iter)); - } + this->addEntries(); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "DictionaryBaseIO.C" diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H index 8288cdf5cfbf5f28feddfe19c73bcb3e249a2b34..63566cc4c1e4272352fa833ed1b67104650273e7 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H @@ -29,12 +29,12 @@ Description Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it holds. - The double templating allows for the instantiation of forms with and + The double templating allows for the instantiation of forms with or without storage management. Note The IDLListType parameter should itself be a template but this confused - gcc 2.95.2 so it has to be instantiated for T when an intantiation of + gcc 2.95.2 so it has to be instantiated for T when an instantiation of DictionaryBase is requested See Also @@ -67,7 +67,7 @@ Ostream& operator<<(Ostream&, const DictionaryBase<IDLListType, T>&); /*---------------------------------------------------------------------------*\ - Class DictionaryBase Declaration + Class DictionaryBase Declaration \*---------------------------------------------------------------------------*/ template<class IDLListType, class T> @@ -77,7 +77,7 @@ class DictionaryBase { // Private data - //- HashTable of the enries held on the DL-list for quick lookup + //- HashTable of the entries held on the IDLListType for quick lookup HashTable<T*> hashedTs_; @@ -99,10 +99,10 @@ public: //- Construct from Istream using given Istream constructor class template<class INew> - DictionaryBase(Istream& is, const INew& inewt); + DictionaryBase(Istream&, const INew&); - //- Construct from Istream - DictionaryBase(Istream& is); + //- Construct from Istream using default Istream constructor class + DictionaryBase(Istream&); // Member functions @@ -110,7 +110,13 @@ public: // Search and lookup //- Search DictionaryBase for given keyword - bool found(const word& keyword) const; + bool found(const word&) const; + + //- Find and return an entry if present, otherwise return NULL + const T* lookupPtr(const word&) const; + + //- Find and return an entry if present, otherwise return NULL + T* lookupPtr(const word&); //- Find and return entry const T* lookup(const word&) const; @@ -125,13 +131,14 @@ public: // Editing //- Add at head of dictionary - void insert(const word& keyword, T*); + void insert(const word&, T*); //- Add at tail of dictionary - void append(const word& keyword, T*); + void append(const word&, T*); - //- Remove and return entry specified by keyword - T* remove(const word& keyword); + //- Remove and return entry specified by keyword. + // Return NULL if the keyword was not found. + T* remove(const word&); //- Clear the dictionary void clear(); diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBaseIO.C b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBaseIO.C index 15854c515bf653dcb8a09ee0377dd59585be5673..6af2b1622dcc46f760622704bcfffba39c995b40 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBaseIO.C +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBaseIO.C @@ -30,15 +30,13 @@ Description #include "DictionaryBase.H" #include "IOstreams.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * // template<class IDLListType, class T> -Ostream& operator<<(Ostream& os, const DictionaryBase<IDLListType, T>& dict) +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const DictionaryBase<IDLListType, T>& dict) { for ( @@ -53,7 +51,7 @@ Ostream& operator<<(Ostream& os, const DictionaryBase<IDLListType, T>& dict) if (!os.good()) { Info - << "operator<<(Ostream& os, const DictionaryBase&) : " + << "operator<<(Ostream&, const DictionaryBase&) : " << "Can't write entry for DictionaryBase" << endl; @@ -67,6 +65,4 @@ Ostream& operator<<(Ostream& os, const DictionaryBase<IDLListType, T>& dict) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.C b/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.C index b2b7861eb4f00e3f4bee21689a5f36fc2df18465..4b0a48ac900002db096e6f544e8aa9b742306a97 100644 --- a/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.C +++ b/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.C @@ -26,20 +26,15 @@ License #include "PtrDictionary.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class T> -PtrDictionary<T>::PtrDictionary() +Foam::PtrDictionary<T>::PtrDictionary() {} template<class T> -PtrDictionary<T>::PtrDictionary(const PtrDictionary& dict) +Foam::PtrDictionary<T>::PtrDictionary(const PtrDictionary& dict) : DictionaryBase<DLPtrList<T>, T>(dict) {} @@ -47,14 +42,14 @@ PtrDictionary<T>::PtrDictionary(const PtrDictionary& dict) template<class T> template<class INew> -PtrDictionary<T>::PtrDictionary(Istream& is, const INew& iNew) +Foam::PtrDictionary<T>::PtrDictionary(Istream& is, const INew& iNew) : DictionaryBase<DLPtrList<T>, T>(is, iNew) {} template<class T> -PtrDictionary<T>::PtrDictionary(Istream& is) +Foam::PtrDictionary<T>::PtrDictionary(Istream& is) : DictionaryBase<DLPtrList<T>, T>(is) {} @@ -62,6 +57,4 @@ PtrDictionary<T>::PtrDictionary(Istream& is) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.H b/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.H index 3396236515c1a1ec08ef83318e32532703e9b5e8..9c7da2f4de329a18c8aa06c98041d169a32eb521 100644 --- a/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.H +++ b/src/OpenFOAM/containers/Dictionaries/PtrDictionary/PtrDictionary.H @@ -27,8 +27,10 @@ Class Description Template dictionary class which does not manages the storage - associated with it. It is derived from DictionaryBase instantiated on - a non-memory managed form of intrusive doubly-linked list of T. + associated with it. + + It is derived from DictionaryBase instantiated on a non-memory managed + form of intrusive doubly-linked list of T. SourceFiles PtrDictionary.C @@ -47,7 +49,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class PtrDictionary Declaration + Class PtrDictionary Declaration \*---------------------------------------------------------------------------*/ template<class T> diff --git a/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.C b/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.C index 9712b747351431b59989a0ba9d88a97239fbd773..8f29af262bc361ddef8e5ebc9b25e6887e0c1460 100644 --- a/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.C +++ b/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.C @@ -26,22 +26,15 @@ License #include "UDictionary.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Null constructor template<class T> -UDictionary<T>::UDictionary() +Foam::UDictionary<T>::UDictionary() {} -// Copy constructor template<class T> -UDictionary<T>::UDictionary(const UDictionary& dict) +Foam::UDictionary<T>::UDictionary(const UDictionary& dict) : DictionaryBase<UIDLList<T>, T>(dict) {} @@ -49,6 +42,4 @@ UDictionary<T>::UDictionary(const UDictionary& dict) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.H b/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.H index fb30237d40d91768a8b9ba850bfe51e35ddd98ac..5cc4d301f4e3f2aab7d1558d337111b6ce9077a4 100644 --- a/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.H +++ b/src/OpenFOAM/containers/Dictionaries/UDictionary/UDictionary.H @@ -49,7 +49,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class UDictionary Declaration + Class UDictionary Declaration \*---------------------------------------------------------------------------*/ template<class T> diff --git a/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.C b/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.C index 3a4686fbf6aa659ad4c5e9d8046099de1e7a4ffd..6aa7da72abd4c50cbcca4ca9c2d37cf796f0c6a3 100644 --- a/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.C +++ b/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.C @@ -26,22 +26,15 @@ License #include "UPtrDictionary.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Null constructor template<class T> -UPtrDictionary<T>::UPtrDictionary() +Foam::UPtrDictionary<T>::UPtrDictionary() {} -// Copy constructor template<class T> -UPtrDictionary<T>::UPtrDictionary(const UPtrDictionary& dict) +Foam::UPtrDictionary<T>::UPtrDictionary(const UPtrDictionary& dict) : DictionaryBase<DLList<T*>, T>(dict) {} @@ -49,6 +42,4 @@ UPtrDictionary<T>::UPtrDictionary(const UPtrDictionary& dict) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.H b/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.H index 2caac9efac685a5e5e88658f73edbc897a6e1980..99aee0ac562ce84c04c8ef25b823cca530d9e3b7 100644 --- a/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.H +++ b/src/OpenFOAM/containers/Dictionaries/UPtrDictionary/UPtrDictionary.H @@ -27,8 +27,10 @@ Class Description Template dictionary class which does not manages the storage - associated with it. It is derived from DictionaryBase instantiated on - a non-memory managed form of intrusive doubly-linked list of \<T\>. + associated with it. + + It is derived from DictionaryBase instantiated on a non-memory managed + form of intrusive doubly-linked list of \<T\>. SourceFiles UPtrDictionary.C @@ -47,7 +49,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class UPtrDictionary Declaration + Class UPtrDictionary Declaration \*---------------------------------------------------------------------------*/ template<class T>