18 #ifndef viskores_VecFlat_h
19 #define viskores_VecFlat_h
34 struct TotalNumComponents;
37 struct TotalNumComponents<T,
viskores::VecTraitsTagMultipleComponents>
42 "viskores::VecFlat can only be used with Vec types with a static number of components.");
49 struct TotalNumComponents<T,
viskores::VecTraitsTagSingleComponent>
56 viskores::internal::TotalNumComponents<T>::value>;
59 using IsFlatVec =
typename std::is_same<T, FlattenVec<T>>::type;
80 using ComponentType =
typename Traits::ComponentType;
81 using BaseComponentType =
typename Traits::BaseComponentType;
84 return GetFlatVecComponentImpl(Traits::GetComponent(vec, index / subSize),
86 typename std::is_same<ComponentType, BaseComponentType>::type{});
96 return detail::GetFlatVecComponentImpl(vec, index, std::false_type{});
102 template <
typename T, viskores::IdComponent N>
107 flatVec[flatOffset] = nestedVec;
110 template <
typename T, viskores::IdComponent NFlat, viskores::IdComponent NNest>
117 flatVec[nestedIndex + flatOffset] = nestedVec[nestedIndex];
121 template <
typename T, viskores::IdComponent N,
typename NestedVecType>
127 using ComponentType =
typename Traits::ComponentType;
133 CopyVecNestedToFlatImpl(Traits::GetComponent(nestedVec, nestIndex), flatVec, flatIndex);
134 flatIndex += subSize;
140 template <
typename T, viskores::IdComponent N,
typename NestedVecType>
144 detail::CopyVecNestedToFlatImpl(nestedVec, flatVec, 0);
150 template <
typename T, viskores::IdComponent N>
155 nestedVec = flatVec[flatOffset];
158 template <
typename T, viskores::IdComponent NFlat, viskores::IdComponent NNest>
165 nestedVec[nestedIndex] = flatVec[nestedIndex + flatOffset];
169 template <
typename T,
171 typename ComponentType,
182 CopyVecFlatToNestedImpl(flatVec, flatIndex, nestedVec[nestIndex]);
183 flatIndex += subSize;
187 template <
typename T, viskores::IdComponent N,
typename NestedVecType>
190 NestedVecType& nestedVec)
193 using ComponentType =
typename Traits::ComponentType;
199 ComponentType component;
200 CopyVecFlatToNestedImpl(flatVec, flatIndex, component);
201 Traits::SetComponent(nestedVec, nestIndex, component);
202 flatIndex += subSize;
208 template <
typename T, viskores::IdComponent N,
typename NestedVecType>
210 NestedVecType& nestedVec)
212 detail::CopyVecFlatToNestedImpl(flatVec, 0, nestedVec);
239 template <typename T, bool = internal::IsFlatVec<T>::value>
243 template <
typename T>
249 using Superclass::Superclass;
256 internal::CopyVecNestedToFlat(src, *
this);
263 internal::CopyVecFlatToNested(*
this, nestedVec);
269 template <
typename T>
283 this->T::operator=(src);
289 this->T::operator=(std::move(src));
296 template <
typename T>
302 template <
typename T>
307 template <
typename T>
314 #endif //viskores_VecFlat_h