Commit 35c1f9ad authored by GILLES Sebastien's avatar GILLES Sebastien

#1470 There are now only two Print facilities in Utilities: for containers and for tuples.

parent 78dc5073
......@@ -542,6 +542,8 @@
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 */; };
BE353BD222E8917B00A06A8F /* Key.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE353BD122E8917B00A06A8F /* Key.hpp */; };
BE353BD422E8918A00A06A8F /* Key.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE353BD322E8918A00A06A8F /* Key.hxx */; };
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 */; };
......@@ -3447,6 +3449,8 @@
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>"; };
BE353BD122E8917B00A06A8F /* Key.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Key.hpp; sourceTree = "<group>"; };
BE353BD322E8918A00A06A8F /* Key.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Key.hxx; 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>"; };
......@@ -6845,6 +6849,8 @@
BE353BC522E87E4F00A06A8F /* Pointer.hxx */,
BE353BCC22E87F6F00A06A8F /* Associative.hpp */,
BE353BCB22E87F6F00A06A8F /* Associative.hxx */,
BE353BD122E8917B00A06A8F /* Key.hpp */,
BE353BD322E8918A00A06A8F /* Key.hxx */,
);
path = PrintPolicy;
sourceTree = "<group>";
......@@ -11382,6 +11388,7 @@
BE90E1671A24926E00CCAFDE /* Print.hpp in Headers */,
BEDEB9371C3C078A00B1C71B /* InputData.hxx in Headers */,
BE41A8CB1A24AA46004E4312 /* Mpi.hxx in Headers */,
BE353BD222E8917B00A06A8F /* Key.hpp in Headers */,
BEDEB9291C3C073100B1C71B /* Umfpack.hpp in Headers */,
BE53FC151E0D7C6800C5D6F5 /* TupleIteration.hpp in Headers */,
BE90E16C1A24926E00CCAFDE /* UnorderedMap.hpp in Headers */,
......@@ -11448,6 +11455,7 @@
BE90E1AB1A24929A00CCAFDE /* Matrix.hxx in Headers */,
BE110E981E11513200D2D2C8 /* NonZeroPattern.hpp in Headers */,
BE353BCF22E87F6F00A06A8F /* Associative.hpp in Headers */,
BE353BD422E8918A00A06A8F /* Key.hxx in Headers */,
BEDE16A8204F365600DEFE08 /* LuaOptionFile.hxx in Headers */,
BE145A051E54BC49000A2BF5 /* IgnoreRestVisitor.h in Headers */,
BE41A8CA1A24AA46004E4312 /* Mpi.hpp in Headers */,
......@@ -16,6 +16,7 @@
#include <vector>
#include "Utilities/Containers/Print.hpp"
#include "Utilities/Containers/PrintPolicy/Key.hpp"
#include "FiniteElement/Nodes_and_dofs/Exceptions/Dof.hpp"
......@@ -125,7 +126,7 @@ namespace // anonymous
oconv << "The unknown found int the input file are not the ones expected by the problem: \n";
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);
MoReFEM::Utilities::PrintContainer<MoReFEM::Utilities::PrintPolicyNS::Key>::Do(input_file_unknown_list, oconv);
return oconv.str();
}
......
......@@ -17,6 +17,7 @@
#include <cassert>
#include "Utilities/Containers/Print.hpp"
#include "Utilities/Containers/PrintPolicy/Key.hpp"
#include "Utilities/Containers/UnorderedMap.hpp"
#include "Geometry/GeometricElt/Advanced/GeometricEltFactory.hpp"
#include "Geometry/GeometricElt/Internal/Exceptions/GeometricElt.hpp"
......@@ -110,7 +111,7 @@ namespace MoReFEM
throw MoReFEM::Exception("No Ensight geometric elements defined!!!", __FILE__, __LINE__);
std::ostringstream oconv;
Utilities::PrintKeys(callbacks_ensight_, oconv, ", ", "[", "]");
Utilities::PrintContainer<Utilities::PrintPolicyNS::Key>::Do(callbacks_ensight_, oconv, ", ", "[", "]");
return oconv.str();
}
......
......@@ -13,6 +13,7 @@
#include "Utilities/Containers/EnumClass.hpp"
#include "Utilities/Containers/PrintPolicy/Key.hpp"
#include "Geometry/Mesh/Internal/Format/Format.hpp"
#include "Geometry/Mesh/Internal/Format/Ensight.hpp"
......@@ -90,7 +91,8 @@ namespace MoReFEM
oconv << "No type matching format name " << format_name << " were found. The possible values are: "
<< std::endl;
Utilities::PrintKeys(mapping, oconv, "\n\t- ", "\t- ", '\n');
Utilities::PrintContainer<Utilities::PrintPolicyNS::Key>
::Do(mapping, oconv, "\n\t- ", "\t- ", '\n');
throw MoReFEM::Exception(oconv.str(), __FILE__, __LINE__);
}
......
......@@ -7,7 +7,9 @@
//
*/
#include <sstream>
#include "Utilities/Containers/PrintPolicy/Associative.hpp"
#include "Test/Geometry/LightweightDomainList/Model.hpp"
......@@ -40,9 +42,9 @@ namespace MoReFEM
std::ostringstream oconv;
oconv << "Domains do not contain the expected number of elements: prevision was ";
Utilities::PrintAssociativeContainer(expected, oconv);
Utilities::PrintContainer<Utilities::PrintPolicyNS::Associative>::Do(expected, oconv);
oconv << " and what was obtained was: ";
Utilities::PrintAssociativeContainer(obtained, oconv);
Utilities::PrintContainer<Utilities::PrintPolicyNS::Associative>::Do(obtained, oconv);
oconv << " (key is domain id, value the number of GeometricElt inside).";
throw Exception(oconv.str(), __FILE__, __LINE__);
......
......@@ -13,6 +13,7 @@
#include <string>
#include <list>
#include <deque>
#include <map>
#define BOOST_TEST_MODULE print_containers
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
......@@ -20,6 +21,8 @@
#include "Utilities/Containers/Print.hpp"
#include "Utilities/Containers/PrintPolicy/Variant.hpp"
#include "Utilities/Containers/PrintPolicy/Pointer.hpp"
#include "Utilities/Containers/PrintPolicy/Associative.hpp"
#include "Utilities/Containers/PrintPolicy/Key.hpp"
using namespace MoReFEM;
......@@ -69,7 +72,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<>::Do<3>(primes, oconv, ", ", "{", ", ... }");
Utilities::PrintContainer<>::Nelt<3>(primes, oconv, ", ", "{", ", ... }");
BOOST_CHECK_EQUAL(oconv.str(), "{2, 3, 5, ... }");
}
......@@ -100,6 +103,26 @@ BOOST_AUTO_TEST_CASE(print_vector_of_pointer)
}
BOOST_AUTO_TEST_CASE(print_associative_containers)
{
std::map<std::string, unsigned int> map { { "triangle", 3 }, { "segment", 2 }, { "quadrangle", 4 } };
std::ostringstream oconv;
Utilities::PrintContainer<Utilities::PrintPolicyNS::Associative>::Do(map, oconv, ", ", "{ ", " }");
BOOST_CHECK_EQUAL(oconv.str(), "{ (quadrangle, 4), (segment, 2), (triangle, 3) }");
}
BOOST_AUTO_TEST_CASE(print_associative_keys)
{
std::map<std::string, unsigned int> map { { "triangle", 3 }, { "segment", 2 }, { "quadrangle", 4 } };
std::ostringstream oconv;
Utilities::PrintContainer<Utilities::PrintPolicyNS::Key>::Do(map, oconv, ", ", "{ ", " }");
BOOST_CHECK_EQUAL(oconv.str(), "{ quadrangle, segment, triangle }");
}
PRAGMA_DIAGNOSTIC(pop)
......
......@@ -77,39 +77,6 @@ namespace MoReFEM
StringT3&& closer = "]\n");
};
/*!
* \brief Print the \a N first elements of a non associative container (list, vector, deque, array, etc...)
*
* If container is smaller than \a N, print it completely.
*
* \tparam N Number of elements to display.
* \tparam StreamT Type of output stream considered
* \tparam ContainerT Type of the container to be displayed. It must define the method 'size()' (so
* std::forward_list won't work for instance).
*
* \param[in,out] stream Output stream in which container will be displayed
* \param[in] container Container displayed
* \param[in] separator Separator between two entries of the contained
* \param[in] opener Prefix used while displaying the container
* \param[in] closer Suffix used while displaying the container
*
* In most cases templates parameters can be determined implicitly at compile time:
* \code
* std::vector<double> foo { 1., 2., 3., 10., 42. };
* std::ostringstream oconv;
* PrintContainer(foo, oconv, " ", "---", "---")
* \endcode
* This code yields:
* ---1. 2. 3. 10. 42.---
*/
template <class PrintPolicyT = PrintPolicyNS::Normal>
struct PrintNelt
{
template
<
std::size_t N,
......@@ -119,8 +86,8 @@ namespace MoReFEM
typename StringT2 = std::string,
typename StringT3 = std::string
>
static void Do(const ContainerT& container, StreamT& stream = std::cout,
StringT1&& separator = ", ",
static void Nelt(const ContainerT& container, StreamT& stream = std::cout,
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
......@@ -128,89 +95,6 @@ namespace MoReFEM
};
/*!
* \brief Print the keys of an associative container (set, map, multimap, unordered_map, ...)
*
* Essentially the same as PrintContainer(), except that only the keys are printed
*
* \tparam StreamT Type of output stream considered
* \tparam AssociativeContainerT Type of the container to be displayed
*
* \param[in,out] stream Output stream in which container keys will be displayed
* \param[in] container Container which keys are displayed
* \param[in] separator Separator between two entries of the contained
* \param[in] opener Prefix used while displaying the container
* \param[in] closer Suffix used while displaying the container
*
* In most cases templates parameters can be determined implicitly at compile time:
* \code
* std::unordered_map<double, int> foo { {1., 1},
* {2., 2},
* {3., 10},
* {10., 52},
* {42., 2},
* std::ostringstream oconv;
* PrintKeys(foo, oconv, " ", "---", "---")
* \endcode
* This code yields:
* ---1. 2. 3. 10. 42.---
*/
template
<
class AssociativeContainerT,
typename StreamT = std::ostream,
typename StringT1 = std::string,
typename StringT2 = std::string,
typename StringT3 = std::string
>
void PrintKeys(const AssociativeContainerT& container, StreamT& stream = std::cout,
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
/*!
* \brief Print an associative container (set, map, multimap, unordered_map, ...)
*
* Essentially the same as PrintContainer()
*
* \tparam StreamT Type of output stream considered
* \tparam AssociativeContainerT Type of the container to be displayed
*
* \param[in,out] stream Output stream in which container keys will be displayed
* \param[in] container Container which content is displayed.
* \param[in] separator Separator between two entries of the container.
* \param[in] opener Prefix ued while displaying the container.
* \param[in] closer Suffix ued while displaying the container.
*
* In most cases templates parameters can be determined implicitly at compile time:
* \code
* std::unordered_map<double, int> foo { {1., 1},
* {2., 2},
* {3., 10},
* {10., 52},
* {42., 2},
* std::ostringstream oconv;
* PrintKeys(foo, oconv, " ", "---", "---")
* \endcode
* This code yields:
* ---(1., 1) (2., 2) (3., 10) (10., 52) (42., 2)---
*/
template
<
class AssociativeContainerT,
typename StreamT = std::ostream,
typename StringT1 = std::string,
typename StringT2 = std::string,
typename StringT3 = std::string
>
void PrintAssociativeContainer(const AssociativeContainerT& container, StreamT& stream = std::cout,
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
/*!
* \brief Print the content of a tuple or a pair.
......
......@@ -48,8 +48,8 @@ namespace MoReFEM
typename StringT2,
typename StringT3
>
void PrintNelt<PrintPolicyT>::Do(const ContainerT& container, StreamT& stream,
StringT1&& separator, StringT2&& opener, StringT3&& closer)
void PrintContainer<PrintPolicyT>::Nelt(const ContainerT& container, StreamT& stream,
StringT1&& separator, StringT2&& opener, StringT3&& closer)
{
stream << opener;
......@@ -67,99 +67,6 @@ namespace MoReFEM
}
template
<
class ContainerT,
typename StreamT,
typename StringT1,
typename StringT2,
typename StringT3
>
void PrintPointerContainer(const ContainerT& container, StreamT& stream,
StringT1&& separator, StringT2&& opener, StringT3&& closer)
{
stream << opener;
auto it = container.cbegin();
auto end = container.cend();
auto size = container.size();
static_cast<void>(end); // avoid compilation warning in release mode
for (decltype(size) i = 0u; i + 1u < size; ++it, ++i)
{
assert(it != end);
stream << *(*it) << separator;
}
if (size > 0u)
stream << *(*it);
stream << closer;
}
template
<
class AssociativeContainerT,
typename StreamT,
typename StringT1,
typename StringT2,
typename StringT3
>
void PrintKeys(const AssociativeContainerT& container, StreamT& stream,
StringT1&& separator, StringT2&& opener, StringT3&& closer)
{
stream << opener;
auto it = container.cbegin();
auto end = container.cend();
auto size = container.size();
(void) end; // avoid compilation warning in release mode
for (decltype(size) i = 0u; i + 1u < size; ++it, ++i)
{
assert(it != end);
stream << it->first << separator;
}
if (size > 0u)
stream << it->first;
stream << closer;
}
template
<
class AssociativeContainerT,
typename StreamT,
typename StringT1,
typename StringT2,
typename StringT3
>
void PrintAssociativeContainer(const AssociativeContainerT& container, StreamT& stream,
StringT1&& separator, StringT2&& opener, StringT3&& closer)
{
stream << opener;
auto it = container.cbegin();
auto end = container.cend();
auto size = container.size();
(void) end; // avoid compilation warning in release mode
for (decltype(size) i = 0u; i + 1u < size; ++it, ++i)
{
assert(it != end);
stream << '(' << it->first << ", " << it->second << ')' << separator;
}
if (size > 0u)
stream << '(' << it->first << ", " << it->second << ')';
stream << closer;
}
template
<
class TupleT,
......
//! \file
//! \file
//
//
// Associative.hpp
......@@ -8,8 +8,8 @@
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef _____PROJECTNAMEASIDENTIFIER________FILEBASENAMEASIDENTIFIER_____HPP
# define _____PROJECTNAMEASIDENTIFIER________FILEBASENAMEASIDENTIFIER_____HPP
#ifndef MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_ASSOCIATIVE_HPP_
# define MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_ASSOCIATIVE_HPP_
# include <memory>
# include <vector>
......@@ -28,7 +28,7 @@ namespace MoReFEM::Utilities::PrintPolicyNS
static void Do(std::ostream& stream, ElementTypeT&& element);
};
} // namespace MoReFEM::Utilities::PrintPolicyNS
......@@ -36,4 +36,4 @@ namespace MoReFEM::Utilities::PrintPolicyNS
# include "Utilities/Containers/PrintPolicy/Associative.hxx"
#endif /* defined(_____PROJECTNAMEASIDENTIFIER________FILEBASENAMEASIDENTIFIER_____HPP) */
#endif // MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_ASSOCIATIVE_HPP_
//! \file
//! \file
//
//
// Associative.hxx
......@@ -8,8 +8,8 @@
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef _____PROJECTNAMEASIDENTIFIER________FILEBASENAMEASIDENTIFIER_____HXX
# define _____PROJECTNAMEASIDENTIFIER________FILEBASENAMEASIDENTIFIER_____HXX
#ifndef MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_ASSOCIATIVE_HXX_
# define MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_ASSOCIATIVE_HXX_
namespace MoReFEM::Utilities::PrintPolicyNS
......@@ -26,4 +26,4 @@ namespace MoReFEM::Utilities::PrintPolicyNS
} // namespace MoReFEM::Utilities::PrintPolicyNS
#endif /* defined(_____PROJECTNAMEASIDENTIFIER________FILEBASENAMEASIDENTIFIER_____HXX) */
#endif // MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_ASSOCIATIVE_HXX_
//! \file
//
//
// Associative.hpp
// MoReFEM
//
// Created by sebastien on 24/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_KEYS_HPP_
# define MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_KEYS_HPP_
# include <memory>
# include <vector>
namespace MoReFEM::Utilities::PrintPolicyNS
{
struct Key
{
public:
template<class ElementTypeT>
static void Do(std::ostream& stream, ElementTypeT&& element);
};
} // namespace MoReFEM::Utilities::PrintPolicyNS
# include "Utilities/Containers/PrintPolicy/Key.hxx"
#endif // MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_KEYS_HPP_
//! \file
//
//
// Associative.hxx
// MoReFEM
//
// Created by sebastien on 24/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_KEYS_HXX_
# define MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_KEYS_HXX_
namespace MoReFEM::Utilities::PrintPolicyNS
{
template<class ElementTypeT>
void Key::Do(std::ostream& stream, ElementTypeT&& element)
{
stream << element.first;
}
} // namespace MoReFEM::Utilities::PrintPolicyNS
#endif // MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_POLICY_x_KEYS_HXX_
......@@ -10,6 +10,10 @@
target_sources(${MOREFEM_UTILITIES}
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/Associative.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Associative.hxx"
"${CMAKE_CURRENT_LIST_DIR}/Key.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Key.hxx"
"${CMAKE_CURRENT_LIST_DIR}/Normal.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Normal.hxx"
"${CMAKE_CURRENT_LIST_DIR}/Pointer.hpp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment