wavelength 1.0.0
Loading...
Searching...
No Matches
memfuncommand.h
Go to the documentation of this file.
1#pragma once
2
3#include "os/command.h"
4
15template <typename Function, typename Object>
16class MemFunCommand : public Command {
17public:
24 MemFunCommand(Object *pObject, Function pfnMember) : mObject(pObject), mMember(pfnMember) {
25 }
26
104 ~MemFunCommand() override = default;
105
182 void Execute() override {
183 (mObject->*mMember)();
184 }
185
186private:
187 Object *mObject;
188 Function mMember;
189};
190
201template <typename Result, typename Owner, typename Object>
202class MemFunCommand<Result (Owner::*)(float), Object> : public Command {
203public:
205 using Function = Result (Owner::*)(float);
206
208 static constexpr float kDefaultArgument = -1.0f;
209
216 MemFunCommand(Object *pObject, Function pfnMember) : mObject(pObject), mMember(pfnMember) {
217 }
218
225 ~MemFunCommand() override = default;
226
233 void Execute() override {
234 (mObject->*mMember)(kDefaultArgument);
235 }
236
237private:
238 Object *mObject;
239 Function mMember;
240};
241
325template <typename Function, typename Object>
326Command *NewMemFunCommand(Object *pObject, Function pfnMember) {
327 return new MemFunCommand<Function, Object>(pObject, pfnMember);
328}
Unit of work a Scheduler runs at a set time.
Definition command.h:13
MemFunCommand(Object *pObject, Function pfnMember)
Construct a command that calls a member function.
Definition memfuncommand.h:216
~MemFunCommand() override=default
Release the command.
static constexpr float kDefaultArgument
The argument the member function receives.
Definition memfuncommand.h:208
void Execute() override
Call the member function with the default argument.
Definition memfuncommand.h:233
Result(Owner::*)(float) Function
The member function type.
Definition memfuncommand.h:205
Command that calls a member function of an object.
Definition memfuncommand.h:16
~MemFunCommand() override=default
Release the command.
MemFunCommand(Object *pObject, Function pfnMember)
Construct a command that calls a member function.
Definition memfuncommand.h:24
void Execute() override
Call the member function.
Definition memfuncommand.h:182
Command * NewMemFunCommand(Object *pObject, Function pfnMember)
Allocate a command that calls a member function of an object.
Definition memfuncommand.h:326