Commit 78dc5073 authored by GILLES Sebastien's avatar GILLES Sebastien

#279 - #1470 Replace PrintPointerContainer by PrintContainer with the dedicated Pointer policy.

parent 2fcf1dd0
......@@ -24,6 +24,7 @@
# include "Utilities/Containers/Print.hpp"
# include "Utilities/Containers/PointerComparison.hpp"
# include "Utilities/Containers/PrintPolicy/Pointer.hpp"
# include "Geometry/Coords/Coords.hpp"
# include "Geometry/Interfaces/Interface.hpp"
......
......@@ -51,7 +51,8 @@ namespace MoReFEM
oconv << NatureT;
oconv << " -> [";
Utilities::PrintPointerContainer(GetVertexCoordsList(), out, ", ", oconv.str(), std::string("]"));
Utilities::PrintContainer<Utilities::PrintPolicyNS::Pointer>
::Do(GetVertexCoordsList(), out, ", ", oconv.str(), std::string("]"));
assert(GetIndex() != NumericNS::UninitializedIndex<decltype(GetIndex())>());
......
......@@ -19,6 +19,7 @@
#include "Utilities/Containers/Print.hpp"
#include "Utilities/Containers/PrintPolicy/Variant.hpp"
#include "Utilities/Containers/PrintPolicy/Pointer.hpp"
using namespace MoReFEM;
......@@ -93,7 +94,7 @@ BOOST_AUTO_TEST_CASE(print_vector_of_pointer)
vector_of_ptr.emplace_back(std::make_unique<std::size_t>(i));
std::ostringstream oconv;
Utilities::PrintPointerContainer(vector_of_ptr, oconv, ", ", "{ ", " }");
Utilities::PrintContainer<Utilities::PrintPolicyNS::Pointer>::Do(vector_of_ptr, oconv, ", ", "{ ", " }");
BOOST_CHECK_EQUAL(oconv.str(), "{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }");
}
......
......@@ -128,36 +128,6 @@ namespace MoReFEM
};
/*!
* \brief Print the content of a non associative container (list, vector, deque, array, etc...) after
* dereferencing pointers.
*
* \tparam StreamT Type of output stream considered.
* \tparam ContainerT Type of the container to be displayed.
*
* \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.
* // \todo #279 Fusion it with standard PrintContainer, with additional parameter to indicate whether pointers
* // should be deferenced or not (need a a bit of metaprogramming)
*/
template
<
class ContainerT,
typename StreamT = std::ostream,
typename StringT1 = std::string,
typename StringT2 = std::string,
typename StringT3 = std::string
>
void PrintPointerContainer(const ContainerT& container, StreamT& stream = std::cout,
StringT1&& separator = ", ",
StringT2&& opener = "[",
StringT3&& closer = "]\n");
/*!
* \brief Print the keys of an associative container (set, map, multimap, unordered_map, ...)
*
......@@ -169,8 +139,8 @@ namespace MoReFEM
* \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 ued while displaying the container
* \param[in] closer Suffix ued while displaying the container
* \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
......
......@@ -25,7 +25,7 @@ namespace MoReFEM::Utilities::PrintPolicyNS
public:
template<class ElementTypeT>
static void Do(std::ostream& stream, const ElementTypeT& element);
static void Do(std::ostream& stream, ElementTypeT&& element);
};
......
......@@ -17,7 +17,7 @@ namespace MoReFEM::Utilities::PrintPolicyNS
template<class ElementTypeT>
void Associative::Do(std::ostream& stream, const ElementTypeT& element)
void Associative::Do(std::ostream& stream, ElementTypeT&& element)
{
stream << '(' << element.first << ", " << element.second << ')';
}
......
......@@ -24,7 +24,7 @@ namespace MoReFEM::Utilities::PrintPolicyNS
public:
template<class ElementTypeT>
static void Do(std::ostream& stream, const ElementTypeT& element);
static void Do(std::ostream& stream, ElementTypeT&& element);
};
......
......@@ -17,7 +17,7 @@ namespace MoReFEM::Utilities::PrintPolicyNS
template<class ElementTypeT>
void Normal::Do(std::ostream& stream, const ElementTypeT& element)
void Normal::Do(std::ostream& stream, ElementTypeT&& element)
{
stream << element;
}
......
......@@ -25,7 +25,7 @@ namespace MoReFEM::Utilities::PrintPolicyNS
public:
template<class ElementTypeT>
static void Do(std::ostream& stream, const ElementTypeT& element);
static void Do(std::ostream& stream, ElementTypeT&& element);
};
......
......@@ -17,9 +17,11 @@ namespace MoReFEM::Utilities::PrintPolicyNS
template<class ElementTypeT>
void Pointer::Do(std::ostream& stream, const ElementTypeT& ptr)
void Pointer::Do(std::ostream& stream, ElementTypeT&& ptr)
{
static_assert(IsSharedPtr<ItemPtrT>() || std::is_pointer<ItemPtrT>() || IsUniquePtr<ItemPtrT>(),
using type = std::remove_cv_t<std::remove_reference_t<ElementTypeT>>;
static_assert(IsSharedPtr<type>() || std::is_pointer<type>() || IsUniquePtr<type>(),
"ptr must behaves like a pointer!");
stream << *ptr;
}
......
......@@ -27,7 +27,7 @@ namespace MoReFEM::Utilities::PrintPolicyNS
public:
template<class ElementTypeT>
static void Do(std::ostream& stream, const ElementTypeT& element);
static void Do(std::ostream& stream, ElementTypeT&& element);
};
......
......@@ -17,12 +17,14 @@ namespace MoReFEM::Utilities::PrintPolicyNS
template<class T>
void Variant::Do(std::ostream& stream, const T& value)
void Variant::Do(std::ostream& stream, T&& value)
{
using type = std::decay_t<T>;
if constexpr (Utilities::IsSpecializationOf
<
std::variant,
T
type
>())
{
std::visit([&stream](auto&& arg)
......
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