9#pragma pointers_to_members(full_generality, single_inheritance)
18 struct ReflectedTarget
76 typedef void (ReflectedTarget::*MemberFunction)();
82 template<
typename Class,
typename Ret,
typename... Args>
83 Method(
const Name& name, Ret (Class::*method)(Args...)) :
85 function(reinterpret_cast<MemberFunction>(method)),
86 numArguments(sizeof...(Args)),
87 returnTypeSize(getReturnSize<Ret>())
107 template<
typename Ret>
114 template<
typename... Args>
117 size_t sizes[] = { (
sizeof(Args))... };
120 for (
size_t i = 0; i < numArguments; ++i) {
121 argumentSizes[i] = sizes[i];
126 template<
typename... Args>
129 size_t sizes [] = { (
sizeof(Args))... };
132 for (
size_t i = 0; i < numArguments; ++i) {
133 assert(argumentSizes[i] == sizes[i] &&
"Argument passed to method not of correct type or size");
143 template<
typename Class,
typename... Arg>
144 void call(Class *
object, Arg... arg)
const
146 assert(numArguments ==
sizeof...(Arg) &&
"Method does not support being called with the given number of arguments.");
149 compareSizes<Arg...>();
152 typedef void (Class::*TypedMessage)(Arg...);
154 auto method =
reinterpret_cast<TypedMessage
>(function);
156 (
object->*method)(arg...);
167 template<
typename Class,
typename Ret,
typename... Arg>
170 assert(returnTypeSize == getReturnSize<Ret>() &&
"Method does not have correct return type or size.");
171 assert(numArguments ==
sizeof...(Arg) &&
"Method does not support being called with the given number of arguments.");
174 compareSizes<Arg...>();
177 typedef Ret (Class::*TypedMessage)(Arg...);
179 auto method =
reinterpret_cast<TypedMessage
>(function);
181 return (object->*method)(arg...);
206 inline size_t Method::getReturnSize<void>()
const
213 inline void Method::setSizes<>()
220 inline void Method::compareSizes<>()
const
#define COGSFOUNDATION_API
Definition: FoundationBase.h:31
Simple method definition.
Definition: Method.h:72
Method(Method &&other) noexcept=default
Default move constructor.
size_t returnTypeSize
Return type size.
Definition: Method.h:198
Ret callWithReturn(Class *object, Ret, Arg... arg) const
Call the method named name on the given object, with the given arguments, returning a value of type R...
Definition: Method.h:168
void compareSizes() const
Compare the sizes of a set of given arguments to the stored argument sizes.
Definition: Method.h:127
const Name & getName() const
Get the name of this method.
Definition: Method.h:185
Method & operator=(const Method &other)=default
Default copy assignment operator.
MemberFunction function
Pointer to member function for our method.
Definition: Method.h:192
Method(const Name &name, Ret(Class::*method)(Args...))
Creates a new method definition using the given name and the given pointer to member function.
Definition: Method.h:83
Name name
Name to use when looking up this method.
Definition: Method.h:189
size_t numArguments
Number of arguments given.
Definition: Method.h:195
Method & operator=(Method &&other) noexcept=default
Default move assignment operator.
Method(const Method &other)=default
Default copy constructor.
void call(Class *object, Arg... arg) const
Call the method named name on the given object, with the given arguments.
Definition: Method.h:144
void setSizes()
Register argument sizes.
Definition: Method.h:115
size_t getReturnSize() const
Register the size of the return type.
Definition: Method.h:108
constexpr size_t kMaxMethodArguments
Max number of method arguments supported.
Definition: Method.h:25
Main Cogs namespace.
Definition: MortonCode.h:5
Represents an unique name.
Definition: Name.h:70