Skip to content
Snippets Groups Projects
Commit fbeec628 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: add Ostream output for std::vector

- convenient when using data structures from other codes
parent 2c5c3aff
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2011, 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011, 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2013 OpenFOAM Foundation | Copyright (C) 2011-2013 OpenFOAM Foundation
...@@ -40,6 +40,7 @@ Description ...@@ -40,6 +40,7 @@ Description
#include "Switch.H" #include "Switch.H"
#include "fileName.H" #include "fileName.H"
#include "stringList.H" #include "stringList.H"
#include "stringOps.H"
using namespace Foam; using namespace Foam;
...@@ -132,7 +133,8 @@ int main(int argc, char *argv[]) ...@@ -132,7 +133,8 @@ int main(int argc, char *argv[])
string output(stringOps::expand(input)); string output(stringOps::expand(input));
Info<< "input: " << input << nl Info<< "input: " << input << nl
<< "expand: " << output << nl << nl; << "expand: " << output << nl
<< "split: " << stringOps::split(output, "/") << nl << nl;
} }
} }
......
...@@ -58,6 +58,7 @@ SourceFiles ...@@ -58,6 +58,7 @@ SourceFiles
#include <initializer_list> #include <initializer_list>
#include <iterator> #include <iterator>
#include <type_traits> #include <type_traits>
#include <vector>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -567,6 +568,10 @@ Ostream& operator<<(Ostream& os, const UList<T>& list) ...@@ -567,6 +568,10 @@ Ostream& operator<<(Ostream& os, const UList<T>& list)
return list.writeList(os, Detail::ListPolicy::short_length<T>::value); 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
...@@ -666,6 +671,7 @@ struct sizeOp ...@@ -666,6 +671,7 @@ struct sizeOp
#ifdef NoRepository #ifdef NoRepository
#include "UList.C" #include "UList.C"
#include "stdVectorIO.C"
#endif #endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
// ************************************************************************* //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment