our_dick/include/audio/detail.hpp

64 lines
2.0 KiB
C++

/**
This file is a part of our_dick
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_AUDIO_DETAIL_HPP
#define OUR_DICK_AUDIO_DETAIL_HPP
#include <tuple> //tuple, get
#include <utility> //forward, integer_sequence
namespace audio::detail{
template<typename Func, typename... Args>
struct callback_helper{
Func&& m_f;
std::tuple<Args...> m_args;
template<int... Indices>
int operator()(const void* input, void* output, unsigned long frame_count,
unsigned long flags, std::integer_sequence<int,Indices...>)
{
return std::forward<Func>(m_f)(input, output, frame_count, flags, std::get<Indices>(m_args)...);
}
};
class callback_iface
{
public:
callback_iface() = default;
virtual ~callback_iface() = default;
virtual int operator()(const void* input, void* output, unsigned long frame_count, unsigned long flags) = 0;
};
template<typename Func, typename... Args>
class callback_impl : public callback_iface
{
private:
callback_helper<Func,Args...> m_ch;
public:
template<class Fn, class... Ts>
callback_impl(Fn&& f, Ts&&... ts):
m_ch{std::forward<Fn>(f), {std::forward<Ts>(ts)...}}{}
int operator()(const void* input, void* output, unsigned long frame_count, unsigned long flags)override{
return m_ch(input, output, frame_count, flags, typename ::util::sequence_gen<sizeof...(Args)>::type{});
}
};
}
#endif