41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
#pragma once
|
|
#include <type_traits>
|
|
#include <utility>
|
|
#include <string_view>
|
|
#include <vector>
|
|
#include <Mixin/Types.hpp>
|
|
#include <Mixin/Registrer.hpp>
|
|
#include <Reflect/Method.hpp>
|
|
|
|
namespace vl::mixin {
|
|
|
|
template<class Target>
|
|
class Mixin {
|
|
public:
|
|
using TargetClass = Target;
|
|
static constexpr std::string_view Owner = Target::Meta.internalName;
|
|
|
|
protected:
|
|
// internal accumulation (per mixin type)
|
|
static Mixin& instance() { static Mixin inst; return inst; }
|
|
|
|
static void add(const InjectionSpec& s) { instance().spec_.injections.push_back(s); }
|
|
static void add(const RedirectSpec& s) { instance().spec_.redirects.push_back(s); }
|
|
static void add(const ModifyConstSpec&s){ instance().spec_.constants.push_back(s); }
|
|
static void add(const ModifyVarSpec& s) { instance().spec_.vars.push_back(s); }
|
|
static void set_replace(CallbackId provider) { instance().spec_.replaceWholeClass = true; instance().spec_.classBodyProvider = provider; }
|
|
|
|
private:
|
|
// Auto-register once per T
|
|
static inline bool _autoReg = []{
|
|
auto &inst = instance();
|
|
inst.spec_.owner = Owner;
|
|
Registrar::submit(inst.spec_);
|
|
return true;
|
|
}();
|
|
|
|
MixinSpec spec_{};
|
|
};
|
|
|
|
} // namespace vl::mixin
|