Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
SafeConstArrayView.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/utils/Precomp.h>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Alien
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32template <typename T>
33class SafeConstArrayView : private ConstArrayView<T>
34{
35 public:
36 //! Classe de base
37 typedef ConstArrayView<T> BaseArrayView;
38
39 public:
40 //! Constructeur par d�faut
42
43 //! Constructeur � partir d'une vue
44 SafeConstArrayView(ConstArrayView<T> view)
46 {}
47
48 // Constructeur de copie
49 SafeConstArrayView(const SafeConstArrayView<T>& src) = default;
50
51 //! Constructeur � partir d'un array
52 SafeConstArrayView(const SharedArray<T>& array)
53 : m_array(array)
54 {
55 this->setArray(m_array.view());
56 }
57
58 //! Destructeur de la classe
60
61 //! Egalit� avec une vue (on lib�re le array)
62 SafeConstArrayView& operator=(ConstArrayView<T> view)
63 {
64 m_array = SharedArray<T>();
65 BaseArrayView::operator=(view);
66 return *this;
67 }
68
69 //! Egalit� avec un array (on r�f�rence le array)
70 SafeConstArrayView& operator=(const SharedArray<T>& array)
71 {
72 m_array = array;
73 setArray(m_array.view());
74 return *this;
75 }
76
77 public:
78 //! Type des �l�ments du tableau
79 typedef typename BaseArrayView::value_type value_type;
80 //! Type de l'it�rateur constant sur un �l�ment du tableau
81 typedef typename BaseArrayView::const_iterator const_iterator;
82 //! Type pointeur constant d'un �l�ment du tableau
83 typedef typename BaseArrayView::const_pointer const_pointer;
84 //! Type r�f�rence constante d'un �l�ment du tableau
85 typedef typename BaseArrayView::const_reference const_reference;
86 //! Type indexant le tableau
87 typedef typename BaseArrayView::size_type size_type;
88 //! Type d'une distance entre it�rateur �l�ments du tableau
89 typedef typename BaseArrayView::difference_type difference_type;
90
91 public:
92 //! \brief Sous-vue (constante) � partir de l'�l�ment \a begin et contenant \a size
93 //! �l�ments.
94 using BaseArrayView::subView;
95 //! Sous-vue (constante) � partir de l'�l�ment \a begin et contenant \a size �l�ments.
96 using BaseArrayView::subConstView;
97 //! Sous-vue correspondant � l'interval \a index sur \a nb_interval
98 using BaseArrayView::subViewInterval;
99 //! i-�me �l�ment du tableau.
100 using BaseArrayView::operator[];
101 //! i-�me �l�ment du tableau.
102 using BaseArrayView::item;
103 //! Nombre d'�l�ments du tableau
104 using BaseArrayView::size;
105 //! Nombre d'�l�ments du tableau
106 using BaseArrayView::length;
107 //! Iterateur sur le premier �l�ment du tableau
108 using BaseArrayView::begin;
109 //! Iterateur sur le premier �l�ment apr�s la fin du tableau
110 using BaseArrayView::end;
111 //! \a true si le tableau est vide (size()==0)
112 using BaseArrayView::empty;
113 //! \a true si le tableau contient l'�l�ment de valeur \a v
114 using BaseArrayView::contains;
115
116 public:
117 //! Retourne une vue du SafeConstArrayView
118 BaseArrayView view() const { return *this; }
119
120 private:
121 SharedArray<T> m_array;
122};
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127} // namespace Alien
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
virtual ~SafeConstArrayView()
Destructeur de la classe.
SafeConstArrayView & operator=(ConstArrayView< T > view)
Egalit� avec une vue (on lib�re le array).
BaseArrayView::const_pointer const_pointer
Type pointeur constant d'un �l�ment du tableau.
SafeConstArrayView & operator=(const SharedArray< T > &array)
Egalit� avec un array (on r�f�rence le array).
BaseArrayView::size_type size_type
Type indexant le tableau.
BaseArrayView::const_reference const_reference
Type r�f�rence constante d'un �l�ment du tableau.
ConstArrayView< T > BaseArrayView
Classe de base.
SafeConstArrayView(const SharedArray< T > &array)
Constructeur � partir d'un array.
BaseArrayView::value_type value_type
Type des �l�ments du tableau.
SafeConstArrayView()
Constructeur par d�faut.
BaseArrayView view() const
Retourne une vue du SafeConstArrayView.
BaseArrayView::difference_type difference_type
Type d'une distance entre it�rateur �l�ments du tableau.
BaseArrayView::const_iterator const_iterator
Type de l'it�rateur constant sur un �l�ment du tableau.
SafeConstArrayView(ConstArrayView< T > view)
Constructeur � partir d'une vue.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17