From f0341171ff7222c3b698c88ba8d3e75395ff0ff0 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Fri, 9 Jan 2009 13:10:10 +0100 Subject: [PATCH] renamed 'empty' class to 'nil', added missing empty() member to some containers --- applications/test/HashSet/hashSetTest.C | 10 +++--- .../containers/HashTables/HashSet/HashSet.C | 2 +- .../containers/HashTables/HashSet/HashSet.H | 28 ++++++++-------- .../HashTables/HashTable/HashTable.H | 3 ++ .../HashTables/HashTable/HashTableI.H | 7 ++++ .../StaticHashTable/StaticHashTable.H | 3 ++ .../StaticHashTable/StaticHashTableI.H | 7 ++++ .../linkTypes/DLListBase/DLListBase.H | 3 ++ .../linkTypes/DLListBase/DLListBaseI.H | 6 ++++ .../linkTypes/SLListBase/SLListBase.H | 3 ++ .../linkTypes/SLListBase/SLListBaseI.H | 6 ++++ .../containers/LinkedLists/user/FIFOStack.H | 9 ----- .../containers/LinkedLists/user/LIFOStack.H | 9 ----- .../Lists/BiIndirectList/BiIndirectList.H | 2 ++ .../Lists/BiIndirectList/BiIndirectListI.H | 7 ++++ .../Lists/CompactListList/CompactListList.H | 3 ++ .../Lists/CompactListList/CompactListListI.H | 7 ++++ .../Lists/IndirectList/IndirectList.H | 2 ++ .../Lists/IndirectList/IndirectListI.H | 7 ++++ .../containers/Lists/PackedList/PackedList.H | 3 ++ .../containers/Lists/PackedList/PackedListI.H | 7 ++++ .../containers/Lists/PtrList/PtrList.H | 3 ++ .../containers/Lists/PtrList/PtrListI.H | 7 ++++ .../primitives/{empty/empty.H => nil/nil.H} | 33 ++++++++----------- 24 files changed, 120 insertions(+), 57 deletions(-) rename src/OpenFOAM/primitives/{empty/empty.H => nil/nil.H} (80%) diff --git a/applications/test/HashSet/hashSetTest.C b/applications/test/HashSet/hashSetTest.C index a3527f7dd76..9625b2e0dc6 100644 --- a/applications/test/HashSet/hashSetTest.C +++ b/applications/test/HashSet/hashSetTest.C @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) wordHashSet setA(0); HashTable<label, word> tableA; - HashTable<empty> tableB; + HashTable<nil> tableB; Map<label> mapA; setA.insert("kjhk"); @@ -49,9 +49,9 @@ int main(int argc, char *argv[]) tableA.insert("value2", 2); tableA.insert("value3", 3); - tableB.insert("value4", empty()); - tableB.insert("value5", empty()); - tableB.insert("value6", empty()); + tableB.insert("value4", nil()); + tableB.insert("value5", nil()); + tableB.insert("value6", nil()); mapA.set(1, 1); mapA.set(2, 2); @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) Info<< wordHashSet(setA) << endl; Info<< "create from HashTable<T>: "; Info<< wordHashSet(tableA) << endl; - Info<< "create from HashTable<empty>: "; + Info<< "create from HashTable<nil>: "; Info<< wordHashSet(tableB) << endl; Info<< "create from Map<label>: "; diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C index 3e4123ae4f9..b741bd2b0b5 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C @@ -35,7 +35,7 @@ template<class Key, class Hash> template<class T> Foam::HashSet<Key, Hash>::HashSet(const HashTable<T, Key, Hash>& ht) : - HashTable<empty, Key, Hash>(ht.size()) + HashTable<nil, Key, Hash>(ht.size()) { for ( diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index 889ede7a7da..0ea8f8c6460 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -46,7 +46,7 @@ Description #define HashSet_H #include "HashTable.H" -#include "empty.H" +#include "nil.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -60,13 +60,13 @@ namespace Foam template<class Key=word, class Hash=string::hash> class HashSet : - public HashTable<empty, Key, Hash> + public HashTable<nil, Key, Hash> { public: - typedef typename HashTable<empty, Key, Hash>::iterator iterator; - typedef typename HashTable<empty, Key, Hash>::const_iterator const_iterator; + typedef typename HashTable<nil, Key, Hash>::iterator iterator; + typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator; // Constructors @@ -74,19 +74,19 @@ public: //- Construct given initial size HashSet(label size = 100) : - HashTable<empty, Key, Hash>(size) + HashTable<nil, Key, Hash>(size) {} //- Construct from Istream HashSet(Istream& is) : - HashTable<empty, Key, Hash>(is) + HashTable<nil, Key, Hash>(is) {} //- Construct from UList of Key HashSet(const UList<Key>& lst) : - HashTable<empty, Key, Hash>(2*lst.size()) + HashTable<nil, Key, Hash>(2*lst.size()) { forAll(lst, i) { @@ -97,19 +97,19 @@ public: //- Construct as copy HashSet(const HashSet<Key, Hash>& hs) : - HashTable<empty, Key, Hash>(hs) + HashTable<nil, Key, Hash>(hs) {} //- Construct by transferring the parameter contents HashSet(const Xfer<HashSet<Key, Hash> >& hs) : - HashTable<empty, Key, Hash>(hs) + HashTable<nil, Key, Hash>(hs) {} //- Construct by transferring the parameter contents - HashSet(const Xfer<HashTable<empty, Key, Hash> >& hs) + HashSet(const Xfer<HashTable<nil, Key, Hash> >& hs) : - HashTable<empty, Key, Hash>(hs) + HashTable<nil, Key, Hash>(hs) {} //- Construct from table of contents of the HashTable @@ -123,13 +123,13 @@ public: //- Insert a new entry bool insert(const Key& key) { - return HashTable<empty, Key, Hash>::insert(key, empty()); + return HashTable<nil, Key, Hash>::insert(key, nil()); } - //- Same as insert (cannot overwrite empty content) + //- Same as insert (cannot overwrite nil content) bool set(const Key& key) { - return HashTable<empty, Key, Hash>::insert(key, empty()); + return HashTable<nil, Key, Hash>::insert(key, nil()); } diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 0ecc044222e..47cbc6b4c92 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -171,6 +171,9 @@ public: //- Return number of elements in table. inline label size() const; + //- Return true if the hash table is empty + inline bool empty() const; + //- Return true if hashedEntry is found in table bool found(const Key&) const; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H index 8762d12a9a2..03359b2fd10 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H @@ -51,6 +51,13 @@ inline Foam::label Foam::HashTable<T, Key, Hash>::size() const } +template<class T, class Key, class Hash> +inline bool Foam::HashTable<T, Key, Hash>::empty() const +{ + return (nElmts_ == 0); +} + + template<class T, class Key, class Hash> inline bool Foam::HashTable<T, Key, Hash>::insert ( diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H index 15044c33e21..2816056383e 100644 --- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H +++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H @@ -164,6 +164,9 @@ public: //- Return number of elements in table. inline label size() const; + //- Return true if the hash table is empty + inline bool empty() const; + //- Return true if hashed entry is found in table bool found(const Key& key) const; diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H index 104cbbf3feb..93317105a82 100644 --- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H +++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H @@ -38,6 +38,13 @@ inline Foam::label Foam::StaticHashTable<T, Key, Hash>::size() const } +template<class T, class Key, class Hash> +inline bool Foam::StaticHashTable<T, Key, Hash>::empty() const +{ + return (nElmts_ == 0); +} + + template<class T, class Key, class Hash> inline bool Foam::StaticHashTable<T, Key, Hash>::insert ( diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H index 33d55e31862..475109cc771 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H @@ -122,6 +122,9 @@ public: //- Return number of elements in list inline label size() const; + //- Return true if the list is empty + inline bool empty() const; + //- Return first entry inline link* first(); diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H index e30902ce505..6692ce5c525 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H @@ -81,6 +81,12 @@ inline Foam::label Foam::DLListBase::size() const } +inline bool Foam::DLListBase::empty() const +{ + return (nElmts_ == 0); +} + + inline Foam::DLListBase::link* Foam::DLListBase::first() { diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H index 4102dee3366..06f5960faec 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H @@ -119,6 +119,9 @@ public: //- Return number of elements in list inline label size() const; + //- Return true if the list is empty + inline bool empty() const; + //- Return first entry inline link* first(); diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H index 2d84028e6c5..ca069a239d7 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H @@ -71,6 +71,12 @@ inline Foam::label Foam::SLListBase::size() const } +inline bool Foam::SLListBase::empty() const +{ + return (nElmts_ == 0); +} + + inline Foam::SLListBase::link* Foam::SLListBase::first() { diff --git a/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H b/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H index 04a6791f244..a07b94cbcc5 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H +++ b/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H @@ -92,15 +92,6 @@ public: } - // Check - - //- Is the stack empty - bool empty() const - { - return this->size() == 0; - } - - // Edit //- Push an element onto the stack diff --git a/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H b/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H index b8bcde265cf..9e60f35f772 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H +++ b/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H @@ -92,15 +92,6 @@ public: } - // Check - - //- Is the stack empty - bool empty() const - { - return this->size() == 0; - } - - // Edit //- Push an element onto the stack diff --git a/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H b/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H index 6e60d13d8af..a7827ec6cb3 100644 --- a/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H +++ b/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H @@ -75,6 +75,8 @@ public: // Access inline label size() const; + inline bool empty() const; + inline const UList<T>& posList() const; inline const UList<T>& negList() const; inline const List<label>& addressing() const; diff --git a/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectListI.H b/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectListI.H index 8425cb980d3..b30769d107b 100644 --- a/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectListI.H +++ b/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectListI.H @@ -49,6 +49,13 @@ inline Foam::label Foam::BiIndirectList<T>::size() const } +template<class T> +inline bool Foam::BiIndirectList<T>::empty() const +{ + return addressing_.empty(); +} + + template<class T> inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const { diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H index 91a6729706d..7cf9e316696 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H @@ -126,6 +126,9 @@ public: //- Return the primary size, i.e. the number of rows inline label size() const; + //- Return true if the number of rows is zero + inline bool empty() const; + //- Return the offset table inline const List<label>& offsets() const; diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H index 851609ba7c2..e2e794356eb 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H @@ -74,6 +74,13 @@ inline Foam::label Foam::CompactListList<T>::size() const } +template<class T> +inline bool Foam::CompactListList<T>::empty() const +{ + return offsets_.empty(); +} + + template<class T> inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const { diff --git a/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H b/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H index 18affc9d064..776d7b65db7 100644 --- a/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H +++ b/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H @@ -69,6 +69,8 @@ public: // Access inline label size() const; + inline bool empty() const; + inline const UList<T>& completeList() const; inline const List<label>& addressing() const; diff --git a/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H b/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H index 94a8bbf4b3b..0ae5311d97f 100644 --- a/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H +++ b/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H @@ -47,6 +47,13 @@ inline Foam::label Foam::IndirectList<T>::size() const } +template<class T> +inline bool Foam::IndirectList<T>::empty() const +{ + return addressing_.empty(); +} + + template<class T> inline const Foam::UList<T>& Foam::IndirectList<T>::completeList() const { diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index ea75d13eda2..d2d015ad566 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -166,6 +166,9 @@ public: //- Number of packed elements inline label size() const; + //- Return true if the list is empty (i.e., if size() == 0). + inline bool empty() const; + //- Get value at index I inline unsigned int get(const label i) const; diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index 809ae08ab5f..dc5f18786e8 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -117,6 +117,13 @@ inline Foam::label Foam::PackedList<nBits>::size() const } +template<int nBits> +inline bool Foam::PackedList<nBits>::empty() const +{ + return (size_ == 0); +} + + // Get value at i template<int nBits> inline unsigned int Foam::PackedList<nBits>::get(const label i) const diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H index b90f0f0b6f8..86c7ea8f4d8 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H @@ -158,6 +158,9 @@ public: //- Return the number of elements in the PtrList inline label size() const; + //- Return true if the PtrList is empty (i.e., if size() == 0). + inline bool empty() const; + // Edit diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H index fe983406cfa..8dfbe2686ab 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H @@ -38,6 +38,13 @@ inline Foam::label Foam::PtrList<T>::size() const } +template<class T> +inline bool Foam::PtrList<T>::empty() const +{ + return ptrs_.empty(); +} + + template<class T> inline bool Foam::PtrList<T>::set(const label i) const { diff --git a/src/OpenFOAM/primitives/empty/empty.H b/src/OpenFOAM/primitives/nil/nil.H similarity index 80% rename from src/OpenFOAM/primitives/empty/empty.H rename to src/OpenFOAM/primitives/nil/nil.H index ba1628421c8..c6fd97eaaf3 100644 --- a/src/OpenFOAM/primitives/empty/empty.H +++ b/src/OpenFOAM/primitives/nil/nil.H @@ -23,20 +23,15 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::empty + Foam::nil Description - A class without storage. Used, for example, in HashSet. - -SourceFiles - emptyI.H - empty.C - emptyIO.C + A class without any storage. Used, for example, in HashSet. \*---------------------------------------------------------------------------*/ -#ifndef empty_H -#define empty_H +#ifndef nil_H +#define nil_H // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,17 +44,17 @@ class Ostream; // Forward declaration of friend functions and operators -class empty; +class nil; -Istream& operator>>(Istream& is, empty&); -Ostream& operator<<(Ostream& os, const empty&); +Istream& operator>>(Istream&, nil&); +Ostream& operator<<(Ostream&, const nil&); /*---------------------------------------------------------------------------*\ - Class empty Declaration + Class nil Declaration \*---------------------------------------------------------------------------*/ -class empty +class nil { public: @@ -67,22 +62,22 @@ public: // Constructors //- Construct null - empty() + nil() {} //- Construct from Istream - empty(Istream&) + nil(Istream&) {} - // IOstream Operator + // IOstream Operators - friend Istream& operator>>(Istream& is, empty&) + friend Istream& operator>>(Istream& is, nil&) { return is; } - friend Ostream& operator<<(Ostream& os, const empty&) + friend Ostream& operator<<(Ostream& os, const nil&) { return os; } -- GitLab