ENH: add Ostream output for std::vector
- convenient when using data structures from other codes
This commit is contained in:
parent
2c5c3affef
commit
fbeec6286b
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2011, 2016 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011, 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
@ -40,6 +40,7 @@ Description
|
||||
#include "Switch.H"
|
||||
#include "fileName.H"
|
||||
#include "stringList.H"
|
||||
#include "stringOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -132,7 +133,8 @@ int main(int argc, char *argv[])
|
||||
string output(stringOps::expand(input));
|
||||
|
||||
Info<< "input: " << input << nl
|
||||
<< "expand: " << output << nl << nl;
|
||||
<< "expand: " << output << nl
|
||||
<< "split: " << stringOps::split(output, "/") << nl << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ SourceFiles
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -567,6 +568,10 @@ Ostream& operator<<(Ostream& os, const UList<T>& list)
|
||||
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
|
||||
}
|
||||
|
||||
//- Write std::vector to Ostream
|
||||
template<class T>
|
||||
Ostream& operator<<(Ostream& os, const std::vector<T>& list);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
@ -666,6 +671,7 @@ struct sizeOp
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "UList.C"
|
||||
#include "stdVectorIO.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
60
src/OpenFOAM/containers/Lists/UList/stdVectorIO.C
Normal file
60
src/OpenFOAM/containers/Lists/UList/stdVectorIO.C
Normal file
@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "UList.H"
|
||||
#include "Ostream.H"
|
||||
#include "token.H"
|
||||
#include <vector>
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const std::vector<T>& list)
|
||||
{
|
||||
auto iter = list.cbegin();
|
||||
const auto last = list.cend();
|
||||
|
||||
// Write ascii list contents, no breaks
|
||||
|
||||
os << label(list.size()) << token::BEGIN_LIST;
|
||||
|
||||
if (iter != last)
|
||||
{
|
||||
os << *iter;
|
||||
|
||||
for (++iter; iter != last; ++iter)
|
||||
{
|
||||
os << token::SPACE << *iter;
|
||||
}
|
||||
}
|
||||
|
||||
os << token::END_LIST;
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
Loading…
Reference in New Issue
Block a user