AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Impl::ChatCommands::CommandInvoker Struct Reference

#include "ChatCommand.h"

Public Member Functions

 CommandInvoker ()
 
template<typename TypedHandler >
 CommandInvoker (TypedHandler &handler)
 
 CommandInvoker (bool(&handler)(ChatHandler *, char const *))
 
 operator bool () const
 
bool operator() (ChatHandler *chatHandler, std::string_view args) const
 

Private Types

using wrapper_func = bool(void *, ChatHandler *, std::string_view)
 

Private Attributes

wrapper_func_wrapper
 
void * _handler
 

Detailed Description

Member Typedef Documentation

◆ wrapper_func

using Acore::Impl::ChatCommands::CommandInvoker::wrapper_func = bool(void*, ChatHandler*, std::string_view)
private

Constructor & Destructor Documentation

◆ CommandInvoker() [1/3]

Acore::Impl::ChatCommands::CommandInvoker::CommandInvoker ( )
inline
119: _wrapper(nullptr), _handler(nullptr) {}
wrapper_func * _wrapper
Definition: ChatCommand.h:162
void * _handler
Definition: ChatCommand.h:163

◆ CommandInvoker() [2/3]

template<typename TypedHandler >
Acore::Impl::ChatCommands::CommandInvoker::CommandInvoker ( TypedHandler &  handler)
inline
122 {
123 _wrapper = [](void* handler, ChatHandler* chatHandler, std::string_view argsStr)
124 {
125 using Tuple = TupleType<TypedHandler>;
126
127 Tuple arguments;
128 std::get<0>(arguments) = chatHandler;
129 ChatCommandResult result = ConsumeFromOffset<Tuple, 1>(arguments, chatHandler, argsStr);
130 if (result)
131 return std::apply(reinterpret_cast<TypedHandler*>(handler), std::move(arguments));
132 else
133 {
134 if (result.HasErrorMessage())
135 SendErrorMessageToHandler(chatHandler, result.GetErrorMessage());
136 return false;
137 }
138 };
139 _handler = reinterpret_cast<void*>(handler);
140 }
AC_GAME_API void SendErrorMessageToHandler(ChatHandler *handler, std::string_view str)
Definition: ChatCommandHelpers.cpp:21
Definition: Chat.h:37
Definition: ChatCommandHelpers.h:100
bool HasErrorMessage() const
Definition: ChatCommandHelpers.h:115
std::string const & GetErrorMessage() const
Definition: ChatCommandHelpers.h:116

References _handler, _wrapper, Acore::Impl::ChatCommands::ChatCommandResult::GetErrorMessage(), Acore::Impl::ChatCommands::ChatCommandResult::HasErrorMessage(), and Acore::Impl::ChatCommands::SendErrorMessageToHandler().

◆ CommandInvoker() [3/3]

Acore::Impl::ChatCommands::CommandInvoker::CommandInvoker ( bool(&)(ChatHandler *, char const *)  handler)
inline
142 {
143 _wrapper = [](void* handler, ChatHandler* chatHandler, std::string_view argsStr)
144 {
145 // make a copy of the argument string
146 // legacy handlers can destroy input strings with strtok
147 std::string argsStrCopy(argsStr);
148 return reinterpret_cast<bool(*)(ChatHandler*, char const*)>(handler)(chatHandler, argsStrCopy.c_str());
149 };
150 _handler = reinterpret_cast<void*>(handler);
151 }

References _handler, and _wrapper.

Member Function Documentation

◆ operator bool()

Acore::Impl::ChatCommands::CommandInvoker::operator bool ( ) const
inlineexplicit
153{ return (_wrapper != nullptr); }

References _wrapper.

◆ operator()()

bool Acore::Impl::ChatCommands::CommandInvoker::operator() ( ChatHandler chatHandler,
std::string_view  args 
) const
inline
155 {
157 return _wrapper(_handler, chatHandler, args);
158 }
#define ASSERT
Definition: Errors.h:68

References _handler, _wrapper, and ASSERT.

Member Data Documentation

◆ _handler

void* Acore::Impl::ChatCommands::CommandInvoker::_handler
private

Referenced by CommandInvoker(), and operator()().

◆ _wrapper

wrapper_func* Acore::Impl::ChatCommands::CommandInvoker::_wrapper
private