|
@ -6,52 +6,34 @@ |
|
|
|
|
|
|
|
|
namespace exposer { |
|
|
namespace exposer { |
|
|
|
|
|
|
|
|
// REF: http://bloglitb.blogspot.com/2010/07/access-to-private-members-thats-easy.html
|
|
|
template <typename T, T Val, typename Tag> |
|
|
|
|
|
|
|
|
//template <typename T>
|
|
|
|
|
|
//struct Exposer {
|
|
|
|
|
|
// static T ptr;
|
|
|
|
|
|
//};
|
|
|
|
|
|
//
|
|
|
|
|
|
//template <typename T>
|
|
|
|
|
|
//T Exposer<T>::ptr;
|
|
|
|
|
|
//
|
|
|
|
|
|
//template <typename T, T Ptr>
|
|
|
|
|
|
//struct ExposerImpl {
|
|
|
|
|
|
// static struct Factory {
|
|
|
|
|
|
// Factory() { Exposer<T>::ptr = Ptr; }
|
|
|
|
|
|
// } factory;
|
|
|
|
|
|
//};
|
|
|
|
|
|
//
|
|
|
|
|
|
//template <typename T, T Ptr>
|
|
|
|
|
|
//typename ExposerImpl<T, Ptr>::Factory ExposerImpl<T, Ptr>::factory;
|
|
|
|
|
|
|
|
|
|
|
|
//template <typename T>
|
|
|
|
|
|
//constexpr T fetch();
|
|
|
|
|
|
|
|
|
|
|
|
//template <typename T, T Val, int Flag>
|
|
|
|
|
|
template <typename T, T Val, typename Unique> |
|
|
|
|
|
struct Exposer { |
|
|
struct Exposer { |
|
|
// constexpr friend T fetch<>() { return Val; }
|
|
|
constexpr friend T fetch(Tag) { return Val; } |
|
|
constexpr friend T fetch(Unique) { return Val; } |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
} // namespace exposer
|
|
|
} // namespace exposer
|
|
|
|
|
|
|
|
|
#define FORCIBLY_ACCESS(Class, Member, Type) \ |
|
|
#define COMBINE_IMPL(x, y) x##y |
|
|
namespace exposer { \ |
|
|
|
|
|
template struct ExposerImpl<decltype(&Class::Member), &Class::Member>; \ |
|
|
#define COMBINE(x, y) COMBINE_IMPL(x, y) |
|
|
inline auto& Class##_##Member(Class &T) { \ |
|
|
|
|
|
return T.*exposer::Exposer<Type Class::*>::ptr; \ |
|
|
#define UNIQUE_TAG COMBINE(Tag, __COUNTER__) |
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define FORCE_ACCESS_VAR(Class, Member, Type, Unique) \ |
|
|
#define FORCE_ACCESS_VAR_IMPL(Class, Type, Member, Tag) \ |
|
|
namespace exposer { \ |
|
|
namespace exposer { \ |
|
|
struct Unique {}; \ |
|
|
struct Tag {}; \ |
|
|
template struct Exposer<Type (Class::*), &Class::Member, Unique>; \ |
|
|
template struct Exposer<Type(Class::*), &Class::Member, Tag>; \ |
|
|
constexpr Type Class::* fetch(Unique); \ |
|
|
constexpr Type Class::* fetch(Tag); \ |
|
|
Type& Class##_##Member(Class &T) { \ |
|
|
constexpr Type& Class##_##Member(Class &c) { \ |
|
|
return T.*fetch(Unique{}); \ |
|
|
return c.*fetch(Tag{}); \ |
|
|
|
|
|
} \ |
|
|
|
|
|
constexpr const Type& Class##_##Member(const Class &c) { \ |
|
|
|
|
|
return c.*fetch(Tag{}); \ |
|
|
|
|
|
} \ |
|
|
|
|
|
constexpr Type Class##_##Member(Class &&c) { \ |
|
|
|
|
|
return c.*fetch(Tag{}); \ |
|
|
} \ |
|
|
} \ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define FORCE_ACCESS_VAR(Class, Type, Member) \ |
|
|
|
|
|
FORCE_ACCESS_VAR_IMPL(Class, Type, Member, UNIQUE_TAG) |
|
|