Skip to content

Commit 60691f8

Browse files
committed
Make VariantOfVectors a public type of PointData, add setData overload
Moved the definition of the type `VariantOfVectors` from the private to the (first) public section of PointData. Added an extra `PointData::setData` overload that allows specifying such a variant as `data` parameter. Suggested by Jeroen Eggermont.
1 parent 1a96b1c commit 60691f8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

HDPS/src/plugins/PointData/src/PointData.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class POINTDATA_EXPORT PointData : public mv::plugin::RawData
6565
uint8
6666
};
6767

68-
private:
6968
using VariantOfVectors = std::variant <
7069
std::vector<float>,
7170
std::vector<biovault::bfloat16_t>,
@@ -74,6 +73,7 @@ class POINTDATA_EXPORT PointData : public mv::plugin::RawData
7473
std::vector<std::int8_t>,
7574
std::vector<std::uint8_t> >;
7675

76+
private:
7777
// Sets the index of the specified variant. If the new index is different from the previous one, the value will be reset.
7878
// Inspired by `expand_type` from kmbeutel at
7979
// https://www.reddit.com/r/cpp/comments/f8cbzs/creating_stdvariant_based_on_index_at_runtime/?rdt=52905
@@ -398,6 +398,15 @@ class POINTDATA_EXPORT PointData : public mv::plugin::RawData
398398
_numDimensions = static_cast<unsigned int>(numDimensions);
399399
}
400400

401+
/// Copies (or "moves") the data from the specified variant into the internal data and sets the number of dimensions as specified.
402+
/// Note that the `data` parameter is passed by-value (non-const), in order to avoid expensive copying (using C++ move semantics).
403+
template <typename T>
404+
void setData(VariantOfVectors data, const std::size_t numDimensions)
405+
{
406+
_variantOfVectors = std::move(data);
407+
_numDimensions = static_cast<unsigned int>(numDimensions);
408+
}
409+
401410
/// Efficiently "moves" the data from the specified vector into the internal
402411
/// data, sets the number of dimensions as specified, and sets the selected
403412
/// internal data type according to the specified data type T.

0 commit comments

Comments
 (0)