di 0.1.0
Loading...
Searching...
No Matches
value_type.h
Go to the documentation of this file.
1#pragma once
2
5#include "di/meta/core.h"
6#include "di/meta/language.h"
7#include "di/meta/vocab.h"
9
10namespace di::cli {
20
21namespace detail {
22 template<typename Value>
23 constexpr static auto concrete_get_values() -> Vector<Tuple<String, StringView>> {
25 return {};
26 } else {
27 auto result = Vector<Tuple<String, StringView>> {};
29 [&](auto enumerator) {
32 },
33 reflect(Value()));
34 return result;
35 }
36 }
37
38 template<auto member>
39 constexpr static auto concrete_default_value() -> String {
40 using Base = meta::MemberPointerClass<decltype(member)>;
41 using Value = meta::MemberPointerValue<decltype(member)>;
42
43 if constexpr (concepts::Optional<Value> || concepts::InstanceOf<Value, Vector> ||
44 concepts::SameAs<bool, Value>) {
45 return {};
46 } else {
47 auto v = Base();
48 return fmt::to_string(v.*member);
49 }
50 }
51}
52
53namespace detail {
54 template<typename T>
55 struct DefaultValueType {
56 constexpr static auto value = ValueType::Unknown;
57 };
58
59 template<>
60 struct DefaultValueType<PathView> {
61 constexpr static auto value = ValueType::Path;
62 };
63
64 template<>
65 struct DefaultValueType<Path> {
66 constexpr static auto value = ValueType::Path;
67 };
68
69 template<typename T>
70 struct DefaultValueType<Optional<T>> : DefaultValueType<T> {};
71
72 template<typename T>
73 struct DefaultValueType<Vector<T>> : DefaultValueType<T> {};
74
75 template<concepts::Enum T>
76 struct DefaultValueType<T> {
77 constexpr static auto value = ValueType::Enum;
78 };
79}
80
81template<typename T>
82constexpr inline auto default_value_type = detail::DefaultValueType<meta::RemoveCVRef<T>>::value;
83}
Definition vector.h:25
Definition language.h:259
Definition argument.h:13
ValueType
Definition value_type.h:11
@ CommandName
Definition value_type.h:17
@ CommandWithArgs
Definition value_type.h:18
@ Executable
Definition value_type.h:16
@ Unknown
Definition value_type.h:12
@ Path
Definition value_type.h:14
@ Enum
Definition value_type.h:13
@ Directory
Definition value_type.h:15
constexpr auto default_value_type
Definition value_type.h:82
string::StringImpl< string::Utf8Encoding > String
Definition string.h:11
PathViewImpl< string::TransparentEncoding > PathView
Definition path_view.h:11
PathImpl< TransparentString > Path
Definition path.h:10
constexpr auto fixed_string_to_utf8_string_view
Definition fixed_string_to_utf8_string_view.h:32
constexpr auto to_string
Definition to_string.h:14
Type< detail::MemberPointerValueHelper< RemoveCV< T > > > MemberPointerValue
Definition language.h:184
Type< detail::MemberPointerClassHelper< RemoveCV< T > > > MemberPointerClass
Definition language.h:195
Optional(T) -> Optional< T >
constexpr auto enumerator
Definition enumerator.h:41
constexpr auto to_owned
Definition to_owned.h:26
constexpr void tuple_for_each(F &&function, Tup &&tuple)
Definition tuple_for_each.h:22
constexpr auto reflect
Definition reflect.h:47