18#ifndef TRINITY_CHATCOMMANDTAGS_H
19#define TRINITY_CHATCOMMANDTAGS_H
26#include <boost/preprocessor/repetition/repeat.hpp>
27#include <boost/preprocessor/punctuation/comma_if.hpp>
28#include <fmt/ostream.h>
48 struct tag_base<T,
std::enable_if_t<std::is_base_of_v<ContainerTag, T>>>
50 using type =
typename T::value_type;
54 inline constexpr char GetChar(
char const (&s)[N],
size_t i)
56 static_assert(N <= 25,
"The EXACT_SEQUENCE macro can only be used with up to 25 character long literals. Specify them char-by-char (null terminated) as parameters to ExactSequence<> instead.");
57 return i >= N ?
'\0' : s[i];
60#define CHATCOMMANDS_IMPL_SPLIT_LITERAL_EXTRACT_CHAR(z, i, strliteral) \
61 BOOST_PP_COMMA_IF(i) Trinity::Impl::ChatCommands::GetChar(strliteral, i)
63#define CHATCOMMANDS_IMPL_SPLIT_LITERAL_CONSTRAINED(maxlen, strliteral) \
64 BOOST_PP_REPEAT(maxlen, CHATCOMMANDS_IMPL_SPLIT_LITERAL_EXTRACT_CHAR, strliteral)
67#define CHATCOMMANDS_IMPL_SPLIT_LITERAL(strliteral) CHATCOMMANDS_IMPL_SPLIT_LITERAL_CONSTRAINED(25, strliteral)
86 template <
char... chars>
95 std::string_view start = args.substr(0,
_string.length());
99 if (remainingToken.empty())
101 start = args.substr(0,
_string.length() + remainingToken.length());
107 static constexpr std::array<char,
sizeof...(chars)>
_storage = { chars... };
108 static_assert(!
_storage.empty() && (
_storage.back() ==
'\0'),
"ExactSequence parameters must be null terminated! Use the EXACT_SEQUENCE macro to make this easier!");
112#define EXACT_SEQUENCE(str) Trinity::ChatCommands::ExactSequence<CHATCOMMANDS_IMPL_SPLIT_LITERAL(str)>
118 using std::string_view::operator=;
122 std::string_view::operator=(args);
123 return std::string_view();
131 using std::wstring::operator=;
136 return std::string_view();
157 operator std::string
const& ()
const {
return _name; }
158 operator std::string_view()
const {
return _name; }
161 std::string
const&
GetName()
const {
return _name; }
183 operator std::string
const&()
const {
return _name; }
184 operator std::string_view()
const {
return _name; }
186 std::string
const&
GetName()
const {
return _name; }
200 return FromSelf(handler);
209 template <
typename linktag>
227 if (info.
tag != linktag::tag())
231 if (!linktag::StoreTo(
val, info.
data))
252 template <
typename T>
255 template <
typename U>
262 template <
typename T1,
typename... Ts>
263 struct Variant :
public std::variant<T1, Ts...>
265 using base = std::variant<T1, Ts...>;
270 template <
bool C = have_operators>
276 template <
bool C = have_operators>
277 operator std::enable_if_t<C, first_type>()
const
282 template <
bool C = have_operators>
283 std::enable_if_t<C, bool>
operator!()
const {
return !**
this; }
285 template <
typename T>
288 template <
size_t index>
289 constexpr decltype(
auto)
get() {
return std::get<index>(
static_cast<base&
>(*
this)); }
290 template <
size_t index>
291 constexpr decltype(
auto)
get()
const {
return std::get<index>(
static_cast<base const&
>(*
this)); }
292 template <
typename type>
293 constexpr decltype(
auto)
get() {
return std::get<type>(
static_cast<base&
>(*
this)); }
294 template <
typename type>
295 constexpr decltype(
auto)
get()
const {
return std::get<type>(
static_cast<base const&
>(*
this)); }
297 template <
typename T>
298 constexpr decltype(
auto)
visit(T&& arg) {
return std::visit(std::forward<T>(arg),
static_cast<base&
>(*
this)); }
299 template <
typename T>
300 constexpr decltype(
auto)
visit(T&& arg)
const {
return std::visit(std::forward<T>(arg),
static_cast<base const&
>(*
this)); }
302 template <
typename T>
305 template <
bool C = have_operators>
313template <
typename T1,
typename... Ts>
316template <
typename T1,
typename... Ts>
319 template <
typename T,
typename OutputIt>
320 auto format(T
const& value, basic_format_context<OutputIt, char>& ctx)
const -> OutputIt
Trinity::Impl::ChatCommands::ChatCommandResult ChatCommandResult
#define STRING_VIEW_FMT_ARG(str)
@ LANG_CMDPARSER_EXACT_SEQ_MISMATCH
@ LANG_CMDPARSER_LINKDATA_INVALID
@ LANG_CMDPARSER_INVALID_UTF8
std::optional< T > Optional
Optional helper class to wrap optional values within.
bool StringEqualI(std::string_view a, std::string_view b)
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Player session in the World.
HyperlinkInfo TC_GAME_API ParseSingleHyperlink(std::string_view str)
TokenizeResult tokenize(std::string_view args)
typename tag_base< T >::type tag_base_t
std::string FormatTrinityString(ChatHandler const *handler, TrinityStrings which, Ts &&... args)
TC_GAME_API char const * GetTrinityString(ChatHandler const *handler, TrinityStrings which)
constexpr char GetChar(char const (&s)[N], size_t i)
std::string const & GetName() const
WorldSession * GetConnectedSession()
static constexpr std::string_view _string
static constexpr std::array< char, sizeof...(chars)> _storage
ChatCommandResult TryConsume(ChatHandler const *handler, std::string_view args) const
std::remove_cvref_t< value_type > storage_type
ChatCommandResult TryConsume(ChatHandler const *handler, std::string_view args)
storage_type const * operator->() const
typename linktag::value_type value_type
value_type operator*() const
Player * GetConnectedPlayer() const
ObjectGuid GetGUID() const
std::string const & GetName() const
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)
TC_GAME_API ChatCommandResult TryConsume(ChatHandler const *handler, std::string_view args)
ChatCommandResult TryConsume(ChatHandler const *, std::string_view args)
std::string_view value_type
constexpr bool holds_alternative() const
constexpr decltype(auto) visit(T &&arg)
Trinity::Impl::ChatCommands::tag_base_t< T1 > first_type
std::enable_if_t< C, first_type > operator*() const
constexpr decltype(auto) visit(T &&arg) const
constexpr decltype(auto) get()
Variant & operator=(T &&arg)
std::enable_if_t< C, bool > operator!() const
std::variant< T1, Ts... > base
static constexpr bool have_operators
friend std::enable_if_t< C, std::ostream & > operator<<(std::ostream &os, Trinity::ChatCommands::Variant< T1, Ts... > const &v)
constexpr decltype(auto) get() const
ChatCommandResult TryConsume(ChatHandler const *handler, std::string_view args)
std::string_view const data
std::string_view const tag
std::string_view const tail
T operator()(U const &v) const
typename T::value_type type