ENH: expose HashTable iterator object() methods

- to the referenced object via a method name, which may be clearer
  than deferencing the iterator

     [key, value] =>  iter.key(), *iter
     [key, value] =>  iter.key(), iter()
     [key, value] =>  iter.key(), iter.object()
This commit is contained in:
Mark Olesen
2017-01-26 18:11:02 +01:00
parent 2b9b2dd865
commit de5688e095
2 changed files with 17 additions and 14 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -49,6 +49,8 @@ int main()
{"aec", 10.0} {"aec", 10.0}
}; };
// Info<< "\ntable1: " << table1<< endl;
// Erase by key // Erase by key
table1.erase("aaw"); table1.erase("aaw");
@ -60,7 +62,7 @@ int main()
Info<< "\ntable1 sortedToc: " << table1.sortedToc() << endl; Info<< "\ntable1 sortedToc: " << table1.sortedToc() << endl;
table1.printInfo(Info) table1.printInfo(Info)
<< "table1 [" << table1.size() << "] " << endl; << "table1 [" << table1.size() << "] " << endl;
forAllIter(HashTable<scalar>, table1, iter) forAllConstIter(HashTable<scalar>, table1, iter)
{ {
Info<< iter.key() << " => " << iter() << nl; Info<< iter.key() << " => " << iter() << nl;
} }
@ -106,7 +108,7 @@ int main()
Info<< "\nerase table2 by iterator" << nl; Info<< "\nerase table2 by iterator" << nl;
forAllIter(HashTable<scalar>, table2, iter) forAllIter(HashTable<scalar>, table2, iter)
{ {
Info<< "erasing " << iter.key() << " => " << iter() << " ... "; Info<< "erasing " << iter.key() << " => " << iter.object() << " ... ";
table2.erase(iter); table2.erase(iter);
Info<< "erased" << endl; Info<< "erased" << endl;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -144,10 +144,10 @@ class HashTable
private: private:
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
hashedEntry(const hashedEntry&); hashedEntry(const hashedEntry&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const hashedEntry&); void operator=(const hashedEntry&) = delete;
}; };
@ -400,10 +400,6 @@ public:
//- Return non-const access to referenced object //- Return non-const access to referenced object
inline T& object(); inline T& object();
//- Return const access to referenced object
inline const T& cobject() const;
public: public:
// Member operators // Member operators
@ -413,6 +409,9 @@ public:
//- Return the Key corresponding to the iterator //- Return the Key corresponding to the iterator
inline const Key& key() const; inline const Key& key() const;
//- Return const access to referenced object
inline const T& cobject() const;
//- Compare hashedEntry element pointers //- Compare hashedEntry element pointers
inline bool operator==(const iteratorBase&) const; inline bool operator==(const iteratorBase&) const;
inline bool operator!=(const iteratorBase&) const; inline bool operator!=(const iteratorBase&) const;
@ -460,11 +459,14 @@ public:
// Member operators // Member operators
//- Return referenced hash value //- Return non-const access to referenced object
using iteratorBase::object;
//- Return non-const access to referenced object
inline T& operator*(); inline T& operator*();
inline T& operator()(); inline T& operator()();
//- Return referenced hash value //- Return const access to referenced object
inline const T& operator*() const; inline const T& operator*() const;
inline const T& operator()() const; inline const T& operator()() const;
@ -518,13 +520,12 @@ public:
// Member operators // Member operators
//- Return referenced hash value //- Return const access to referenced object
inline const T& operator*() const; inline const T& operator*() const;
inline const T& operator()() const; inline const T& operator()() const;
inline const_iterator& operator++(); inline const_iterator& operator++();
inline const_iterator operator++(int); inline const_iterator operator++(int);
}; };