10 #ifndef vtk_m_cont_ArrayHandleConcatenate_h
11 #define vtk_m_cont_ArrayHandleConcatenate_h
22 template <
typename PortalType1,
typename PortalType2>
25 using WritableP1 = vtkm::internal::PortalSupportsSets<PortalType1>;
26 using WritableP2 = vtkm::internal::PortalSupportsSets<PortalType2>;
27 using Writable = std::integral_constant<bool, WritableP1::value && WritableP2::value>;
30 using ValueType =
typename PortalType1::ValueType;
34 ArrayPortalConcatenate()
42 ArrayPortalConcatenate(
const PortalType1& p1,
const PortalType2& p2)
50 template <
typename OtherP1,
typename OtherP2>
51 VTKM_EXEC_CONT ArrayPortalConcatenate(
const ArrayPortalConcatenate<OtherP1, OtherP2>& src)
52 : portal1(src.GetPortal1())
53 , portal2(src.GetPortal2())
60 return this->portal1.GetNumberOfValues() + this->portal2.GetNumberOfValues();
67 if (index < this->portal1.GetNumberOfValues())
69 return this->portal1.Get(index);
73 return this->portal2.Get(index - this->portal1.GetNumberOfValues());
78 template <
typename Writable_ = Writable,
79 typename =
typename std::enable_if<Writable_::value>::type>
82 if (index < this->portal1.GetNumberOfValues())
84 this->portal1.Set(index, value);
88 this->portal2.Set(index - this->portal1.GetNumberOfValues(), value);
93 const PortalType1& GetPortal1()
const {
return this->portal1; }
96 const PortalType2& GetPortal2()
const {
return this->portal2; }
111 template <
typename StorageTag1,
typename StorageTag2>
119 template <
typename T,
typename ST1,
typename ST2>
122 using SourceStorage1 = vtkm::cont::internal::Storage<T, ST1>;
123 using SourceStorage2 = vtkm::cont::internal::Storage<T, ST2>;
130 std::size_t NumBuffers1;
131 std::size_t NumBuffers2;
134 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> Buffers1(
135 const std::vector<vtkm::cont::internal::Buffer>& buffers)
137 Info info = buffers[0].GetMetaData<Info>();
138 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1,
139 buffers.begin() + 1 + info.NumBuffers1);
142 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> Buffers2(
143 const std::vector<vtkm::cont::internal::Buffer>& buffers)
145 Info info = buffers[0].GetMetaData<Info>();
146 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1 + info.NumBuffers1,
153 using ReadPortalType =
154 vtkm::internal::ArrayPortalConcatenate<
typename SourceStorage1::ReadPortalType,
155 typename SourceStorage2::ReadPortalType>;
156 using WritePortalType =
157 vtkm::internal::ArrayPortalConcatenate<
typename SourceStorage1::WritePortalType,
158 typename SourceStorage2::WritePortalType>;
161 const std::vector<vtkm::cont::internal::Buffer>& buffers)
163 return (SourceStorage1::GetNumberOfValues(Buffers1(buffers)) +
164 SourceStorage2::GetNumberOfValues(Buffers2(buffers)));
167 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
173 vtkm::Id size1 = SourceStorage1::GetNumberOfValues(Buffers1(buffers));
174 if ((startIndex < size1) && (endIndex <= size1))
176 SourceStorage1::Fill(Buffers1(buffers), fillValue, startIndex, endIndex, token);
178 else if (startIndex < size1)
180 SourceStorage1::Fill(Buffers1(buffers), fillValue, startIndex, size1, token);
181 SourceStorage2::Fill(Buffers2(buffers), fillValue, 0, endIndex - size1, token);
185 SourceStorage2::Fill(
186 Buffers2(buffers), fillValue, startIndex - size1, endIndex - size1, token);
190 VTKM_CONT static ReadPortalType CreateReadPortal(
191 const std::vector<vtkm::cont::internal::Buffer>& buffers,
195 return ReadPortalType(SourceStorage1::CreateReadPortal(Buffers1(buffers), device, token),
196 SourceStorage2::CreateReadPortal(Buffers2(buffers), device, token));
199 VTKM_CONT static WritePortalType CreateWritePortal(
200 const std::vector<vtkm::cont::internal::Buffer>& buffers,
204 return WritePortalType(SourceStorage1::CreateWritePortal(Buffers1(buffers), device, token),
205 SourceStorage2::CreateWritePortal(Buffers2(buffers), device, token));
208 VTKM_CONT static auto CreateBuffers(
const ArrayHandleType1& array1 = ArrayHandleType1{},
209 const ArrayHandleType2& array2 = ArrayHandleType2{})
210 -> decltype(vtkm::cont::internal::CreateBuffers())
213 info.NumBuffers1 = array1.GetBuffers().size();
214 info.NumBuffers2 = array2.GetBuffers().size();
215 return vtkm::cont::internal::CreateBuffers(info, array1, array2);
218 VTKM_CONT static const ArrayHandleType1 GetArray1(
219 const std::vector<vtkm::cont::internal::Buffer>& buffers)
221 return ArrayHandleType1(Buffers1(buffers));
224 VTKM_CONT static const ArrayHandleType2 GetArray2(
225 const std::vector<vtkm::cont::internal::Buffer>& buffers)
227 return ArrayHandleType2(Buffers2(buffers));
240 template <
typename ArrayHandleType1,
typename ArrayHandleType2>
243 StorageTagConcatenate<typename ArrayHandleType1::StorageTag,
244 typename ArrayHandleType2::StorageTag>>
252 typename ArrayHandleType2::StorageTag>>));
255 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
260 : Superclass(
StorageType::CreateBuffers(array1, array2))
265 template <
typename ArrayHandleType1,
typename ArrayHandleType2>
267 const ArrayHandleType1& array1,
268 const ArrayHandleType2& array2)
283 template <
typename AH1,
typename AH2>
284 struct SerializableTypeString<
vtkm::cont::ArrayHandleConcatenate<AH1, AH2>>
294 template <
typename T,
typename ST1,
typename ST2>
295 struct SerializableTypeString<
296 vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConcatenate<ST1, ST2>>>
297 : SerializableTypeString<vtkm::cont::ArrayHandleConcatenate<vtkm::cont::ArrayHandle<T, ST1>,
298 vtkm::cont::ArrayHandle<T, ST2>>>
307 template <
typename AH1,
typename AH2>
308 struct Serialization<
vtkm::cont::ArrayHandleConcatenate<AH1, AH2>>
315 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
317 auto storage = obj.GetStorage();
318 vtkmdiy::save(bb, storage.GetArray1());
319 vtkmdiy::save(bb, storage.GetArray2());
334 template <
typename T,
typename ST1,
typename ST2>
335 struct Serialization<
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConcatenate<ST1, ST2>>>
336 : Serialization<vtkm::cont::ArrayHandleConcatenate<vtkm::cont::ArrayHandle<T, ST1>,
337 vtkm::cont::ArrayHandle<T, ST2>>>
344 #endif //vtk_m_cont_ArrayHandleConcatenate_h