From c6e9b323f513f38624e23b47b49de01b675c0776 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 27 Jan 2009 21:55:03 +0100 Subject: [PATCH] added HashSet::operator[]() const - can use the same syntax for boolList, PackedBoolList and labelHashSet if (myHashedSet[x]) ... if (myBoolList[x]) ... if (myPackedList[x]) ... --- applications/test/HashSet/hashSetTest.C | 27 +++++++++++++++++++ .../containers/HashTables/HashSet/HashSet.C | 7 +++++ .../containers/HashTables/HashSet/HashSet.H | 4 ++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/applications/test/HashSet/hashSetTest.C b/applications/test/HashSet/hashSetTest.C index 9625b2e0dc..21e1276604 100644 --- a/applications/test/HashSet/hashSetTest.C +++ b/applications/test/HashSet/hashSetTest.C @@ -111,6 +111,33 @@ int main(int argc, char *argv[]) Info<< "setD : " << setD << endl; Info<< "setB ^ setC ^ setD : " << (setB ^ setC ^ setD) << endl; + // test operator[] + + Info<< "setD : " << setD << endl; + if (setD[0]) + { + Info<< "setD has 0" << endl; + } + else + { + Info<< "setD has no 0" << endl; + } + + + if (setD[11]) + { + Info<< "setD has 11" << endl; + } + else + { + Info<< "setD has no 0" << endl; + } + + Info<< "setD : " << setD << endl; + + // this doesn't work (yet?) + // setD[12] = true; + return 0; } diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C index 2136916780..6bf84e0c55 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C @@ -51,6 +51,13 @@ Foam::HashSet::HashSet(const HashTable& ht) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +template +inline bool Foam::HashSet::operator[](const Key& key) const +{ + return found(key); +} + + template bool Foam::HashSet::operator==(const HashSet& rhs) const { diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index fbe0baf785..9a4c5951be 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -133,9 +133,11 @@ public: return HashTable::insert(key, nil()); } - // Member Operators + //- Return true if the entry exists, same as found() + inline bool operator[](const Key&) const; + //- Equality. Two hashtables are equal when their contents are equal. // Independent of table size or order. bool operator==(const HashSet&) const;