AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Impl::ChatCommands::ArgInfo< T, std::enable_if_t< std::is_integral_v< T >||std::is_floating_point_v< T > > > Struct Template Reference

#include "ChatCommandArgs.h"

Static Public Member Functions

static ChatCommandResult TryConsume (T &val, ChatHandler const *handler, std::string_view args)
 

Detailed Description

template<typename T>
struct Acore::Impl::ChatCommands::ArgInfo< T, std::enable_if_t< std::is_integral_v< T >||std::is_floating_point_v< T > > >

Member Function Documentation

◆ TryConsume()

template<typename T >
static ChatCommandResult Acore::Impl::ChatCommands::ArgInfo< T, std::enable_if_t< std::is_integral_v< T >||std::is_floating_point_v< T > > >::TryConsume ( T &  val,
ChatHandler const *  handler,
std::string_view  args 
)
inlinestatic
57 {
58 auto [token, tail] = tokenize(args);
59 if (token.empty())
60 return std::nullopt;
61
62 if (Optional<T> v = StringTo<T>(token, 0))
63 val = *v;
64 else
65 return FormatAcoreString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(token), GetTypeName<T>().c_str());
66
67 if constexpr (std::is_floating_point_v<T>)
68 {
69 if (!std::isfinite(val))
70 return FormatAcoreString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(token), GetTypeName<T>().c_str());
71 }
72
73 return tail;
74 }
#define STRING_VIEW_FMT_ARG(str)
Definition: Define.h:101
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
@ LANG_CMDPARSER_STRING_VALUE_INVALID
Definition: Language.h:1002
std::string FormatAcoreString(ChatHandler const *handler, AcoreStrings which, Ts &&... args)
Definition: ChatCommandHelpers.h:126
TokenizeResult tokenize(std::string_view args)
Definition: ChatCommandHelpers.h:55

References Acore::Impl::ChatCommands::FormatAcoreString(), LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG, and Acore::Impl::ChatCommands::tokenize().