Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
IVectorConverter.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7
8
9#pragma once
10
11#include <alien/core/backend/BackEnd.h>
13#include <alien/utils/ObjectWithTrace.h>
14
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18namespace Alien
19{
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
35class IVectorConverter : public ObjectWithTrace
36{
37 public:
39 virtual ~IVectorConverter() {}
40
41 public:
46 virtual BackEndId sourceBackend() const = 0;
47
52 virtual BackEndId targetBackend() const = 0;
53
59 virtual void convert(const IVectorImpl* sourceImpl, IVectorImpl* targetImpl) const = 0;
60
61 protected:
66 template <typename T>
67 BackEndId backendId() const { return AlgebraTraits<T>::name(); }
68
77 template <typename T>
78 static T& cast(IVectorImpl* impl, [[maybe_unused]] BackEndId backend)
79 {
80 ALIEN_ASSERT((impl != NULL), ("Null implementation"));
81 ALIEN_ASSERT((impl->backend() == backend), ("Bad backend"));
82 T* t = dynamic_cast<T*>(impl);
83 ALIEN_ASSERT((t != NULL), ("Bad dynamic cast"));
84 return *t;
85 }
86
95 template <typename T>
96 static const T& cast(const IVectorImpl* impl, [[maybe_unused]] BackEndId backend)
97 {
98 ALIEN_ASSERT((impl != NULL), ("Null implementation"));
99 ALIEN_ASSERT((impl->backend() == backend), ("Bad backend"));
100 const T* t = dynamic_cast<const T*>(impl);
101 ALIEN_ASSERT((t != NULL), ("Bad dynamic cast"));
102 return *t;
103 }
104};
105
106template<typename SourceTagT,
107 typename TargetTagT>
109{
110public:
111 using SourceVectorType = typename AlgebraTraits<SourceTagT>::vector_type;
112 using TargetVectorType = typename AlgebraTraits<TargetTagT>::vector_type;
114 virtual ~VectorConverterT() {}
115
116 virtual void convert(SourceVectorType const& source, TargetVectorType& target) const = 0 ;
117};
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
121} // namespace Alien
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
IVectorImpl.h.
virtual ~IVectorConverter()
Free resources.
static T & cast(IVectorImpl *impl, BackEndId backend)
Cast a vector implementation in its actual type.
virtual void convert(const IVectorImpl *sourceImpl, IVectorImpl *targetImpl) const =0
Convert a vector from one format to another.
static const T & cast(const IVectorImpl *impl, BackEndId backend)
Const cast a vector implementation in its actual type.
virtual BackEndId targetBackend() const =0
Get the target backend id.
virtual BackEndId sourceBackend() const =0
Get the source backend id.
BackEndId backendId() const
Get the target backend id.
Interface to handle abstract vectors implementation.
Definition IVectorImpl.h:47
virtual BackEndId backend() const
Definition IVectorImpl.h:95
virtual ~VectorConverterT()
Free resources.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17