Commit d362e120 authored by GILLES Sebastien's avatar GILLES Sebastien

#1470 Reorganize the Utilities/Containers/Print in several files to conform...

#1470 Reorganize the Utilities/Containers/Print in several files to conform with the layout of the rest of the code.
parent 22180104
......@@ -532,6 +532,8 @@
BE353BA622E76CF500A06A8F /* ConvertEntryToString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE353BA322E76CF500A06A8F /* ConvertEntryToString.cpp */; };
BE353BA722E76CF500A06A8F /* ConvertEntryToString.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE353BA422E76CF500A06A8F /* ConvertEntryToString.hxx */; };
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 */; };
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 */; };
......@@ -3426,6 +3428,9 @@
BE353BA522E76CF500A06A8F /* ConvertEntryToString.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ConvertEntryToString.hpp; sourceTree = "<group>"; };
BE353BAA22E77F5C00A06A8F /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
BE353BAB22E77F5C00A06A8F /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
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>"; };
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>"; };
......@@ -5979,6 +5984,8 @@
BE83582A1FFD779E0009956E /* Sort.hpp */,
BE83582C1FFD78DD0009956E /* Sort.hxx */,
BE110E8C1E114F1400D2D2C8 /* TupleHelper.hpp */,
BE353BB122E83AF800A06A8F /* Print.hpp */,
BE353BB022E83AF800A06A8F /* Print.hxx */,
);
path = Internal;
sourceTree = "<group>";
......@@ -9687,6 +9694,7 @@
BEB991B718F42080009ACA4C /* EnumClass.hpp */,
BEB991BE18F42080009ACA4C /* Tuple.hpp */,
BEB991BA18F42080009ACA4C /* Print.hpp */,
BE353BAD22E83A4700A06A8F /* Print.hxx */,
BE56573F1D3CD7470091F063 /* Array.hpp */,
BE5657401D3CD7470091F063 /* Array.hxx */,
BEB991B818F42080009ACA4C /* PointerComparison.hpp */,
......@@ -11299,6 +11307,7 @@
BE90E16F1A24926E00CCAFDE /* BoolArray.hxx in Headers */,
BE90E1831A24929A00CCAFDE /* InputData.hpp in Headers */,
BE41E96E1AC3F92A0072C8E6 /* EmptyString.hpp in Headers */,
BE353BB422E83AF800A06A8F /* Print.hpp in Headers */,
BE5B6F921C3C16E9004A0284 /* ShellMatrix.hxx in Headers */,
BE90E17D1A24929A00CCAFDE /* Base.hxx in Headers */,
BE1EBB021CA0961000EC0EAA /* InputData.hpp in Headers */,
......@@ -11432,6 +11441,7 @@
BE76F2551D7D5DE90061B50E /* CSRPattern.hpp in Headers */,
BE90E1D21A2492AA00CCAFDE /* Seldon.hpp in Headers */,
BE90E1B31A24929A00CCAFDE /* AccessVectorContent.hpp in Headers */,
BE353BB322E83AF800A06A8F /* Print.hxx in Headers */,
BE1459FC1E54BC49000A2BF5 /* Arg.h in Headers */,
BE76F2631D7D60660061B50E /* GlobalVectorTemporaryStorage.hxx in Headers */,
BEFE4F101CBD23200087DD1F /* PetscMatPrivate.h in Headers */,
//! \file
//
//
// Print.hpp
// MoReFEM
//
// Created by sebastien on 24/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_CONTAINERS_x_INTERNAL_x_PRINT_HPP_
# define MOREFEM_x_UTILITIES_x_CONTAINERS_x_INTERNAL_x_PRINT_HPP_
# include <tuple>
namespace MoReFEM::Internal::TupleNS
{
/*!
** \brief Facility to print elements of a tuple
**
** Inspired by Nicolai M. Josuttis "The C++ standard library" page 74
*/
template<class StreamT, unsigned int Index, unsigned int Max, class TupleT>
struct PrintTupleHelper
{
/*!
* \brief Static function that does the actual work.
*
* \param[in,out] stream Stream to which the tuple will be printed.
* \param[in] t Tuple to display.
* \param[in] separator Separator between all elements of the tuple.
*/
template<typename StringT>
static void Print(StreamT& stream, const TupleT& t, const StringT& separator);
};
//! Specialization used to stop recursive call.
template<class StreamT, unsigned int Max, class TupleT>
struct PrintTupleHelper<StreamT, Max, Max, TupleT>
{
//! Nothing done here in the specialization.
template<typename StringT>
static void Print(StreamT&, const TupleT& , const StringT&);
};
} // namespace MoReFEM::Internal::TupleNS
# include "Utilities/Containers/Internal/Print.hxx"
#endif // MOREFEM_x_UTILITIES_x_CONTAINERS_x_INTERNAL_x_PRINT_HPP_
//! \file
//
//
// Print.hxx
// MoReFEM
//
// Created by sebastien on 24/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_CONTAINERS_x_INTERNAL_x_PRINT_HXX_
# define MOREFEM_x_UTILITIES_x_CONTAINERS_x_INTERNAL_x_PRINT_HXX_
namespace MoReFEM::Internal::TupleNS
{
template<class StreamT, unsigned int Index, unsigned int Max, class TupleT>
template<typename StringT>
void PrintTupleHelper<StreamT, Index, Max, TupleT>
::Print(StreamT& stream, const TupleT& t, const StringT& separator)
{
using EltTupleType = typename std::tuple_element<Index,TupleT>::type;
const auto quote =
Utilities::String::IsString<EltTupleType>::value ? "\"" : "";
stream << quote << std::get<Index>(t) << quote << (Index + 1 == Max ? "" : separator);
PrintTupleHelper<StreamT, Index + 1, Max, TupleT>::Print(stream, t, separator);
};
template<class StreamT, unsigned int Max, class TupleT>
template<typename StringT>
void PrintTupleHelper<StreamT, Max, Max, TupleT>::Print(StreamT&, const TupleT& , const StringT&)
{
// Do nothing!
}
} // namespace MoReFEM::Internal::TupleNS
#endif // MOREFEM_x_UTILITIES_x_CONTAINERS_x_INTERNAL_x_PRINT_HXX_
......@@ -10,6 +10,8 @@
target_sources(${MOREFEM_UTILITIES}
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/Print.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Print.hxx"
"${CMAKE_CURRENT_LIST_DIR}/Sort.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Sort.hxx"
"${CMAKE_CURRENT_LIST_DIR}/TupleHelper.hpp"
......
This diff is collapsed.
/*!
*/
#ifndef MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_HXX_
# define MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_HXX_
namespace MoReFEM
{
namespace Utilities
{
template
<
class ContainerT,
typename StreamT,
typename StringT1,
typename StringT2,
typename StringT3
>
void PrintContainer(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);
// If one of the element is a std::variant, it may be printed... provided the type within the
// variant overloas properly operator<< !
if constexpr (Utilities::IsSpecializationOf
<
std::variant,
typename ContainerT::value_type
>())
{
std::visit([&stream](auto&& arg)
{
using type_arg = std::decay_t<decltype(arg)>;
if constexpr (Utilities::IsSpecializationOf
<
std::map,
type_arg
>())
{
stream << "Map!";
}
else if constexpr (std::is_same_v<type_arg, std::nullptr_t>)
stream << "Nullptr!";
else
stream << arg;
},
*it);
}
else
stream << *it;
stream << separator;
}
if (size > 0u)
{
// TMP: this is not DRY !!!
if constexpr (Utilities::IsSpecializationOf
<
std::variant,
typename ContainerT::value_type
>())
{
std::visit([&stream](auto&& arg)
{
using type_arg = std::decay_t<decltype(arg)>;
if constexpr (Utilities::IsSpecializationOf
<
std::map,
type_arg
>())
{
stream << "Map!";
}
else if constexpr (std::is_same_v<type_arg, std::nullptr_t>)
stream << "Nullptr!";
else
stream << arg;
},
*it);
}
else
stream << *it;
}
stream << closer;
}
template
<
unsigned int N,
class ContainerT,
typename StreamT,
typename StringT1,
typename StringT2,
typename StringT3
>
void PrintNelt(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();
(void) end; // avoid compilation warning in release mode
const auto stop = std::min(size, static_cast<decltype(size)>(N));
for (decltype(size) i = 0; i + 1 < stop; ++it, ++i)
{
assert(it != end);
stream << *it << separator;
}
if (size > 0u)
stream << *it;
if (N < size)
stream << separator << "...";
stream << closer;
}
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,
typename StreamT,
typename StringT1,
typename StringT2,
typename StringT3
>
void PrintTuple(const TupleT& tuple,
StreamT& stream,
StringT1 separator,
StringT2 opener,
StringT3 closer)
{
stream << opener;
enum { size = std::tuple_size<TupleT>::value };
Internal::TupleNS::PrintTupleHelper<StreamT, 0, size, TupleT>::Print(stream, tuple, separator);
stream << closer;
}
} // namespace Utilities
} // namespace MoReFEM
/// @} // addtogroup UtilitiesGroup
#endif // MOREFEM_x_UTILITIES_x_CONTAINERS_x_PRINT_HXX_
......@@ -21,6 +21,7 @@ target_sources(${MOREFEM_UTILITIES}
"${CMAKE_CURRENT_LIST_DIR}/PointerComparison.hpp"
"${CMAKE_CURRENT_LIST_DIR}/PointerComparison.hxx"
"${CMAKE_CURRENT_LIST_DIR}/Print.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Print.hxx"
"${CMAKE_CURRENT_LIST_DIR}/Sort.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Tuple.hpp"
"${CMAKE_CURRENT_LIST_DIR}/UnorderedMap.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