Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Dynamic/Morpheus_Copy_Impl.hpp
1
24#ifndef MORPHEUS_DYNAMIC_COPY_IMPL_HPP
25#define MORPHEUS_DYNAMIC_COPY_IMPL_HPP
26
27#include <Morpheus_Exceptions.hpp>
28#include <Morpheus_FormatTraits.hpp>
29#include <Morpheus_FormatTags.hpp>
30
31#include <impl/Morpheus_Copy_Impl.hpp>
32#include <impl/Morpheus_Variant.hpp>
33
34namespace Morpheus {
35namespace Impl {
36
37struct copy_fn {
38 using result_type = void;
39
40 template <typename SourceType, typename DestinationType>
41 result_type operator()(
42 const SourceType& src, DestinationType& dst,
43 typename std::enable_if_t<
46 SourceType, DestinationType>::value>* = nullptr) {
47 Impl::copy(src, dst);
48 }
49
50 // Needed for the compiler to generate all possible combinations
51 template <typename SourceType, typename DestinationType>
52 result_type operator()(
53 const SourceType& src, DestinationType& dst,
54 typename std::enable_if_t<
57 SourceType, DestinationType>::value)>* = nullptr) {
59 "Morpheus::copy() is only available between the same container types "
60 "(" +
61 std::to_string(src.format_index()) +
62 " != " + std::to_string(dst.format_index()) +
63 "). Please use Morpheus::convert() instead to perform conversions "
64 "between different types.");
65 }
66};
67
68template <typename SourceType, typename DestinationType>
69void copy(const SourceType& src, DestinationType& dst,
70 typename std::enable_if_t<
73 nullptr) {
74 if (src.const_formats().index() == static_cast<int>(dst.format_enum())) {
75 auto f = std::bind(Impl::copy_fn(), std::placeholders::_1, std::ref(dst));
76 Morpheus::Impl::Variant::visit(f, src.const_formats());
77 } else {
79 "Morpheus::copy() is only available between the same container types. "
80 "Active type of dynamic matrix should match the type of destination "
81 "matrix. Please use Morpheus::convert() instead to perform conversions "
82 "between different types.");
83 }
84}
85
86template <typename SourceType, typename DestinationType>
87void copy(
88 const SourceType& src, DestinationType& dst,
89 typename std::enable_if_t<
92 nullptr) {
93 auto f = std::bind(Impl::copy_fn(), std::cref(src), std::placeholders::_1);
94 Impl::Variant::visit(f, dst.formats());
95}
96
97template <typename SourceType, typename DestinationType>
98void copy(
99 const SourceType& src, DestinationType& dst,
100 typename std::enable_if_t<
103 nullptr) {
104 Impl::Variant::visit(Impl::copy_fn(), src.const_formats(), dst.formats());
105}
106
107} // namespace Impl
108} // namespace Morpheus
109
110#endif // MORPHEUS_DYNAMIC_COPY_IMPL_HPP
Definition: Morpheus_Exceptions.hpp:69
Checks if the given type T is a valid Dynamic Matrix Format Container i.e is valid matrix container a...
Definition: Morpheus_FormatTags.hpp:201
Checks if the two types are format compatible containers but from different memory space i....
Definition: Morpheus_FormatTraits.hpp:383
A valid Sparse Matrix container is the one that has a valid Sparse Matrix tag i.e satisfies the has_s...
Definition: Morpheus_FormatTraits.hpp:85
Generic Morpheus interfaces.
Definition: dummy.cpp:24
Definition: Dynamic/Morpheus_Copy_Impl.hpp:37
Checks if the two types are format compatible containers i.e are compatible containers and have the s...
Definition: Morpheus_FormatTraits.hpp:362