/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ 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 3 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, see . \*---------------------------------------------------------------------------*/ #include "DictionaryBase.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template void Foam::DictionaryBase::addEntries() { for ( typename IDLListType::iterator iter = this->begin(); iter != this->end(); ++iter ) { this->hashedTs_.insert((*iter).keyword(), &(*iter)); } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::DictionaryBase::DictionaryBase(const label size) : hashedTs_(size) {} template Foam::DictionaryBase::DictionaryBase ( const DictionaryBase& dict ) : IDLListType(dict) { addEntries(); } template Foam::DictionaryBase::DictionaryBase ( DictionaryBase&& dict ) : IDLListType(move(dict)), hashedTs_(move(dict.hashedTs_)) {} template template Foam::DictionaryBase::DictionaryBase ( Istream& is, const INew& iNew ) : IDLListType(is, iNew) { addEntries(); } template Foam::DictionaryBase::DictionaryBase(Istream& is) : IDLListType(is) { addEntries(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template bool Foam::DictionaryBase::found(const word& keyword) const { return hashedTs_.found(keyword); } template const T* Foam::DictionaryBase::lookupPtr ( const word& keyword ) const { typename HashTable::const_iterator iter = hashedTs_.find(keyword); if (iter != hashedTs_.end()) { return *iter; } else { return nullptr; } } template T* Foam::DictionaryBase::lookupPtr(const word& keyword) { typename HashTable::iterator iter = hashedTs_.find(keyword); if (iter != hashedTs_.end()) { return *iter; } else { return nullptr; } } template const T* Foam::DictionaryBase::lookup(const word& keyword) const { typename HashTable::const_iterator iter = hashedTs_.find(keyword); if (iter == hashedTs_.end()) { FatalErrorInFunction << keyword << " is undefined" << exit(FatalError); } return *iter; } template T* Foam::DictionaryBase::lookup(const word& keyword) { typename HashTable::iterator iter = hashedTs_.find(keyword); if (iter == hashedTs_.end()) { FatalErrorInFunction << keyword << " is undefined" << exit(FatalError); } return *iter; } template Foam::wordList Foam::DictionaryBase::toc() const { wordList keywords(this->size()); label i = 0; for ( typename IDLListType::const_iterator iter = this->begin(); iter != this->end(); ++iter ) { keywords[i++] = iter().keyword(); } return keywords; } template Foam::wordList Foam::DictionaryBase::sortedToc() const { return hashedTs_.sortedToc(); } template void Foam::DictionaryBase::insert(const word& keyword, T* tPtr) { // NOTE: we should probably check that HashTable::insert actually worked hashedTs_.insert(keyword, tPtr); IDLListType::insert(tPtr); } template void Foam::DictionaryBase::append(const word& keyword, T* tPtr) { // NOTE: we should probably check that HashTable::insert actually worked hashedTs_.insert(keyword, tPtr); IDLListType::append(tPtr); } template T* Foam::DictionaryBase::remove(const word& keyword) { typename HashTable::iterator iter = hashedTs_.find(keyword); if (iter != hashedTs_.end()) { T* tPtr = IDLListType::remove(iter()); hashedTs_.erase(iter); return tPtr; } else { return nullptr; } } template void Foam::DictionaryBase::clear() { IDLListType::clear(); hashedTs_.clear(); } template void Foam::DictionaryBase::transfer ( DictionaryBase& dict ) { IDLListType::transfer(dict); hashedTs_.transfer(dict.hashedTs_); } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template void Foam::DictionaryBase::operator= ( const DictionaryBase& dict ) { // Check for assignment to self if (this == &dict) { FatalErrorInFunction << "attempted assignment to self" << abort(FatalError); } IDLListType::operator=(dict); this->hashedTs_.clear(); this->addEntries(); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "DictionaryBaseIO.C" // ************************************************************************* //