/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \*---------------------------------------------------------------------------*/ #include "error.H" #include "IOstreams.H" // * * * * * * * * * * * * * Private Member Classes * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template inline Foam::label Foam::StaticHashTable::size() const { return nElmts_; } template inline bool Foam::StaticHashTable::empty() const { return !nElmts_; } template inline bool Foam::StaticHashTable::insert ( const Key& key, const T& newEntry ) { return set(key, newEntry, true); } template inline bool Foam::StaticHashTable::set ( const Key& key, const T& newEntry ) { return set(key, newEntry, false); } template inline Foam::Xfer > Foam::StaticHashTable::xfer() { return xferMove(*this); } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template inline T& Foam::StaticHashTable::operator[](const Key& key) { iterator iter = find(key); if (iter == end()) { FatalErrorIn("StaticHashTable::operator[](const Key&)") << key << " not found in table. Valid entries: " << toc() << exit(FatalError); } return *iter; } template inline const T& Foam::StaticHashTable::operator[] ( const Key& key ) const { const_iterator iter = find(key); if (iter == end()) { FatalErrorIn ( "StaticHashTable::operator[](const Key&) const" ) << key << " not found in table. Valid entries: " << toc() << exit(FatalError); } return *iter; } template inline T& Foam::StaticHashTable::operator()(const Key& key) { iterator iter = find(key); if (iter == end()) { insert(key, T()); return *find(key); } else { return *iter; } } // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * // template template inline Foam::StaticHashTable::Iterator::Iterator ( TableRef curHashTable, label hashIndex, label elementIndex ) : curHashTable_(curHashTable), hashIndex_(hashIndex), elementIndex_(elementIndex) {} template template inline Foam::StaticHashTable::Iterator::Iterator ( const iterator& iter ) : curHashTable_(iter.curHashTable_), hashIndex_(iter.hashIndex_), elementIndex_(iter.elementIndex_) {} template template inline void Foam::StaticHashTable::Iterator::operator= ( const iterator& iter ) { this->hashIndex_ = iter.hashIndex_; this->elementIndex_ = iter.elementIndex_; } template template inline bool Foam::StaticHashTable::Iterator::operator== ( const iterator& iter ) const { return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_; } template template inline bool Foam::StaticHashTable::Iterator::operator== ( const const_iterator& iter ) const { return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_; } template template inline bool Foam::StaticHashTable::Iterator::operator!= ( const iterator& iter ) const { return !operator==(iter); } template template inline bool Foam::StaticHashTable::Iterator::operator!= ( const const_iterator& iter ) const { return !operator==(iter); } template template inline TRef Foam::StaticHashTable::Iterator::operator*() { return curHashTable_.objects_[hashIndex_][elementIndex_]; } template template inline TRef Foam::StaticHashTable::Iterator::operator()() { return operator*(); } template template inline typename Foam::StaticHashTable::template Iterator < TRef, TableRef >& Foam::StaticHashTable::Iterator < TRef, TableRef >::operator++() { // Check for special value from erase. (sets hashIndex to -1) if (hashIndex_ >= 0) { // Try the next element on the local list elementIndex_++; if (elementIndex_ < curHashTable_.objects_[hashIndex_].size()) { return *this; } } // Step to the next table entry elementIndex_ = 0; while ( ++hashIndex_ < curHashTable_.objects_.size() && !curHashTable_.objects_[hashIndex_].size() ) {} if (hashIndex_ >= curHashTable_.objects_.size()) { // make end iterator hashIndex_ = curHashTable_.keys_.size(); } return *this; } template template inline typename Foam::StaticHashTable::template Iterator < TRef, TableRef > Foam::StaticHashTable::Iterator < TRef, TableRef >::operator++ ( int ) { iterator tmp = *this; ++*this; return tmp; } template template inline const Key& Foam::StaticHashTable::Iterator::key() { return curHashTable_.keys_[hashIndex_][elementIndex_]; } template inline typename Foam::StaticHashTable::iterator Foam::StaticHashTable::begin() { // Find first non-empty entry forAll(keys_, hashIdx) { if (keys_[hashIdx].size()) { return iterator(*this, hashIdx, 0); } } # ifdef FULLDEBUG if (debug) { Info<< "StaticHashTable is empty\n"; } # endif return StaticHashTable::endIter_; } template inline const typename Foam::StaticHashTable::iterator& Foam::StaticHashTable::end() { return StaticHashTable::endIter_; } template inline typename Foam::StaticHashTable::const_iterator Foam::StaticHashTable::cbegin() const { // Find first non-empty entry forAll(keys_, hashIdx) { if (keys_[hashIdx].size()) { return const_iterator(*this, hashIdx, 0); } } # ifdef FULLDEBUG if (debug) { Info<< "StaticHashTable is empty\n"; } # endif return StaticHashTable::endConstIter_; } template inline const typename Foam::StaticHashTable::const_iterator& Foam::StaticHashTable::cend() const { return StaticHashTable::endConstIter_; } template inline typename Foam::StaticHashTable::const_iterator Foam::StaticHashTable::begin() const { return this->cbegin(); } template inline const typename Foam::StaticHashTable::const_iterator& Foam::StaticHashTable::end() const { return StaticHashTable::endConstIter_; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // ************************************************************************* //