Skip to content

Commit

Permalink
Make VariantOfVectors a public type of PointData, add setData overload
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
N-Dekker committed Feb 8, 2024
1 parent b83c803 commit 364329b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion HDPS/src/plugins/PointData/src/PointData.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class POINTDATA_EXPORT PointData : public mv::plugin::RawData
uint8
};

private:
using VariantOfVectors = std::variant <
std::vector<float>,
std::vector<biovault::bfloat16_t>,
Expand All @@ -74,6 +73,7 @@ class POINTDATA_EXPORT PointData : public mv::plugin::RawData
std::vector<std::int8_t>,
std::vector<std::uint8_t> >;

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

/// Copies (or "moves") the data from the specified variant into the internal data and sets the number of dimensions as specified.
/// Note that the `data` parameter is passed by-value (non-const), in order to avoid expensive copying (using C++ move semantics).
template <typename T>
void setData(VariantOfVectors data, const std::size_t numDimensions)
{
_variantOfVectors = std::move(data);
_numDimensions = static_cast<unsigned int>(numDimensions);
}

/// Efficiently "moves" the data from the specified vector into the internal
/// data, sets the number of dimensions as specified, and sets the selected
/// internal data type according to the specified data type T.
Expand Down

0 comments on commit 364329b

Please sign in to comment.