diff --git a/applications/test/HashTable/Test-hashTable.C b/applications/test/HashTable/Test-hashTable.C index 173356b238e66f44f2935932849b9a56fd891909..8352a88ae0c05615b0fff10cd6198a7f6fc50b0b 100644 --- a/applications/test/HashTable/Test-hashTable.C +++ b/applications/test/HashTable/Test-hashTable.C @@ -25,6 +25,8 @@ License #include "HashTable.H" #include "List.H" +#include "SortableList.H" +#include "DynamicList.H" #include "FlatOutput.H" #include "IOstreams.H" #include "IStringStream.H" @@ -194,7 +196,24 @@ int main() // These do not yet work. Issues resolving the distance. // // List<scalar> table1vals(table1.begin(), table1.end()); - // wordList table1keys(table1.begin(), table1.end()); + + { + Info<<"distance/size: " + << std::distance(table1.begin(), table1.end()) + << "/" << table1.size() + << " and " + << std::distance(table1.keys().begin(), table1.keys().end()) + << "/" << table1.keys().size() + << nl; + + SortableList<word> sortKeys + // DynamicList<word> sortKeys + ( + table1.keys().begin(), + table1.keys().end() + ); + Info<<"sortKeys: " << flatOutput(sortKeys) << nl; + } Info<< "\nFrom table1: " << flatOutput(table1.sortedToc()) << nl << "retain keys: " << flatOutput(table3.sortedToc()) << nl; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 53cf8da553b2708349da02f212e71f484c950734..3ba008d557505d42b6bf90b8c0a94613cbcc03d0 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -61,6 +61,7 @@ SourceFiles #include "nullObject.H" #include <initializer_list> +#include <iterator> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -179,10 +180,17 @@ public: //- Type of values that the HashTable contains. typedef T value_type; + //- The type used for storing into value_type objects. + // This type is usually value_type&. + typedef T* pointer; + //- The type used for storing into value_type objects. // This type is usually value_type&. typedef T& reference; + //- The type used for reading from constant value_type objects. + typedef const T* const_pointer; + //- The type used for reading from constant value_type objects. typedef const T& const_reference; @@ -441,6 +449,7 @@ protected: // Public typedefs using table_type = this_type; using key_type = this_type::key_type; + using iterator_category = std::forward_iterator_tag; using difference_type = this_type::difference_type; private: @@ -518,16 +527,20 @@ public: public WrappedIterator { public: + using value_type = this_type::key_type; + using pointer = const Key*; using reference = const Key&; - using difference_type = typename WrappedIterator::difference_type; //- Implicit conversion inline key_iterator_base(const WrappedIterator& iter); //- Return the key inline reference operator*() const; - }; + inline reference operator()() const; + inline key_iterator_base& operator++(); + inline key_iterator_base operator++(int); + }; // STL iterator @@ -544,9 +557,9 @@ public: // Public typedefs using table_type = this_type; - using key_type = this_type::key_type; + using value_type = this_type::value_type; + using pointer = this_type::pointer; using reference = this_type::reference; - using difference_type = typename iterator_base::difference_type; // Constructors @@ -592,9 +605,9 @@ public: // Public typedefs using table_type = const this_type; - using key_type = this_type::key_type; + using value_type = const this_type::value_type; + using pointer = this_type::const_pointer; using reference = this_type::const_reference; - using difference_type = typename iterator_base::difference_type; // Constructors diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H index 5391ca78b19c3c195c154938766ae85dadfd2a95..4d8028ca139e61ecd8a0d880d156e6888c199471 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H @@ -363,6 +363,39 @@ Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator> } +template<class T, class Key, class Hash> +template<class WrappedIterator> +inline const Key& +Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator> +::operator()() const +{ + return this->key(); +} + + +template<class T, class Key, class Hash> +template<class WrappedIterator> +inline Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>& +Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator> +::operator++() +{ + this->increment(); + return *this; +} + + +template<class T, class Key, class Hash> +template<class WrappedIterator> +inline Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator> +Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator> +::operator++(int) +{ + key_iterator_base old = *this; + this->increment(); + return old; +} + + // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * // template<class T, class Key, class Hash>