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
261 {
262 if constexpr (I < N)
263 {
264 ChatCommandResult thisResult = ArgInfo<std::variant_alternative_t<I, V>>::TryConsume(val.template emplace<I>(), handler, args);
265 if (thisResult)
266 return thisResult;
267 else
268 {
269 ChatCommandResult nestedResult = TryAtIndex<I + 1>(val, handler, args);
270 if (nestedResult || !thisResult.HasErrorMessage())
271 return nestedResult;
272 if (!nestedResult.HasErrorMessage())
273 return thisResult;
274 if (StringStartsWith(nestedResult.GetErrorMessage(), "\""))
275 return Acore::StringFormat("\"{}\"\n{} {}", thisResult.GetErrorMessage(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
276 else
277 return Acore::StringFormat("\"{}\"\n{} \"{}\"", thisResult.GetErrorMessage(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
278 }
279 }
280 else
281 return std::nullopt;
282 }
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:27
static constexpr std::size_t N
Definition: ChatCommandArgs.h:257
static ChatCommandResult TryConsume(Acore::ChatCommands::Variant< Ts... > &val, ChatHandler const *handler, std::string_view args)
Definition: ChatCommandArgs.h:284
Definition: ChatCommandHelpers.h:100
bool HasErrorMessage() const
Definition: ChatCommandHelpers.h:115
std::string const & GetErrorMessage() const
Definition: ChatCommandHelpers.h:116

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
285 {
286 ChatCommandResult result = TryAtIndex<0>(val, handler, args);
287 if (result.HasErrorMessage() && (result.GetErrorMessage().find('\n') != std::string::npos))
288 return Acore::StringFormat("{} {}", GetAcoreString(handler, LANG_CMDPARSER_EITHER), result.GetErrorMessage());
289 return result;
290 }
@ 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