Skip to content

Commit

Permalink
concepts: play with a visual range concept separate from the mapping …
Browse files Browse the repository at this point in the history
…range
  • Loading branch information
jcelerier committed Dec 9, 2024
1 parent a28f61b commit 3f3e6ff
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/Advanced/Utilities/Gain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ class Gain

struct inputs
{
halp::smooth_knob<"Gain", halp::range{0., 5., 0.}> gain;
struct : halp::smooth_knob<"Gain", halp::range{0., 1., 0.}>
{
struct visual_range
{
double min = 0.;
double max = 5.;
};
} gain;
};
double operator()(double input, const inputs& in) { return input * in.gain; }
};
Expand Down
4 changes: 4 additions & 0 deletions include/avnd/concepts/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ namespace avnd
template <typename C>
concept has_range = requires { C::range(); } || requires { sizeof(C::range); }
|| requires { sizeof(typename C::range); };
template <typename C>
concept has_visual_range = requires { C::visual_range(); } || requires {
sizeof(C::visual_range);
} || requires { sizeof(typename C::visual_range); };
}
26 changes: 26 additions & 0 deletions include/avnd/introspection/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,30 @@ consteval auto get_range(const T&)
{
return get_range<T>();
}

template <avnd::has_visual_range T>
consteval auto get_visual_range()
{
if constexpr(requires { sizeof(typename T::visual_range); })
return typename T::visual_range{};
else if constexpr(requires { T::visual_range(); })
return T::visual_range();
else if constexpr(requires { sizeof(decltype(T::visual_range)); })
return T::visual_range;
else
return get_range<T>();
}

template <avnd::has_range T>
requires(!avnd::has_visual_range<T>)
consteval auto get_visual_range()
{
return get_range<T>();
}

template <typename T>
consteval auto get_visual_range(const T&)
{
return get_visual_range<T>();
}
}

0 comments on commit 3f3e6ff

Please sign in to comment.