mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: place HashTable trivial methods in the header (reduce clutter)
This commit is contained in:
@ -240,13 +240,8 @@ int main(int argc, char *argv[])
|
|||||||
);
|
);
|
||||||
argList::addBoolOption
|
argList::addBoolOption
|
||||||
(
|
(
|
||||||
"copy-append",
|
"merge",
|
||||||
"test move append lists (requires -filter)"
|
"test merging lists (requires -filter)"
|
||||||
);
|
|
||||||
argList::addBoolOption
|
|
||||||
(
|
|
||||||
"move-append",
|
|
||||||
"test move append lists (requires -filter)"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// timeSelector::addOptions();
|
// timeSelector::addOptions();
|
||||||
@ -261,16 +256,10 @@ int main(int argc, char *argv[])
|
|||||||
Info<<"limit names: " << matcher << nl;
|
Info<<"limit names: " << matcher << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.found("copy-append") && matcher.empty())
|
if (args.found("merge") && matcher.empty())
|
||||||
{
|
{
|
||||||
FatalError
|
FatalError
|
||||||
<< nl << "The -copy-append test also requires -filter" << nl
|
<< nl << "The -merge test also requires -filter" << nl
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
if (args.found("move-append") && matcher.empty())
|
|
||||||
{
|
|
||||||
FatalError
|
|
||||||
<< nl << "The -move-append test also requires -filter" << nl
|
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,13 +316,9 @@ int main(int argc, char *argv[])
|
|||||||
// On last time
|
// On last time
|
||||||
if (timeI == timeDirs.size()-1)
|
if (timeI == timeDirs.size()-1)
|
||||||
{
|
{
|
||||||
if (args.found("copy-append"))
|
if (args.found("merge"))
|
||||||
{
|
{
|
||||||
Info<< nl << "Test move append" << nl;
|
Info<< nl << "Test merge" << nl;
|
||||||
}
|
|
||||||
else if (args.found("move-append"))
|
|
||||||
{
|
|
||||||
Info<< nl << "Test move append" << nl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -349,18 +334,8 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "==target==" << nl; reportDetail(objects);
|
Info<< "==target==" << nl; reportDetail(objects);
|
||||||
Info<< "==source==" << nl; reportDetail(other);
|
Info<< "==source==" << nl; reportDetail(other);
|
||||||
|
|
||||||
if (args.found("copy-append"))
|
objects.merge(std::move(other));
|
||||||
{
|
Info<< nl << "After merge" << nl;
|
||||||
objects.append(other);
|
|
||||||
|
|
||||||
Info<< nl << "After copy-append" << nl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
objects.append(std::move(other));
|
|
||||||
|
|
||||||
Info<< nl << "After move-append" << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< "==target==" << nl; reportDetail(objects);
|
Info<< "==target==" << nl; reportDetail(objects);
|
||||||
Info<< "==source==" << nl; reportDetail(other);
|
Info<< "==source==" << nl; reportDetail(other);
|
||||||
|
|||||||
@ -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 * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
|
|||||||
@ -99,6 +99,12 @@ public:
|
|||||||
//- Construct given initial table capacity
|
//- Construct given initial table capacity
|
||||||
inline explicit HashPtrTable(const label size);
|
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
|
//- Construct from Istream using given Istream constructor class
|
||||||
template<class INew>
|
template<class INew>
|
||||||
HashPtrTable(Istream& is, const INew& inew);
|
HashPtrTable(Istream& is, const INew& inew);
|
||||||
@ -109,12 +115,6 @@ public:
|
|||||||
//- Construct from dictionary with default dictionary constructor class
|
//- Construct from dictionary with default dictionary constructor class
|
||||||
explicit HashPtrTable(const dictionary& dict);
|
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
|
//- Destructor
|
||||||
~HashPtrTable();
|
~HashPtrTable();
|
||||||
|
|||||||
@ -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 * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
|
|||||||
@ -62,8 +62,8 @@ Description
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef HashSet_H
|
#ifndef Foam_HashSet_H
|
||||||
#define HashSet_H
|
#define Foam_HashSet_H
|
||||||
|
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
#include "IndirectList.H"
|
#include "IndirectList.H"
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -273,7 +273,7 @@ public:
|
|||||||
//- Find and return a hashed entry. FatalError if it does not exist.
|
//- Find and return a hashed entry. FatalError if it does not exist.
|
||||||
inline const T& at(const Key& key) const;
|
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;
|
inline bool found(const Key& key) const;
|
||||||
|
|
||||||
//- Find and return an iterator set at the hashed entry
|
//- Find and return an iterator set at the hashed entry
|
||||||
@ -630,39 +630,7 @@ protected:
|
|||||||
>::type;
|
>::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:
|
protected:
|
||||||
friend class HashTable; // For begin/find constructors
|
|
||||||
|
|
||||||
// Protected Data
|
// Protected Data
|
||||||
|
|
||||||
@ -680,10 +648,13 @@ protected:
|
|||||||
// to mark the position.
|
// to mark the position.
|
||||||
label index_;
|
label index_;
|
||||||
|
|
||||||
|
// Friendship with HashTable, for begin/find constructors
|
||||||
|
friend class HashTable;
|
||||||
|
|
||||||
|
|
||||||
// Protected Constructors
|
// Protected Constructors
|
||||||
|
|
||||||
//- Default construct (end iterator)
|
//- Default construct. Also the same as the end iterator
|
||||||
inline constexpr Iterator() noexcept;
|
inline constexpr Iterator() noexcept;
|
||||||
|
|
||||||
//- Construct from begin of hash-table
|
//- Construct from begin of hash-table
|
||||||
@ -704,9 +675,47 @@ protected:
|
|||||||
{
|
{
|
||||||
return *reinterpret_cast<const Iterator<Any>*>(this);
|
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.
|
//- Low-level entry erasure using iterator internals.
|
||||||
// This invalidates the iterator until the next ++ operation.
|
// This invalidates the iterator until the next ++ operation.
|
||||||
// \return True if the corresponding entry existed and was removed
|
// \return True if the corresponding entry existed and was removed
|
||||||
|
|||||||
@ -36,8 +36,8 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef HashTableCore_H
|
#ifndef Foam_HashTableCore_H
|
||||||
#define HashTableCore_H
|
#define Foam_HashTableCore_H
|
||||||
|
|
||||||
#include "label.H"
|
#include "label.H"
|
||||||
#include "uLabel.H"
|
#include "uLabel.H"
|
||||||
@ -66,7 +66,7 @@ struct HashTableCore
|
|||||||
ClassName("HashTable");
|
ClassName("HashTable");
|
||||||
|
|
||||||
//- Default construct
|
//- Default construct
|
||||||
HashTableCore() = default;
|
HashTableCore() noexcept = default;
|
||||||
|
|
||||||
static_assert
|
static_assert
|
||||||
(
|
(
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
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<class T, class Key, class Hash>
|
||||||
template<bool Const>
|
template<bool Const>
|
||||||
inline Foam::Ostream& Foam::HashTable<T, Key, Hash>::Iterator<Const>::print
|
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 * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
|
|||||||
@ -40,8 +40,8 @@ See also
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef Map_H
|
#ifndef Foam_Map_H
|
||||||
#define Map_H
|
#define Foam_Map_H
|
||||||
|
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ public:
|
|||||||
parent_type(std::move(map))
|
parent_type(std::move(map))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from an initializer list
|
//- Construct from pairs of values
|
||||||
Map(std::initializer_list<std::pair<label, T>> map)
|
Map(std::initializer_list<std::pair<label, T>> map)
|
||||||
:
|
:
|
||||||
parent_type(map)
|
parent_type(map)
|
||||||
|
|||||||
@ -35,8 +35,8 @@ See also
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef PtrMap_H
|
#ifndef Foam_PtrMap_H
|
||||||
#define PtrMap_H
|
#define Foam_PtrMap_H
|
||||||
|
|
||||||
#include "HashPtrTable.H"
|
#include "HashPtrTable.H"
|
||||||
|
|
||||||
|
|||||||
@ -189,23 +189,28 @@ const Foam::IOobject* Foam::IOobjectList::cfindObject
|
|||||||
const word& objName
|
const word& objName
|
||||||
) const
|
) 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())
|
||||||
{
|
{
|
||||||
|
io = iter.val();
|
||||||
|
}
|
||||||
|
|
||||||
if (IOobject::debug)
|
if (IOobject::debug)
|
||||||
|
{
|
||||||
|
if (io)
|
||||||
{
|
{
|
||||||
InfoInFunction << "Found " << objName << endl;
|
InfoInFunction << "Found " << objName << endl;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return iter.val();
|
|
||||||
}
|
|
||||||
else if (IOobject::debug)
|
|
||||||
{
|
{
|
||||||
InfoInFunction << "Could not find " << objName << endl;
|
InfoInFunction << "Could not find " << objName << endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return io;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -308,31 +308,39 @@ const Foam::IOobject* Foam::IOobjectList::cfindObject
|
|||||||
const word& objName
|
const word& objName
|
||||||
) const
|
) 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 (IOobject::debug)
|
||||||
|
{
|
||||||
|
if (io)
|
||||||
|
{
|
||||||
|
if (io->isHeaderClass<Type>())
|
||||||
{
|
{
|
||||||
InfoInFunction << "Found " << objName << endl;
|
InfoInFunction << "Found " << objName << endl;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return io;
|
|
||||||
}
|
|
||||||
else if (IOobject::debug)
|
|
||||||
{
|
{
|
||||||
InfoInFunction
|
InfoInFunction << "Found " << objName
|
||||||
<< "Found " << objName << " of different type" << endl;
|
<< " with different type" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IOobject::debug)
|
else
|
||||||
{
|
{
|
||||||
InfoInFunction << "Could not find " << objName << endl;
|
InfoInFunction << "Could not find " << objName << endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (io && io->isHeaderClass<Type>())
|
||||||
|
{
|
||||||
|
return io;
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user