/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 .
Description
Miscellaneous tests for HashTable
\*---------------------------------------------------------------------------*/
#include "HashTable.H"
#include "HashPtrTable.H"
#include "Map.H"
#include "FlatOutput.H"
using namespace Foam;
// Simple wrapper for testing purposes
class Label
{
label data_;
public:
Label()
:
data_(0)
{}
Label(label val)
:
data_(val)
{}
~Label()
{
Info<<"delete label: " << data_ << endl;
}
// Some arbitrary non-const method (for testing)
label increment()
{
return ++data_;
}
// Some arbitrary method (for testing)
std::string info() const
{
return "boxed label=" + std::to_string(data_);
}
friend Ostream& operator<<(Ostream& os, const Label& val)
{
os << val.data_;
return os;
}
};
template
void printTable(const HashPtrTable& table)
{
Info<< table.size() << '(' << nl;
for (const auto& key : table.sortedToc())
{
const auto iter = table.find(key);
Info
<< " " << iter.key() << " (" << Foam::name(&(iter.key()))
<< ") : ";
if (iter.val())
{
Info<< *(iter.val());
}
else
{
Info<< "nullptr";
}
Info<< " (" << Foam::name(iter.val()) << ")" << nl;;
}
Info<< ')' << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
HashTable