Commit 2fcf1dd0 authored by GILLES Sebastien's avatar GILLES Sebastien

#1470 Introduce a policy for PrintContainer, which may handle different cases...

#1470 Introduce a policy for PrintContainer, which may handle different cases with the same functions. This will be required to fulfill
#1465.
parent 83c2b5fe
......@@ -534,6 +534,14 @@
BE353BA822E76CF500A06A8F /* ConvertEntryToString.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE353BA522E76CF500A06A8F /* ConvertEntryToString.hpp */; };
BE353BB322E83AF800A06A8F /* Print.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE353BB022E83AF800A06A8F /* Print.hxx */; };
BE353BB422E83AF800A06A8F /* Print.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE353BB122E83AF800A06A8F /* Print.hpp */; };
BE353BBC22E8766100A06A8F /* Normal.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE353BB922E8766100A06A8F /* Normal.hxx */; };
BE353BBD22E8766100A06A8F /* Normal.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE353BBA22E8766100A06A8F /* Normal.hpp */; };
BE353BC222E8790400A06A8F /* Variant.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE353BBF22E8790400A06A8F /* Variant.hxx */; };
BE353BC322E8790400A06A8F /* Variant.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE353BC022E8790400A06A8F /* Variant.hpp */; };
BE353BC822E87E4F00A06A8F /* Pointer.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE353BC522E87E4F00A06A8F /* Pointer.hxx */; };
BE353BC922E87E4F00A06A8F /* Pointer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE353BC622E87E4F00A06A8F /* Pointer.hpp */; };
BE353BCE22E87F6F00A06A8F /* Associative.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE353BCB22E87F6F00A06A8F /* Associative.hxx */; };
BE353BCF22E87F6F00A06A8F /* Associative.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE353BCC22E87F6F00A06A8F /* Associative.hpp */; };
BE3AB281183503C7009E1B76 /* libCore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE05B52916D238FE000E248D /* libCore.a */; };
BE3AB283183503C7009E1B76 /* libFiniteElement.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE9C4D121807F5DC005B94BC /* libFiniteElement.a */; };
BE3AB284183503C7009E1B76 /* libGeometry.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE05B4DD16D23573000E248D /* libGeometry.a */; };
......@@ -3431,6 +3439,14 @@
BE353BAD22E83A4700A06A8F /* Print.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Print.hxx; path = Sources/Utilities/Containers/Print.hxx; sourceTree = SOURCE_ROOT; };
BE353BB022E83AF800A06A8F /* Print.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Print.hxx; sourceTree = "<group>"; };
BE353BB122E83AF800A06A8F /* Print.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Print.hpp; sourceTree = "<group>"; };
BE353BB922E8766100A06A8F /* Normal.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Normal.hxx; sourceTree = "<group>"; };
BE353BBA22E8766100A06A8F /* Normal.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Normal.hpp; sourceTree = "<group>"; };
BE353BBF22E8790400A06A8F /* Variant.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Variant.hxx; sourceTree = "<group>"; };
BE353BC022E8790400A06A8F /* Variant.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Variant.hpp; sourceTree = "<group>"; };
BE353BC522E87E4F00A06A8F /* Pointer.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Pointer.hxx; sourceTree = "<group>"; };
BE353BC622E87E4F00A06A8F /* Pointer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Pointer.hpp; sourceTree = "<group>"; };
BE353BCB22E87F6F00A06A8F /* Associative.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Associative.hxx; sourceTree = "<group>"; };
BE353BCC22E87F6F00A06A8F /* Associative.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Associative.hpp; sourceTree = "<group>"; };
BE372DDB18C4802900127212 /* main_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main_test.cpp; sourceTree = "<group>"; };
BE37EFEB1CB308340006C0AD /* FiniteElement.doxygen */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = FiniteElement.doxygen; sourceTree = "<group>"; };
BE390F142108C9BD0049CD3B /* test_input_data.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = test_input_data.cpp; sourceTree = "<group>"; };
......@@ -6821,6 +6837,14 @@
BE353BB722E8743700A06A8F /* PrintPolicy */ = {
isa = PBXGroup;
children = (
BE353BBA22E8766100A06A8F /* Normal.hpp */,
BE353BB922E8766100A06A8F /* Normal.hxx */,
BE353BC022E8790400A06A8F /* Variant.hpp */,
BE353BBF22E8790400A06A8F /* Variant.hxx */,
BE353BC622E87E4F00A06A8F /* Pointer.hpp */,
BE353BC522E87E4F00A06A8F /* Pointer.hxx */,
BE353BCC22E87F6F00A06A8F /* Associative.hpp */,
BE353BCB22E87F6F00A06A8F /* Associative.hxx */,
);
path = PrintPolicy;
sourceTree = "<group>";
......@@ -11317,6 +11341,7 @@
BE41E96E1AC3F92A0072C8E6 /* EmptyString.hpp in Headers */,
BE353BB422E83AF800A06A8F /* Print.hpp in Headers */,
BE5B6F921C3C16E9004A0284 /* ShellMatrix.hxx in Headers */,
BE353BBC22E8766100A06A8F /* Normal.hxx in Headers */,
BE90E17D1A24929A00CCAFDE /* Base.hxx in Headers */,
BE1EBB021CA0961000EC0EAA /* InputData.hpp in Headers */,
BE145A011E54BC49000A2BF5 /* CmdLineOutput.h in Headers */,
......@@ -11361,6 +11386,7 @@
BE53FC151E0D7C6800C5D6F5 /* TupleIteration.hpp in Headers */,
BE90E16C1A24926E00CCAFDE /* UnorderedMap.hpp in Headers */,
BE90E1C51A2492AA00CCAFDE /* SubVector_Base.hpp in Headers */,
BE353BBD22E8766100A06A8F /* Normal.hpp in Headers */,
BE5389FD1C897FE400D80749 /* Mpi.hpp in Headers */,
BE90E1B01A24929A00CCAFDE /* Vector.hpp in Headers */,
BEDEB9301C3C073100B1C71B /* Snes.hxx in Headers */,
......@@ -11398,6 +11424,7 @@
BE4ED31D1A2CBAC400DE374E /* MatrixOperations.hpp in Headers */,
BECEF92D22DF5D5E00D0DDE7 /* Now.hpp in Headers */,
BE90E1B11A24929A00CCAFDE /* Vector.hxx in Headers */,
BE353BC822E87E4F00A06A8F /* Pointer.hxx in Headers */,
BE110EA91E11517400D2D2C8 /* Solver.hpp in Headers */,
BE9ECC0B1F5857B900D92CD7 /* Filesystem.hpp in Headers */,
BE168EA51CC96DA00090AC88 /* Tetrahedron10.hxx in Headers */,
......@@ -11420,6 +11447,7 @@
BE110EA41E11514200D2D2C8 /* VectorHelper.hpp in Headers */,
BE90E1AB1A24929A00CCAFDE /* Matrix.hxx in Headers */,
BE110E981E11513200D2D2C8 /* NonZeroPattern.hpp in Headers */,
BE353BCF22E87F6F00A06A8F /* Associative.hpp in Headers */,
BEDE16A8204F365600DEFE08 /* LuaOptionFile.hxx in Headers */,
BE145A051E54BC49000A2BF5 /* IgnoreRestVisitor.h in Headers */,
BE41A8CA1A24AA46004E4312 /* Mpi.hpp in Headers */,
......@@ -11453,6 +11481,7 @@
BE1459FC1E54BC49000A2BF5 /* Arg.h in Headers */,
BE76F2631D7D60660061B50E /* GlobalVectorTemporaryStorage.hxx in Headers */,
BEFE4F101CBD23200087DD1F /* PetscMatPrivate.h in Headers */,
BE353BCE22E87F6F00A06A8F /* Associative.hxx in Headers */,
BE90E1CA1A2492AA00CCAFDE /* Parmetis.hpp in Headers */,
BE6E4EE21B2ABE8B0049BB2D /* AccessGhostContent.hpp in Headers */,
BE76F24F1D7D5D900061B50E /* LocalMatrixStorage.hxx in Headers */,
......@@ -11460,6 +11489,7 @@
BE90E1621A24926E00CCAFDE /* Exception.hpp in Headers */,
BECDB4B922C21749009BA8E2 /* PrintTypeName.hpp in Headers */,
BE83582D1FFD78DE0009956E /* Sort.hxx in Headers */,
BE353BC222E8790400A06A8F /* Variant.hxx in Headers */,
BEDEB92A1C3C073100B1C71B /* Umfpack.hxx in Headers */,
BE90E16A1A24926E00CCAFDE /* Sort.hpp in Headers */,
135F21441E7ADB2A00B9E633 /* Viscoelasticity.hpp in Headers */,
......@@ -11469,6 +11499,7 @@
BE145A0E1E54BC49000A2BF5 /* ValueArg.h in Headers */,
135F20BB1E7A909100B9E633 /* VTK_PolygonalData.hxx in Headers */,
BE9512911A8CC3E5009E0082 /* Mutex.hxx in Headers */,
BE353BC922E87E4F00A06A8F /* Pointer.hpp in Headers */,
BE1459FE1E54BC49000A2BF5 /* ArgTraits.h in Headers */,
BEDEB9231C3C073100B1C71B /* Gmres.hpp in Headers */,
BE76F24E1D7D5D900061B50E /* LocalMatrixStorage.hpp in Headers */,
......@@ -11501,6 +11532,7 @@
BE90E1601A24926E00CCAFDE /* Miscellaneous.hpp in Headers */,
BE41A8D01A24AA59004E4312 /* Petsc.hxx in Headers */,
BE2592141C9ABA6900DF404B /* Utilities.doxygen in Headers */,
BE353BC322E8790400A06A8F /* Variant.hpp in Headers */,
BE90E1C31A2492AA00CCAFDE /* SubVector.hpp in Headers */,
BEDEB92F1C3C073100B1C71B /* Snes.hpp in Headers */,
BE5AA42922E62C3A00A393DE /* RAII.hpp in Headers */,
......@@ -162,7 +162,7 @@ namespace MoReFEM
{
std::ostringstream oconv;
oconv << "The following ranks couldn't find the input data file: ";
Utilities::PrintContainer(rank_without_file, oconv, ", ", "", ".\n");
Utilities::PrintContainer<>::Do(rank_without_file, oconv, ", ", "", ".\n");
throw Exception(oconv.str(), __FILE__, __LINE__);
}
}
......
......@@ -57,7 +57,7 @@ namespace MoReFEM
std::ostringstream oconv;
Utilities::PrintContainer(buf, oconv, ", ", "", "");
Utilities::PrintContainer<>::Do(buf, oconv, ", ", "", "");
return oconv.str();
}
......
......@@ -488,7 +488,7 @@ namespace MoReFEM
//// const auto& local_2_global = felt_ptr->GetLocal2Global<MpiScale::program_wise>();
//// out << "Element " << elt_index++ << ": ";
////
//// Utilities::PrintContainer(local_2_global, out, ' ', ' ', '\n');
//// Utilities::PrintContainer<>::Do(local_2_global, out, ' ', ' ', '\n');
//// }
//// }
//// }
......@@ -558,7 +558,7 @@ namespace MoReFEM
// coords_index.push_back(coord->GetIndex());
// }
//
// Utilities::PrintContainer(coords_index, out);
// Utilities::PrintContainer<>::Do(coords_index, out);
// }
// }
// }
......@@ -648,7 +648,7 @@ namespace MoReFEM
std::ostringstream oconv;
oconv << "Node bearers on processor " << rank << " -> [";
Utilities::PrintContainer(indexes, out, ", ", oconv.str());
Utilities::PrintContainer<>::Do(indexes, out, ", ", oconv.str());
}
......@@ -1229,8 +1229,8 @@ namespace MoReFEM
oconv << "Position in the actual matrix must match those defined in the pattern! Not the case "
"for row " << program_wise_index << " (program-wise numbering) on processor " << mpi.GetRank<int>();
Utilities::PrintContainer(position_list_in_matrix, oconv, ", ", "\n\t- Position in matrix -> [");
Utilities::PrintContainer(position_list_in_pattern, oconv, ", ", "\t- Position in pattern -> [");
Utilities::PrintContainer<>::Do(position_list_in_matrix, oconv, ", ", "\n\t- Position in matrix -> [");
Utilities::PrintContainer<>::Do(position_list_in_pattern, oconv, ", ", "\t- Position in pattern -> [");
throw Exception(oconv.str(),
invoking_file, invoking_line);
......
......@@ -123,7 +123,7 @@ namespace // anonymous
{
std::ostringstream oconv;
oconv << "The unknown found int the input file are not the ones expected by the problem: \n";
MoReFEM::Utilities::PrintContainer(tuple_unknown_list, oconv);
MoReFEM::Utilities::PrintContainer<>::Do(tuple_unknown_list, oconv);
oconv << " were expected but those that were in the input file were: \n";
MoReFEM::Utilities::PrintKeys(input_file_unknown_list, oconv);
return oconv.str();
......
......@@ -78,7 +78,7 @@ namespace MoReFEM
}
out << "Edge " << i << ", Orientation " << orientation << ": ";
Utilities::PrintContainer(indexes, out, ",", "(", ")\n");
Utilities::PrintContainer<>::Do(indexes, out, ",", "(", ")\n");
}
}
}
......@@ -104,7 +104,7 @@ namespace MoReFEM
}
out << "Face " << i << ", Orientation " << orientation << ": ";
Utilities::PrintContainer(indexes, out, ",", "(", ")\n");
Utilities::PrintContainer<>::Do(indexes, out, ",", "(", ")\n");
}
}
}
......@@ -123,7 +123,7 @@ namespace MoReFEM
}
out << "Volume: ";
Utilities::PrintContainer(indexes, out, ",", "(", ")\n");
Utilities::PrintContainer<>::Do(indexes, out, ",", "(", ")\n");
}
}
......
......@@ -35,7 +35,7 @@ namespace MoReFEM
void LocalCoords::Print(std::ostream& out) const
{
Utilities::PrintContainer(coordinate_list_, out);
Utilities::PrintContainer<>::Do(coordinate_list_, out);
}
......
......@@ -74,7 +74,7 @@ namespace MoReFEM
void SpatialPoint::Print(std::ostream& out) const
{
Utilities::PrintContainer(coordinate_list_, out, ", ", '(', ')');
Utilities::PrintContainer<>::Do(coordinate_list_, out, ", ", '(', ')');
}
......
......@@ -246,7 +246,7 @@ namespace MoReFEM
Utilities::EliminateDuplicate(list);
Utilities::PrintContainer(list, std::cout);
Utilities::PrintContainer<>::Do(list, std::cout);
std::cout << "INDEX = " << coord_ptr->GetIndex() << std::endl;
}
......
......@@ -107,7 +107,7 @@ namespace MoReFEM::Advanced::MeshNS
}
out << "geometric_elt_index_list = ";
Utilities::PrintContainer(index_list, out, ", ", "{", "}");
Utilities::PrintContainer<>::Do(index_list, out, ", ", "{", "}");
out << std::endl;
}
......@@ -124,7 +124,7 @@ namespace MoReFEM::Advanced::MeshNS
}
out << "processor_wise_coords_index_list = ";
Utilities::PrintContainer(index_list, out, ", ", "{", "}");
Utilities::PrintContainer<>::Do(index_list, out, ", ", "{", "}");
out << std::endl;
}
......@@ -141,7 +141,7 @@ namespace MoReFEM::Advanced::MeshNS
}
out << "ghosted_coords_index_list = ";
Utilities::PrintContainer(index_list, out, ", ", "{", "}");
Utilities::PrintContainer<>::Do(index_list, out, ", ", "{", "}");
out << std::endl;
}
......@@ -161,7 +161,7 @@ namespace MoReFEM::Advanced::MeshNS
}
out << "vertex_index_list = ";
Utilities::PrintContainer(index_list, out, ", ", "{", "}");
Utilities::PrintContainer<>::Do(index_list, out, ", ", "{", "}");
out << std::endl;
}
......@@ -178,7 +178,7 @@ namespace MoReFEM::Advanced::MeshNS
}
out << "edge_index_list = ";
Utilities::PrintContainer(index_list, out, ", ", "{", "}");
Utilities::PrintContainer<>::Do(index_list, out, ", ", "{", "}");
out << std::endl;
}
......@@ -195,7 +195,7 @@ namespace MoReFEM::Advanced::MeshNS
}
out << "face_index_list = ";
Utilities::PrintContainer(index_list, out, ", ", "{", "}");
Utilities::PrintContainer<>::Do(index_list, out, ", ", "{", "}");
out << std::endl;
}
......@@ -212,7 +212,7 @@ namespace MoReFEM::Advanced::MeshNS
}
out << "volume_index_list = ";
Utilities::PrintContainer(index_list, out, ", ", "{", "}");
Utilities::PrintContainer<>::Do(index_list, out, ", ", "{", "}");
out << std::endl;
}
}
......
......@@ -146,7 +146,7 @@ namespace MoReFEM
return geometric_elt_ptr->GetIndex();
});
Utilities::PrintContainer(buf);
Utilities::PrintContainer<>::Do(buf);
}
}
......
......@@ -141,7 +141,7 @@ namespace MoReFEM
std::vector<unsigned int> index
{ vertex_coords_list.back()->GetPositionInCoordsListInMesh<MpiScale::processor_wise>() };
Utilities::PrintContainer(index, out);
Utilities::PrintContainer<>::Do(index, out);
}
}
......@@ -214,7 +214,7 @@ namespace MoReFEM
std::sort(index_list.begin(), index_list.end());
Utilities::PrintContainer(index_list, out);
Utilities::PrintContainer<>::Do(index_list, out);
}
}
......
......@@ -105,7 +105,7 @@ BOOST_FIXTURE_TEST_CASE(check_value, TestNS::FixtureNS::Environment)
//std::cout << "VALUE READ = " << value->GetTheValue() << std::endl;
Utilities::PrintContainer(value->GetTheValue(), std::cout);
Utilities::PrintContainer<>::Do(value->GetTheValue(), std::cout);
}
......
......@@ -65,11 +65,11 @@ namespace MoReFEM
== end_expected_value_list)
{
std::ostringstream oconv;
Utilities::PrintContainer(coords_array, oconv, ", ", "[", "] ");
Utilities::PrintContainer<>::Do(coords_array, oconv, ", ", "[", "] ");
oconv << "was found but is not among the expected values which are:\n";
for (const auto& item : expected_value_list)
Utilities::PrintContainer(item, oconv, ", ", "\t[", "]\n");
Utilities::PrintContainer<>::Do(item, oconv, ", ", "\t[", "]\n");
throw Exception(oconv.str(), __FILE__, __LINE__);
}
......
......@@ -109,9 +109,9 @@ namespace MoReFEM
{
std::ostringstream oconv;
oconv << "Error somewhere in interpolator implementation: interface ";
Utilities::PrintContainer(it_fluid->second, oconv);
Utilities::PrintContainer<>::Do(it_fluid->second, oconv);
oconv << " on fluid mesh do not match interface ";
Utilities::PrintContainer(it_fluid->second, oconv);
Utilities::PrintContainer<>::Do(it_fluid->second, oconv);
oconv << " on solid mesh.";
throw Exception(oconv.str(), __FILE__, __LINE__);
}
......
......@@ -18,6 +18,7 @@
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "Utilities/Containers/Print.hpp"
#include "Utilities/Containers/PrintPolicy/Variant.hpp"
using namespace MoReFEM;
......@@ -35,7 +36,7 @@ BOOST_AUTO_TEST_CASE(vector_simple)
std::ostringstream oconv;
Utilities::PrintContainer(a, oconv);
Utilities::PrintContainer<>::Do(a, oconv);
BOOST_CHECK_EQUAL(oconv.str(), "[5, 7, -4, 3]\n");
}
......@@ -46,7 +47,7 @@ BOOST_AUTO_TEST_CASE(deque_custom)
std::ostringstream oconv;
Utilities::PrintContainer(a, oconv, ' ', "", '!');
Utilities::PrintContainer<>::Do(a, oconv, ' ', "", '!');
BOOST_CHECK_EQUAL(oconv.str(), "Not a hello world!");
}
......@@ -57,7 +58,7 @@ BOOST_AUTO_TEST_CASE(vector_of_simple_variant)
std::vector<variant> a { 4.3, 3, "Hello", -6, "Bye!" };
std::ostringstream oconv;
Utilities::PrintContainer(a, oconv, ", ", "{", '}');
Utilities::PrintContainer<Utilities::PrintPolicyNS::Variant>::Do(a, oconv, ", ", "{", '}');
BOOST_CHECK_EQUAL(oconv.str(), "{4.3, 3, Hello, -6, Bye!}");
}
......@@ -67,7 +68,7 @@ BOOST_AUTO_TEST_CASE(list_print_n_elt)
{
std::list<unsigned int> primes { 2, 3, 5, 7, 11, 13 };
std::ostringstream oconv;
Utilities::PrintNelt<3>(primes, oconv, ", ", "{", ", ... }");
Utilities::PrintNelt<>::Do<3>(primes, oconv, ", ", "{", ", ... }");
BOOST_CHECK_EQUAL(oconv.str(), "{2, 3, 5, ... }");
}
......
......@@ -30,7 +30,7 @@ namespace MoReFEM::Internal::PrintNS
* \tparam StringT Type of the separator. Usually std::string, but might be char or really anything for which
* operator<< is defined.
*/
template<class StringT = std::string>
template<class PrintPolicyT, class StringT = std::string>
class SeparatorFacility
{
public:
......@@ -70,8 +70,9 @@ namespace MoReFEM::Internal::PrintNS
*
* \return \a facility argument (to enable chained calls).
*/
template<class StringU, class T>
friend SeparatorFacility<StringU>& operator<<(SeparatorFacility<StringU>& facility, const T& value);
template<class PrintPolicyU, class StringU, class T>
friend SeparatorFacility<PrintPolicyU, StringU>&
operator<<(SeparatorFacility<PrintPolicyU, StringU>& facility, const T& value);
private:
......@@ -95,8 +96,9 @@ namespace MoReFEM::Internal::PrintNS
*
* \return \a facility argument (to enable chained calls).
*/
template<class StringT, class T>
SeparatorFacility<StringT>& operator<<(SeparatorFacility<StringT>& facility, const T& value);
template<class PrintPolicyT, class StringT, class T>
SeparatorFacility<PrintPolicyT, StringT>&
operator<<(SeparatorFacility<PrintPolicyT, StringT>& facility, const T& value);
/*!
......
......@@ -16,37 +16,23 @@ namespace MoReFEM::Internal::PrintNS
{
template<class StringT>
SeparatorFacility<StringT>::SeparatorFacility(std::ostream& stream, const StringT& separator)
template<class PrintPolicyT, class StringT>
SeparatorFacility<PrintPolicyT, StringT>::SeparatorFacility(std::ostream& stream, const StringT& separator)
: stream_(stream),
separator_(separator)
{ }
template<class StringT, class T>
SeparatorFacility<StringT>& operator<<(SeparatorFacility<StringT>& facility, const T& value)
template<class PrintPolicyT, class StringT, class T>
SeparatorFacility<PrintPolicyT, StringT>&
operator<<(SeparatorFacility<PrintPolicyT, StringT>& facility, const T& value)
{
if (facility.is_first_)
facility.is_first_ = false;
else
facility.stream_ << facility.separator_;
if constexpr (Utilities::IsSpecializationOf
<
std::variant,
T
>())
{
auto& stream = facility.stream_;
std::visit([&stream](auto&& arg)
{
stream << arg;
},
value);
}
else
facility.stream_ << value;
PrintPolicyT::Do(facility.stream_, value);
return facility;
}
......@@ -67,7 +53,6 @@ namespace MoReFEM::Internal::PrintNS
};
template<class StreamT, unsigned int Max, class TupleT>
template<typename StringT>
void PrintTupleHelper<StreamT, Max, Max, TupleT>::Print(StreamT&, const TupleT& , const StringT&)
......
......@@ -27,6 +27,7 @@
# include "Utilities/String/Traits.hpp"
# include "Utilities/Miscellaneous.hpp"
# include "Utilities/Containers/Internal/Print.hpp"
# include "Utilities/Containers/PrintPolicy/Normal.hpp"
namespace MoReFEM
......@@ -57,16 +58,26 @@ namespace MoReFEM
* This code yields:
* ---1. 2. 3. 10. 42.---
*/
template
<
class ContainerT,
typename StreamT = std::ostream,
typename StringT1 = std::string,
typename StringT2 = std::string,
typename StringT3 = std::string
>
void PrintContainer(const ContainerT& container, StreamT& stream = std::cout,
StringT1 separator = ", ", StringT2 opener = "[", StringT3 closer = "]\n");
template<class PrintPolicyT = PrintPolicyNS::Normal>
struct PrintContainer
{
template
<
class ContainerT,
typename StreamT = std::ostream,
typename StringT1 = std::string,
typename StringT2 = std::string,
typename StringT3 = std::string
>
static void Do(const ContainerT& container, StreamT& stream = std::cout,
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
};
/*!
......@@ -94,17 +105,28 @@ namespace MoReFEM
* This code yields:
* ---1. 2. 3. 10. 42.---
*/
template
<
std::size_t N,
class ContainerT,
typename StreamT = std::ostream,
typename StringT1 = std::string,
typename StringT2 = std::string,
typename StringT3 = std::string
>
void PrintNelt(const ContainerT& container, StreamT& stream = std::cout,
StringT1 separator = ", ", StringT2 opener = "[", StringT3 closer = "]\n");
template <class PrintPolicyT = PrintPolicyNS::Normal>
struct PrintNelt
{
template
<
std::size_t N,
class ContainerT,
typename StreamT = std::ostream,
typename StringT1 = std::string,
typename StringT2 = std::string,
typename StringT3 = std::string
>
static void Do(const ContainerT& container, StreamT& stream = std::cout,
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
};
/*!
* \brief Print the content of a non associative container (list, vector, deque, array, etc...) after
......@@ -131,7 +153,9 @@ namespace MoReFEM
typename StringT3 = std::string
>
void PrintPointerContainer(const ContainerT& container, StreamT& stream = std::cout,
StringT1 separator = ", ", StringT2 opener = "[", StringT3 closer = "]\n");
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
/*!
......@@ -171,7 +195,9 @@ namespace MoReFEM
typename StringT3 = std::string
>
void PrintKeys(const AssociativeContainerT& container, StreamT& stream = std::cout,
StringT1 separator = ", ", StringT2 opener = "[", StringT3 closer = "]\n");
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
/*!
......@@ -211,8 +237,9 @@ namespace MoReFEM
typename StringT3 = std::string
>
void PrintAssociativeContainer(const AssociativeContainerT& container, StreamT& stream = std::cout,
StringT1 separator = ", ", StringT2 opener = "[", StringT3 closer = "]\n");
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
/*!
......@@ -240,9 +267,9 @@ namespace MoReFEM
>
void PrintTuple(const TupleT& tuple,
StreamT& stream = std::cout,
StringT1 separator = ",",
StringT2 opener = "[",
StringT3 closer = "]\n");
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
} // namespace Utilities
......
......@@ -13,7 +13,7 @@ namespace MoReFEM
namespace Utilities
{
template<class PrintPolicyT>
template
<
class ContainerT,
......@@ -22,12 +22,14 @@ namespace MoReFEM
typename StringT2,
typename StringT3
>
void PrintContainer(const ContainerT& container, StreamT& stream,
StringT1 separator, StringT2 opener, StringT3 closer)
void PrintContainer<PrintPolicyT>::Do(const ContainerT& container, StreamT& stream,
StringT1&& separator,
StringT2&& opener,
StringT3&& closer)
{
stream << opener;
Internal::PrintNS::SeparatorFacility separator_facility(stream, separator);
Internal::PrintNS::SeparatorFacility<PrintPolicyT, StringT1> separator_facility(stream, separator);
for (const auto& element : container)
separator_facility << element;
......@@ -36,6 +38,7 @@ namespace MoReFEM
}
template<class PrintPolicyT>
template
<
std::size_t N,
......@@ -45,12 +48,12 @@ namespace MoReFEM
typename StringT2,
typename StringT3
>
void PrintNelt(const ContainerT& container, StreamT& stream,
StringT1 separator, StringT2 opener, StringT3 closer)
void PrintNelt<PrintPolicyT>::Do(const ContainerT& container, StreamT& stream,
StringT1&& separator, StringT2&& opener, StringT3&& closer)
{
stream << opener;
Internal::PrintNS::SeparatorFacility separator_facility(stream, separator);
Internal::PrintNS::SeparatorFacility<PrintPolicyT, StringT1> separator_facility(stream, separator);