STYLE: place HashTable trivial methods in the header (reduce clutter)

This commit is contained in:
Mark Olesen 2022-11-17 15:12:11 +01:00
parent 94c7e180fb
commit 21e7ce8f42
12 changed files with 115 additions and 177 deletions

View File

@ -240,13 +240,8 @@ int main(int argc, char *argv[])
);
argList::addBoolOption
(
"copy-append",
"test move append lists (requires -filter)"
);
argList::addBoolOption
(
"move-append",
"test move append lists (requires -filter)"
"merge",
"test merging lists (requires -filter)"
);
// timeSelector::addOptions();
@ -261,16 +256,10 @@ int main(int argc, char *argv[])
Info<<"limit names: " << matcher << nl;
}
if (args.found("copy-append") && matcher.empty())
if (args.found("merge") && matcher.empty())
{
FatalError
<< nl << "The -copy-append test also requires -filter" << nl
<< exit(FatalError);
}
if (args.found("move-append") && matcher.empty())
{
FatalError
<< nl << "The -move-append test also requires -filter" << nl
<< nl << "The -merge test also requires -filter" << nl
<< exit(FatalError);
}
@ -327,13 +316,9 @@ int main(int argc, char *argv[])
// On last time
if (timeI == timeDirs.size()-1)
{
if (args.found("copy-append"))
if (args.found("merge"))
{
Info<< nl << "Test move append" << nl;
}
else if (args.found("move-append"))
{
Info<< nl << "Test move append" << nl;
Info<< nl << "Test merge" << nl;
}
else
{
@ -349,18 +334,8 @@ int main(int argc, char *argv[])
Info<< "==target==" << nl; reportDetail(objects);
Info<< "==source==" << nl; reportDetail(other);
if (args.found("copy-append"))
{
objects.append(other);
Info<< nl << "After copy-append" << nl;
}
else
{
objects.append(std::move(other));
Info<< nl << "After move-append" << nl;
}
objects.merge(std::move(other));
Info<< nl << "After merge" << nl;
Info<< "==target==" << nl; reportDetail(objects);
Info<< "==source==" << nl; reportDetail(other);

View File

@ -57,16 +57,6 @@ Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
}
template<class T, class Key, class Hash>
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
(
HashPtrTable<T, Key, Hash>&& rhs
)
:
parent_type(std::move(rhs))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>

View File

@ -99,6 +99,12 @@ public:
//- Construct given initial table capacity
inline explicit HashPtrTable(const label size);
//- Copy construct, making a copy of each element
HashPtrTable(const this_type& rhs);
//- Move construct
inline HashPtrTable(this_type&& rhs);
//- Construct from Istream using given Istream constructor class
template<class INew>
HashPtrTable(Istream& is, const INew& inew);
@ -109,12 +115,6 @@ public:
//- Construct from dictionary with default dictionary constructor class
explicit HashPtrTable(const dictionary& dict);
//- Copy construct, making a copy of each element
HashPtrTable(const this_type& rhs);
//- Move construct
HashPtrTable(this_type&& rhs);
//- Destructor
~HashPtrTable();

View File

@ -38,6 +38,16 @@ inline Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const label size)
{}
template<class T, class Key, class Hash>
inline Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
(
HashPtrTable<T, Key, Hash>&& rhs
)
:
parent_type(std::move(rhs))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>

View File

@ -62,8 +62,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef HashSet_H
#define HashSet_H
#ifndef Foam_HashSet_H
#define Foam_HashSet_H
#include "HashTable.H"
#include "IndirectList.H"

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -273,7 +273,7 @@ public:
//- Find and return a hashed entry. FatalError if it does not exist.
inline const T& at(const Key& key) const;
//- Return true if hashed entry is found in table
//- True if hashed key is found in table
inline bool found(const Key& key) const;
//- Find and return an iterator set at the hashed entry
@ -630,39 +630,7 @@ protected:
>::type;
// Member Functions
//- True if iterator points to an entry
// This can be used directly instead of comparing to end()
inline bool good() const noexcept;
//- True if iterator points to an entry - same as good()
inline bool found() const noexcept;
//- The key associated with the iterator
inline const Key& key() const;
//- Write the (key, val) pair
inline Ostream& print(Ostream& os) const;
// Member Operators
//- True if iterator points to an entry
// This can be used directly instead of comparing to end()
explicit inline operator bool() const noexcept;
//- Compare hash-entry element pointers.
// Independent of const/non-const access
template<bool Any>
inline bool operator==(const Iterator<Any>& iter) const noexcept;
template<bool Any>
inline bool operator!=(const Iterator<Any>& iter) const noexcept;
protected:
friend class HashTable; // For begin/find constructors
// Protected Data
@ -680,10 +648,13 @@ protected:
// to mark the position.
label index_;
// Friendship with HashTable, for begin/find constructors
friend class HashTable;
// Protected Constructors
//- Default construct (end iterator)
//- Default construct. Also the same as the end iterator
inline constexpr Iterator() noexcept;
//- Construct from begin of hash-table
@ -704,9 +675,47 @@ protected:
{
return *reinterpret_cast<const Iterator<Any>*>(this);
}
};
public:
// Member Functions
//- True if iterator points to an entry
// This can be used directly instead of comparing to end()
bool good() const noexcept { return entry_; }
//- True if iterator points to an entry - same as good()
bool found() const noexcept { return entry_; }
//- The key associated with the iterator
const Key& key() const { return entry_->key(); }
//- Write the (key, val) pair
inline Ostream& print(Ostream& os) const;
// Member Operators
//- True if iterator points to an entry
// This can be used directly instead of comparing to end()
explicit operator bool() const noexcept { return entry_; }
//- Compare hash-entry element pointers.
// Independent of const/non-const access
template<bool Any>
bool operator==(const Iterator<Any>& iter) const noexcept
{
return (entry_ == iter.entry_);
}
template<bool Any>
bool operator!=(const Iterator<Any>& iter) const noexcept
{
return (entry_ != iter.entry_);
}
};
//- Low-level entry erasure using iterator internals.
// This invalidates the iterator until the next ++ operation.
// \return True if the corresponding entry existed and was removed

View File

@ -36,8 +36,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef HashTableCore_H
#define HashTableCore_H
#ifndef Foam_HashTableCore_H
#define Foam_HashTableCore_H
#include "label.H"
#include "uLabel.H"
@ -66,7 +66,7 @@ struct HashTableCore
ClassName("HashTable");
//- Default construct
HashTableCore() = default;
HashTableCore() noexcept = default;
static_assert
(

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -109,32 +109,6 @@ Foam::HashTable<T, Key, Hash>::Iterator<Const>::increment()
}
template<class T, class Key, class Hash>
template<bool Const>
inline bool
Foam::HashTable<T, Key, Hash>::Iterator<Const>::good() const noexcept
{
return entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
inline bool
Foam::HashTable<T, Key, Hash>::Iterator<Const>::found() const noexcept
{
return entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
inline const Key& Foam::HashTable<T, Key, Hash>::Iterator<Const>::key() const
{
return entry_->key();
}
template<class T, class Key, class Hash>
template<bool Const>
inline Foam::Ostream& Foam::HashTable<T, Key, Hash>::Iterator<Const>::print
@ -150,39 +124,6 @@ inline Foam::Ostream& Foam::HashTable<T, Key, Hash>::Iterator<Const>::print
}
template<class T, class Key, class Hash>
template<bool Const>
inline Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator
bool() const noexcept
{
return entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
template<bool Any>
inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator==
(
const Iterator<Any>& iter
) const noexcept
{
return entry_ == iter.entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
template<bool Any>
inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator!=
(
const Iterator<Any>& iter
) const noexcept
{
return entry_ != iter.entry_;
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>

View File

@ -40,8 +40,8 @@ See also
\*---------------------------------------------------------------------------*/
#ifndef Map_H
#define Map_H
#ifndef Foam_Map_H
#define Foam_Map_H
#include "HashTable.H"
@ -103,7 +103,7 @@ public:
parent_type(std::move(map))
{}
//- Construct from an initializer list
//- Construct from pairs of values
Map(std::initializer_list<std::pair<label, T>> map)
:
parent_type(map)

View File

@ -35,8 +35,8 @@ See also
\*---------------------------------------------------------------------------*/
#ifndef PtrMap_H
#define PtrMap_H
#ifndef Foam_PtrMap_H
#define Foam_PtrMap_H
#include "HashPtrTable.H"

View File

@ -189,23 +189,28 @@ const Foam::IOobject* Foam::IOobjectList::cfindObject
const word& objName
) const
{
const_iterator iter = cfind(objName);
// Like HashPtrTable::get(), or lookup() with a nullptr
const IOobject* io = nullptr;
if (iter.found())
const const_iterator iter(cfind(objName));
if (iter.good())
{
if (IOobject::debug)
io = iter.val();
}
if (IOobject::debug)
{
if (io)
{
InfoInFunction << "Found " << objName << endl;
}
return iter.val();
}
else if (IOobject::debug)
{
InfoInFunction << "Could not find " << objName << endl;
else
{
InfoInFunction << "Could not find " << objName << endl;
}
}
return nullptr;
return io;
}

View File

@ -308,30 +308,38 @@ const Foam::IOobject* Foam::IOobjectList::cfindObject
const word& objName
) const
{
const_iterator iter = cfind(objName);
// Like HashPtrTable::get(), or lookup() with a nullptr
const IOobject* io = nullptr;
if (iter.found())
const const_iterator iter(cfind(objName));
if (iter.good())
{
const IOobject* io = iter.val();
io = iter.val();
}
if (io->isHeaderClass<Type>())
if (IOobject::debug)
{
if (io)
{
if (IOobject::debug)
if (io->isHeaderClass<Type>())
{
InfoInFunction << "Found " << objName << endl;
}
return io;
else
{
InfoInFunction << "Found " << objName
<< " with different type" << endl;
}
}
else if (IOobject::debug)
else
{
InfoInFunction
<< "Found " << objName << " of different type" << endl;
InfoInFunction << "Could not find " << objName << endl;
}
}
else if (IOobject::debug)
if (io && io->isHeaderClass<Type>())
{
InfoInFunction << "Could not find " << objName << endl;
return io;
}
return nullptr;