2017-03-16 10:57:39 +01:00
|
|
|
#ifndef option_hh_INCLUDED
|
|
|
|
#define option_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "enum.hh"
|
2017-03-17 00:08:10 +01:00
|
|
|
#include "meta.hh"
|
2017-11-12 06:01:18 +01:00
|
|
|
#include "vector.hh"
|
|
|
|
#include "constexpr_utils.hh"
|
2017-03-16 10:57:39 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
class String;
|
2019-06-18 14:18:17 +02:00
|
|
|
enum class Quoting;
|
2017-03-16 10:57:39 +01:00
|
|
|
|
|
|
|
// Forward declare functions that wont get found by ADL
|
|
|
|
inline String option_to_string(int opt);
|
|
|
|
inline String option_to_string(size_t opt);
|
|
|
|
inline String option_to_string(bool opt);
|
|
|
|
|
2018-05-30 15:23:38 +02:00
|
|
|
// Default fallback to single value functions
|
|
|
|
template<typename T>
|
|
|
|
decltype(option_from_string(Meta::Type<T>{}, StringView{}))
|
|
|
|
option_from_strings(Meta::Type<T>, ConstArrayView<String> strs)
|
|
|
|
{
|
|
|
|
if (strs.size() != 1)
|
|
|
|
throw runtime_error("expected a single value for option");
|
|
|
|
return option_from_string(Meta::Type<T>{}, strs[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2019-06-18 14:18:17 +02:00
|
|
|
Vector<decltype(option_to_string(std::declval<T>(), Quoting{}))>
|
2018-05-30 15:23:38 +02:00
|
|
|
option_to_strings(const T& opt)
|
|
|
|
{
|
2019-06-18 14:18:17 +02:00
|
|
|
return Vector<String>{option_to_string(opt, Quoting{})};
|
2018-05-30 15:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
decltype(option_add(std::declval<T>(), std::declval<String>()))
|
|
|
|
option_add_from_strings(T& opt, ConstArrayView<String> strs)
|
|
|
|
{
|
|
|
|
if (strs.size() != 1)
|
|
|
|
throw runtime_error("expected a single value for option");
|
|
|
|
return option_add(opt, strs[0]);
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:57:39 +01:00
|
|
|
template<typename P, typename T>
|
|
|
|
struct PrefixedList
|
|
|
|
{
|
|
|
|
P prefix;
|
|
|
|
Vector<T, MemoryDomain::Options> list;
|
|
|
|
|
|
|
|
friend bool operator==(const PrefixedList& lhs, const PrefixedList& rhs)
|
|
|
|
{
|
|
|
|
return lhs.prefix == rhs.prefix and lhs.list == rhs.list;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator!=(const PrefixedList& lhs, const PrefixedList& rhs)
|
|
|
|
{
|
|
|
|
return not (lhs == rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using TimestampedList = PrefixedList<size_t, T>;
|
|
|
|
|
|
|
|
enum class DebugFlags
|
|
|
|
{
|
2017-06-17 10:27:07 +02:00
|
|
|
None = 0,
|
|
|
|
Hooks = 1 << 0,
|
|
|
|
Shell = 1 << 1,
|
|
|
|
Profile = 1 << 2,
|
|
|
|
Keys = 1 << 3,
|
|
|
|
Commands = 1 << 4,
|
2017-03-16 10:57:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
|
|
|
|
|
2017-11-12 06:01:18 +01:00
|
|
|
constexpr auto enum_desc(Meta::Type<DebugFlags>)
|
2017-03-16 10:57:39 +01:00
|
|
|
{
|
2017-11-12 06:01:18 +01:00
|
|
|
return make_array<EnumDesc<DebugFlags>, 5>({
|
2017-03-16 10:57:39 +01:00
|
|
|
{ DebugFlags::Hooks, "hooks" },
|
|
|
|
{ DebugFlags::Shell, "shell" },
|
|
|
|
{ DebugFlags::Profile, "profile" },
|
2017-06-17 10:27:07 +02:00
|
|
|
{ DebugFlags::Keys, "keys" },
|
|
|
|
{ DebugFlags::Commands, "commands" },
|
2017-11-12 06:01:18 +01:00
|
|
|
});
|
2017-03-16 10:57:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // option_hh_INCLUDED
|