10 #ifndef vtk_m_VecFlat_h
11 #define vtk_m_VecFlat_h
26 struct TotalNumComponents;
29 struct TotalNumComponents<T,
vtkm::VecTraitsTagMultipleComponents>
33 "vtkm::VecFlat can only be used with Vec types with a static number of components.");
40 struct TotalNumComponents<T,
vtkm::VecTraitsTagSingleComponent>
47 vtkm::internal::TotalNumComponents<T>::value>;
50 using IsFlatVec =
typename std::is_same<T, FlattenVec<T>>::type;
69 using ComponentType =
typename Traits::ComponentType;
70 using BaseComponentType =
typename Traits::BaseComponentType;
73 return GetFlatVecComponentImpl(Traits::GetComponent(vec, index / subSize),
75 typename std::is_same<ComponentType, BaseComponentType>::type{});
85 return detail::GetFlatVecComponentImpl(vec, index, std::false_type{});
91 template <
typename T, vtkm::IdComponent N>
96 flatVec[flatOffset] = nestedVec;
99 template <
typename T, vtkm::IdComponent NFlat, vtkm::IdComponent NNest>
106 flatVec[nestedIndex + flatOffset] = nestedVec[nestedIndex];
110 template <
typename T, vtkm::IdComponent N,
typename NestedVecType>
111 VTKM_EXEC_CONT void CopyVecNestedToFlatImpl(
const NestedVecType& nestedVec,
116 using ComponentType =
typename Traits::ComponentType;
120 for (
vtkm::IdComponent nestIndex = 0; nestIndex < Traits::NUM_COMPONENTS; ++nestIndex)
122 CopyVecNestedToFlatImpl(Traits::GetComponent(nestedVec, nestIndex), flatVec, flatIndex);
123 flatIndex += subSize;
129 template <
typename T, vtkm::IdComponent N,
typename NestedVecType>
132 detail::CopyVecNestedToFlatImpl(nestedVec, flatVec, 0);
138 template <
typename T, vtkm::IdComponent N>
143 nestedVec = flatVec[flatOffset];
146 template <
typename T, vtkm::IdComponent NFlat, vtkm::IdComponent NNest>
153 nestedVec[nestedIndex] = flatVec[nestedIndex + flatOffset];
157 template <
typename T, vtkm::IdComponent NFlat,
typename ComponentType, vtkm::IdComponent NNest>
167 CopyVecFlatToNestedImpl(flatVec, flatIndex, nestedVec[nestIndex]);
168 flatIndex += subSize;
172 template <
typename T, vtkm::IdComponent N,
typename NestedVecType>
175 NestedVecType& nestedVec)
178 using ComponentType =
typename Traits::ComponentType;
182 for (
vtkm::IdComponent nestIndex = 0; nestIndex < Traits::NUM_COMPONENTS; ++nestIndex)
184 ComponentType component;
185 CopyVecFlatToNestedImpl(flatVec, flatIndex, component);
186 Traits::SetComponent(nestedVec, nestIndex, component);
187 flatIndex += subSize;
193 template <
typename T, vtkm::IdComponent N,
typename NestedVecType>
196 detail::CopyVecFlatToNestedImpl(flatVec, 0, nestedVec);
223 template <typename T, bool = internal::IsFlatVec<T>::value>
227 template <
typename T>
233 using Superclass::Superclass;
240 internal::CopyVecNestedToFlat(src, *
this);
247 internal::CopyVecFlatToNested(*
this, nestedVec);
253 template <
typename T>
267 this->T::operator=(src);
273 this->T::operator=(std::move(src));
280 template <
typename T>
286 template <
typename T>
291 template <
typename T>
298 #endif //vtk_m_VecFlat_h