MayaFlux 0.1.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 410 of file SortingHelper.hpp.

412{
413 SortKey key(name, [](const std::any& data) -> double {
414 auto cast_result = safe_any_cast<T>(data);
415 if (!cast_result) {
416 return 0.0;
417 }
418
419 const T& value = *cast_result.value;
420
421 if constexpr (ArithmeticData<T>) {
422 return static_cast<double>(value);
423 } else if constexpr (ComplexData<T>) {
424 return std::abs(value);
425 } else if constexpr (requires { get_temporal_position(value); }) {
426 return get_temporal_position(value);
427 } else {
428 return 0.0;
429 }
430 });
431
432 key.direction = direction;
433 return key;
434}
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: