MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ create_universal_sort_key()

template<typename T >
SortKey MayaFlux::Yantra::create_universal_sort_key ( const std::string &  name,
SortingDirection  direction = SortingDirection::ASCENDING 
)

Create universal sort key extractor for common data types.

Template Parameters
TData type to extract sort key from
Parameters
nameSort key name
directionSort direction (for the key metadata)
Returns
SortKey with appropriate extractor

Definition at line 204 of file SortingHelper.hpp.

206{
207 SortKey key(name, [](const std::any& data) -> double {
208 auto cast_result = safe_any_cast<T>(data);
209 if (!cast_result) {
210 return 0.0;
211 }
212
213 const T& value = *cast_result.value;
214
215 if constexpr (ArithmeticData<T>) {
216 return static_cast<double>(value);
217 } else if constexpr (ComplexData<T>) {
218 return std::abs(value);
219 } else if constexpr (requires { get_temporal_position(value); }) {
220 return get_temporal_position(value);
221 } else {
222 return 0.0;
223 }
224 });
225
226 key.direction = direction;
227 return key;
228}
double get_temporal_position(const T &item)
Helper function to get temporal position from various types Used by TemporalSortable concept.
Multi-dimensional sort key specification for complex sorting.

References MayaFlux::Yantra::SortKey::direction, and get_temporal_position().

+ Here is the call graph for this function: