Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
BaseVectorWriter.h
1/*
2 * Copyright 2020 IFPEN-CEA
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19#pragma once
20
21#include <alien/data/IVector.h>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Alien
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34class Timestamp;
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace Common
40{
41
42 /*---------------------------------------------------------------------------*/
43 /*---------------------------------------------------------------------------*/
44
45 template <typename ValueT>
46 class VectorWriterBaseT
47 {
48 public:
49 typedef ValueT ValueType;
50
51 public:
52 VectorWriterBaseT(IVector& vector, bool update = true);
53
54 virtual ~VectorWriterBaseT() { end(); }
55
56 void end();
57
58 void operator=(const ValueType v);
59
60 protected:
61 ArrayView<ValueType> m_values;
62 Timestamp* m_time_stamp;
63 Integer m_local_offset;
64 bool m_finalized;
65 };
66
67 /*---------------------------------------------------------------------------*/
68
69 template <typename ValueT, typename Parameters>
70 class VectorWriterT : public VectorWriterBaseT<ValueT>
71 {
72 public:
73 using ValueType = ValueT;
74
75 private:
76 using Indexer = typename Parameters::Indexer;
77
78 public:
79 using VectorElement = VectorElementT<ValueT, Indexer>;
80 using MultVectorElement = MultVectorElementT<ValueT, Indexer>;
81 using MultVectorElement2 = MultVectorElement2T<ValueT, Indexer>;
82
83 using VectorWriterBaseT<ValueT>::operator=;
84
85 VectorWriterT(IVector& vector);
86
87 virtual ~VectorWriterT() {}
88
89 inline ValueType& operator[](Integer iIndex)
90 {
91 const Integer id = Indexer::index(iIndex, this->m_local_offset);
92 return this->m_values[id];
93 }
94
95 inline Integer size() const { return this->m_values.size(); }
96
97 inline VectorElement operator()(ConstArrayView<Integer> indexes)
98 {
99 return VectorElement(this->m_values, indexes, this->m_local_offset);
100 }
101
102 inline MultVectorElement operator()(
103 ValueType factor, ConstArrayView<Integer> indexes)
104 {
105 return MultVectorElement(this->m_values, factor, indexes, this->m_local_offset);
106 }
107
108 inline MultVectorElement2 operator()(
109 ValueType factor, ConstArray2View<Integer> indexes, Integer i)
110 {
111 return MultVectorElement2(this->m_values, factor, indexes, i, this->m_local_offset);
112 }
113 };
114
115 /*---------------------------------------------------------------------------*/
116 /*---------------------------------------------------------------------------*/
117
118} // namespace Common
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123} // namespace Alien
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128#include "VectorWriterT.h"
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
IVector.h.
Parameters.h.
VectorElement.h.
Interface for all vectors.
Definition IVector.h:51
Tool to manipulate and scale a vector entry while building a block vector.
Tool to manipulate and scale a vector entry while building a vector.
Tool to manipulate a vector entry while building a vector.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17