@@ -58,6 +58,10 struct Sort<1> { | |||
|
58 | 58 | template <int Dim> |
|
59 | 59 | class ArrayData { |
|
60 | 60 | public: |
|
61 | // ///// // | |
|
62 | // Ctors // | |
|
63 | // ///// // | |
|
64 | ||
|
61 | 65 | /** |
|
62 | 66 | * Ctor for a unidimensional ArrayData |
|
63 | 67 | * @param data the data the ArrayData will hold |
@@ -104,52 +108,9 public: | |||
|
104 | 108 | m_Data = other.m_Data; |
|
105 | 109 | } |
|
106 | 110 | |
|
107 | /** | |
|
108 | * @return the data at a specified index | |
|
109 | * @remarks index must be a valid position | |
|
110 | * @remarks this method is only available for a unidimensional ArrayData | |
|
111 | */ | |
|
112 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
113 | double at(int index) const noexcept | |
|
114 | { | |
|
115 | QReadLocker locker{&m_Lock}; | |
|
116 | return m_Data[0].at(index); | |
|
117 | } | |
|
118 | ||
|
119 | /** | |
|
120 | * @return the data as a vector | |
|
121 | * @remarks this method is only available for a unidimensional ArrayData | |
|
122 | */ | |
|
123 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
124 | QVector<double> data() const noexcept | |
|
125 | { | |
|
126 | QReadLocker locker{&m_Lock}; | |
|
127 | return m_Data[0]; | |
|
128 | } | |
|
129 | ||
|
130 | /** | |
|
131 | * @return the data of a component | |
|
132 | * @param componentIndex the index of the component to retrieve the data | |
|
133 | * @return the component's data, empty vector if the index is invalid | |
|
134 | */ | |
|
135 | QVector<double> data(int componentIndex) const noexcept | |
|
136 | { | |
|
137 | QReadLocker locker{&m_Lock}; | |
|
138 | ||
|
139 | return (componentIndex >= 0 && componentIndex < m_Data.size()) ? m_Data.at(componentIndex) | |
|
140 | : QVector<double>{}; | |
|
141 | } | |
|
142 | ||
|
143 | /** | |
|
144 | * @return the data as a vector, as a const reference | |
|
145 | * @remarks this method is only available for a unidimensional ArrayData | |
|
146 | */ | |
|
147 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
148 | const QVector<double> &cdata() const noexcept | |
|
149 | { | |
|
150 | QReadLocker locker{&m_Lock}; | |
|
151 | return m_Data.at(0); | |
|
152 | } | |
|
111 | // /////////////// // | |
|
112 | // General methods // | |
|
113 | // /////////////// // | |
|
153 | 114 | |
|
154 | 115 | /** |
|
155 | 116 | * Merges into the array data an other array data. The two array datas must have the same number |
@@ -186,6 +147,29 public: | |||
|
186 | 147 | } |
|
187 | 148 | } |
|
188 | 149 | |
|
150 | void clear() | |
|
151 | { | |
|
152 | QWriteLocker locker{&m_Lock}; | |
|
153 | ||
|
154 | auto nbComponents = m_Data.size(); | |
|
155 | for (auto i = 0; i < nbComponents; ++i) { | |
|
156 | m_Data[i].clear(); | |
|
157 | } | |
|
158 | } | |
|
159 | ||
|
160 | /** | |
|
161 | * @return the data of a component | |
|
162 | * @param componentIndex the index of the component to retrieve the data | |
|
163 | * @return the component's data, empty vector if the index is invalid | |
|
164 | */ | |
|
165 | QVector<double> data(int componentIndex) const noexcept | |
|
166 | { | |
|
167 | QReadLocker locker{&m_Lock}; | |
|
168 | ||
|
169 | return (componentIndex >= 0 && componentIndex < m_Data.size()) ? m_Data.at(componentIndex) | |
|
170 | : QVector<double>{}; | |
|
171 | } | |
|
172 | ||
|
189 | 173 | /// @return the size (i.e. number of values) of a single component |
|
190 | 174 | /// @remarks in a case of a two-dimensional ArrayData, each component has the same size |
|
191 | 175 | int size() const |
@@ -200,14 +184,42 public: | |||
|
200 | 184 | return arraydata_detail::Sort<Dim>::sort(m_Data, sortPermutation); |
|
201 | 185 | } |
|
202 | 186 | |
|
203 | void clear() | |
|
187 | // ///////////// // | |
|
188 | // 1-dim methods // | |
|
189 | // ///////////// // | |
|
190 | ||
|
191 | /** | |
|
192 | * @return the data at a specified index | |
|
193 | * @remarks index must be a valid position | |
|
194 | * @remarks this method is only available for a unidimensional ArrayData | |
|
195 | */ | |
|
196 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
197 | double at(int index) const noexcept | |
|
204 | 198 | { |
|
205 |
Q |
|
|
199 | QReadLocker locker{&m_Lock}; | |
|
200 | return m_Data[0].at(index); | |
|
201 | } | |
|
206 | 202 | |
|
207 | auto nbComponents = m_Data.size(); | |
|
208 | for (auto i = 0; i < nbComponents; ++i) { | |
|
209 | m_Data[i].clear(); | |
|
210 |
|
|
|
203 | /** | |
|
204 | * @return the data as a vector, as a const reference | |
|
205 | * @remarks this method is only available for a unidimensional ArrayData | |
|
206 | */ | |
|
207 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
208 | const QVector<double> &cdata() const noexcept | |
|
209 | { | |
|
210 | QReadLocker locker{&m_Lock}; | |
|
211 | return m_Data.at(0); | |
|
212 | } | |
|
213 | ||
|
214 | /** | |
|
215 | * @return the data as a vector | |
|
216 | * @remarks this method is only available for a unidimensional ArrayData | |
|
217 | */ | |
|
218 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
|
219 | QVector<double> data() const noexcept | |
|
220 | { | |
|
221 | QReadLocker locker{&m_Lock}; | |
|
222 | return m_Data[0]; | |
|
211 | 223 | } |
|
212 | 224 | |
|
213 | 225 | private: |
General Comments 0
You need to be logged in to leave comments.
Login now