AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Impl::ChatCommands::ArgInfo< Acore::ChatCommands::Variant< Ts... > > Struct Template Reference

#include "ChatCommandArgs.h"

Public Types

using V = std::variant< Ts... >
 

Static Public Member Functions

template<std::size_t I>
static ChatCommandResult TryAtIndex (Acore::ChatCommands::Variant< Ts... > &val, ChatHandler const *handler, std::string_view args)
 
static ChatCommandResult TryConsume (Acore::ChatCommands::Variant< Ts... > &val, ChatHandler const *handler, std::string_view args)
 

Static Public Attributes

static constexpr std::size_t N = std::variant_size_v<V>
 

Detailed Description

template<typename... Ts>
struct Acore::Impl::ChatCommands::ArgInfo< Acore::ChatCommands::Variant< Ts... > >

Member Typedef Documentation

◆ V

template<typename... Ts>
using Acore::Impl::ChatCommands::ArgInfo< Acore::ChatCommands::Variant< Ts... > >::V = std::variant<Ts...>

Member Function Documentation

◆ TryAtIndex()

template<typename... Ts>
template<std::size_t I>
static ChatCommandResult Acore::Impl::ChatCommands::ArgInfo< Acore::ChatCommands::Variant< Ts... > >::TryAtIndex ( Acore::ChatCommands::Variant< Ts... > &  val,
ChatHandler const *  handler,
std::string_view  args 
)
inlinestatic
262 {
263 if constexpr (I < N)
264 {
265 ChatCommandResult thisResult = ArgInfo<std::variant_alternative_t<I, V>>::TryConsume(val.template emplace<I>(), handler, args);
266 if (thisResult)
267 return thisResult;
268 else
269 {
270 ChatCommandResult nestedResult = TryAtIndex<I + 1>(val, handler, args);
271 if (nestedResult || !thisResult.HasErrorMessage())
272 return nestedResult;
273 if (!nestedResult.HasErrorMessage())
274 return thisResult;
275 if (StringStartsWith(nestedResult.GetErrorMessage(), "\""))
276 return Acore::StringFormat("\"{}\"\n{} {}", thisResult.GetErrorMessage(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
277 else
278 return Acore::StringFormat("\"{}\"\n{} \"{}\"", thisResult.GetErrorMessage(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
279 }
280 }
281 else
282 return std::nullopt;
283 }
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition: Util.h:401
@ LANG_CMDPARSER_OR
Definition: Language.h:992
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
AC_GAME_API char const * GetAcoreString(ChatHandler const *handler, AcoreStrings which)
Definition: ChatCommandHelpers.cpp:28
static constexpr std::size_t N
Definition: ChatCommandArgs.h:258
static ChatCommandResult TryConsume(Acore::ChatCommands::Variant< Ts... > &val, ChatHandler const *handler, std::string_view args)
Definition: ChatCommandArgs.h:285
Definition: ChatCommandHelpers.h:101
bool HasErrorMessage() const
Definition: ChatCommandHelpers.h:116
std::string const & GetErrorMessage() const
Definition: ChatCommandHelpers.h:117

References Acore::Impl::ChatCommands::GetAcoreString(), Acore::Impl::ChatCommands::ChatCommandResult::GetErrorMessage(), Acore::Impl::ChatCommands::ChatCommandResult::HasErrorMessage(), LANG_CMDPARSER_OR, Acore::StringFormat(), and StringStartsWith().

◆ TryConsume()

template<typename... Ts>
static ChatCommandResult Acore::Impl::ChatCommands::ArgInfo< Acore::ChatCommands::Variant< Ts... > >::TryConsume ( Acore::ChatCommands::Variant< Ts... > &  val,
ChatHandler const *  handler,
std::string_view  args 
)
inlinestatic
286 {
287 ChatCommandResult result = TryAtIndex<0>(val, handler, args);
288 if (result.HasErrorMessage() && (result.GetErrorMessage().find('\n') != std::string::npos))
289 return Acore::StringFormat("{} {}", GetAcoreString(handler, LANG_CMDPARSER_EITHER), result.GetErrorMessage());
290 return result;
291 }
@ LANG_CMDPARSER_EITHER
Definition: Language.h:991

References Acore::Impl::ChatCommands::GetAcoreString(), Acore::Impl::ChatCommands::ChatCommandResult::GetErrorMessage(), Acore::Impl::ChatCommands::ChatCommandResult::HasErrorMessage(), LANG_CMDPARSER_EITHER, and Acore::StringFormat().

Member Data Documentation

◆ N

template<typename... Ts>
constexpr std::size_t Acore::Impl::ChatCommands::ArgInfo< Acore::ChatCommands::Variant< Ts... > >::N = std::variant_size_v<V>
staticconstexpr