/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
inline Foam::Keyed::Keyed()
:
key_(-1)
{}
template
inline Foam::Keyed::Keyed(const T& item, const label key)
:
T(item),
key_(key)
{}
template
inline Foam::Keyed::Keyed(T&& item, const label key)
:
T(move(item)),
key_(key)
{}
template
inline Foam::Keyed::Keyed(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
inline Foam::label Foam::Keyed::key() const
{
return key_;
}
template
inline Foam::label& Foam::Keyed::key()
{
return key_;
}
template
inline Foam::List>
Foam::Keyed::createList(const List& lst, const label key)
{
List> newList(lst.size());
forAll(lst, elemI)
{
newList[elemI] = Keyed(lst[elemI], key);
}
return newList;
}
template
inline Foam::List>
Foam::Keyed::createList(const List& lst, const labelUList& keys)
{
if (lst.size() != keys.size())
{
FatalErrorInFunction
<< "size mismatch adding keys to a list:" << nl
<< "List has size " << lst.size()
<< " and keys has size " << keys.size() << nl
<< abort(FatalError);
}
List> newList(lst.size());
forAll(lst, elemI)
{
newList[elemI] = Keyed(lst[elemI], keys[elemI]);
}
return newList;
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template
inline Foam::Istream& Foam::operator>>(Istream& is, Keyed& item)
{
// Read beginning of Keyed item/key pair
is.readBegin("Keyed");
is >> static_cast(item);
is >> item.key_;
// Read end of Keyed item/key pair
is.readEnd("Keyed");
// Check state of Ostream
is.check("Istream& operator>>(Istream&, Keyed&)");
return is;
}
template
inline Foam::Ostream& Foam::operator<<(Ostream& os, const Keyed& item)
{
os << token::BEGIN_LIST
<< static_cast(item)
<< token::SPACE << item.key_
<< token::END_LIST;
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //