12#include "webcface/common/webcface-config.h"
35 if constexpr (std::is_void_v<T>) {
36 return ValType::none_;
37 }
else if constexpr (std::is_same_v<bool, T>) {
38 return ValType::bool_;
39 }
else if constexpr (std::is_integral_v<T>) {
41 }
else if constexpr (std::is_floating_point_v<T>) {
42 return ValType::float_;
44 return ValType::string_;
56 case ValType::string_:
94 std::variant<double, std::int64_t> as_val;
97 enum ValVariant { DOUBLEV = 0, INT64V = 1 };
115 return *
this = std::string_view(str);
135 return *
this = std::wstring_view(str);
147 template <
typename T,
typename std::enable_if_t<std::is_
integral_v<T>,
148 std::
nullptr_t> =
nullptr>
150 :
ValAdaptor(static_cast<std::int64_t>(value)) {}
151 template <
typename T,
typename std::enable_if_t<std::is_
integral_v<T>,
152 std::
nullptr_t> =
nullptr>
154 return *
this =
static_cast<std::int64_t
>(v);
157 template <
typename T,
typename std::enable_if_t<std::is_
floating_po
int_v<T>,
158 std::
nullptr_t> =
nullptr>
160 template <
typename T,
typename std::enable_if_t<std::is_
floating_po
int_v<T>,
161 std::
nullptr_t> =
nullptr>
163 return *
this =
static_cast<double>(v);
188 const std::string &asStringRef()
const;
194 const std::wstring &asWStringRef()
const;
198 const std::string &asU8StringRef()
const;
203 std::string
asString()
const {
return asStringRef(); }
208 std::wstring
asWString()
const {
return asWStringRef(); }
213 operator const std::string &()
const {
return asStringRef(); }
217 operator const std::wstring &()
const {
return asWStringRef(); }
221 operator const char *()
const {
return asStringRef().c_str(); }
225 operator const wchar_t *()
const {
return asWStringRef().c_str(); }
231 double asDouble()
const;
241 long long asLLong()
const;
252 template <
typename T>
253 [[deprecated(
"use asDouble(), asInt() or asLLong() instead")]]
double
255 return static_cast<T
>(asDouble());
260 template <
typename T,
261 typename std::enable_if_t<std::is_convertible_v<double, T> &&
262 !std::is_same_v<T, bool>,
263 std::nullptr_t> =
nullptr>
265 if constexpr (std::is_floating_point_v<T>) {
266 return static_cast<T
>(asDouble());
267 }
else if constexpr (
sizeof(T) >
sizeof(
int)) {
268 return static_cast<T
>(asLLong());
270 return static_cast<T
>(asInt());
286 operator bool()
const {
return asBool(); }
291 template <
typename T,
typename std::enable_if_t<
292 std::is_constructible_v<ValAdaptor, T> &&
293 !std::is_same_v<ValAdaptor, T>,
294 std::nullptr_t> =
nullptr>
298 template <
typename T,
typename std::enable_if_t<
299 std::is_constructible_v<ValAdaptor, T> &&
300 !std::is_same_v<ValAdaptor, T>,
301 std::nullptr_t> =
nullptr>
308 typename std::enable_if_t<std::is_constructible_v<ValAdaptor, T> &&
309 !std::is_same_v<ValAdaptor, T>,
310 std::nullptr_t> =
nullptr>
315 typename std::enable_if_t<std::is_constructible_v<ValAdaptor, T> &&
316 !std::is_same_v<ValAdaptor, T>,
317 std::nullptr_t> =
nullptr>
323 return os << static_cast<std::string>(a);
330template <
int n = 0,
typename T>
331void argToTuple(
const std::vector<ValAdaptor> &args, T &tuple) {
332 constexpr int tuple_size = std::tuple_size<T>::value;
333 if constexpr (n < tuple_size) {
334 using Type =
typename std::tuple_element<n, T>::type;
335 std::get<n>(tuple) =
static_cast<Type
>(args[n]);
336 argToTuple<n + 1>(args, tuple);
340namespace [[deprecated(
"symbols in webcface::encoding namespace are "
341 "now directly in webcface namespace")]] encoding {
345 return webcface::valTypeOf<T>();
352template <
int n = 0,
typename T>
353void argToTuple(
const std::vector<webcface::ValAdaptor> &args, T &tuple) {
354 webcface::argToTuple<n>(args, tuple);
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
数値、文字列などの値を相互変換するクラス
Definition val_adaptor.h:87
bool operator==(const T &other) const
Definition val_adaptor.h:295
std::string asString() const
文字列として返す(コピー)
Definition val_adaptor.h:203
double as() const
数値として返す
Definition val_adaptor.h:254
bool operator!=(const ValAdaptor &other) const
Definition val_adaptor.h:289
ValAdaptor & operator=(const wchar_t *str)
Definition val_adaptor.h:134
bool operator!=(const T &other) const
Definition val_adaptor.h:302
ValAdaptor(T value)
Definition val_adaptor.h:149
ValType valType() const
Definition val_adaptor.h:166
ValAdaptor & operator=(T v)
Definition val_adaptor.h:153
std::wstring asWString() const
文字列として返す(コピー) (wstring)
Definition val_adaptor.h:208
ValAdaptor(const char *str)
Definition val_adaptor.h:113
ValAdaptor & operator=(const char *str)
Definition val_adaptor.h:114
ValAdaptor(const wchar_t *str)
Definition val_adaptor.h:129
std::ostream & operator<<(std::ostream &os, const Arg &arg)
Definition func_info.cc:96
bool operator==(const T &other, const InputRef &ref)
Definition text.h:566
void argToTuple(const std::vector< ValAdaptor > &args, T &tuple)
ValAdaptorのリストから任意の型のタプルに変換する
Definition val_adaptor.h:331
std::string valTypeStr(ValType a)
型名を文字列で取得
Definition val_adaptor.h:52
ValType
引数や戻り値の型を表すenum
Definition val_adaptor.h:21
ValType valTypeOf()
TのValTypeを得る
Definition val_adaptor.h:34
bool operator!=(const T &other, const InputRef &ref)
Definition text.h:572
#define WEBCFACE_DLL
Definition webcface-config.h:60
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103