Try to clean up option include a bit

This commit is contained in:
Maxime Coste 2017-03-16 09:57:39 +00:00
parent 7eaa058450
commit 5f7464d90d
13 changed files with 77 additions and 54 deletions

View File

@ -3,6 +3,7 @@
#include "clock.hh" #include "clock.hh"
#include "coord.hh" #include "coord.hh"
#include "enum.hh"
#include "safe_ptr.hh" #include "safe_ptr.hh"
#include "scope.hh" #include "scope.hh"
#include "shared_string.hh" #include "shared_string.hh"

View File

@ -6,6 +6,7 @@
#include "buffer_utils.hh" #include "buffer_utils.hh"
#include "file.hh" #include "file.hh"
#include "remote.hh" #include "remote.hh"
#include "option.hh"
#include "client_manager.hh" #include "client_manager.hh"
#include "command_manager.hh" #include "command_manager.hh"
#include "event_manager.hh" #include "event_manager.hh"

View File

@ -1339,6 +1339,7 @@ const CommandDesc declare_option_cmd = {
auto docstring = parser.get_switch("docstring").value_or(StringView{}).str(); auto docstring = parser.get_switch("docstring").value_or(StringView{}).str();
OptionsRegistry& reg = GlobalScope::instance().option_registry(); OptionsRegistry& reg = GlobalScope::instance().option_registry();
if (parser[0] == "int") if (parser[0] == "int")
opt = &reg.declare_option<int>(parser[1], docstring, 0, flags); opt = &reg.declare_option<int>(parser[1], docstring, 0, flags);
else if (parser[0] == "bool") else if (parser[0] == "bool")

View File

@ -10,7 +10,7 @@
#include "face_registry.hh" #include "face_registry.hh"
#include "highlighter_group.hh" #include "highlighter_group.hh"
#include "line_modification.hh" #include "line_modification.hh"
#include "option_types.hh" #include "option.hh"
#include "parameters_parser.hh" #include "parameters_parser.hh"
#include "register_manager.hh" #include "register_manager.hh"
#include "regex.hh" #include "regex.hh"

View File

@ -7,6 +7,7 @@
#include "display_buffer.hh" #include "display_buffer.hh"
#include "face_registry.hh" #include "face_registry.hh"
#include "regex.hh" #include "regex.hh"
#include "option.hh"
namespace Kakoune namespace Kakoune
{ {

View File

@ -2,6 +2,7 @@
#define insert_completer_hh_INCLUDED #define insert_completer_hh_INCLUDED
#include "option_manager.hh" #include "option_manager.hh"
#include "option.hh"
#include "display_buffer.hh" #include "display_buffer.hh"
#include "vector.hh" #include "vector.hh"

View File

@ -1,6 +1,6 @@
#include "assert.hh" #include "assert.hh"
#include "buffer.hh"
#include "backtrace.hh" #include "backtrace.hh"
#include "buffer.hh"
#include "buffer_manager.hh" #include "buffer_manager.hh"
#include "buffer_utils.hh" #include "buffer_utils.hh"
#include "client_manager.hh" #include "client_manager.hh"
@ -13,14 +13,15 @@
#include "file.hh" #include "file.hh"
#include "highlighters.hh" #include "highlighters.hh"
#include "insert_completer.hh" #include "insert_completer.hh"
#include "shared_string.hh"
#include "ncurses_ui.hh"
#include "json_ui.hh" #include "json_ui.hh"
#include "ncurses_ui.hh"
#include "option_types.hh"
#include "parameters_parser.hh" #include "parameters_parser.hh"
#include "regex.hh"
#include "register_manager.hh" #include "register_manager.hh"
#include "remote.hh" #include "remote.hh"
#include "regex.hh"
#include "scope.hh" #include "scope.hh"
#include "shared_string.hh"
#include "shell_manager.hh" #include "shell_manager.hh"
#include "string.hh" #include "string.hh"
#include "unit_tests.hh" #include "unit_tests.hh"

View File

@ -3,7 +3,7 @@
namespace Kakoune namespace Kakoune
{ {
namespace Meta inline namespace Meta
{ {
template<typename T> struct Type {}; template<typename T> struct Type {};

59
src/option.hh Normal file
View File

@ -0,0 +1,59 @@
#ifndef option_hh_INCLUDED
#define option_hh_INCLUDED
#include "enum.hh"
namespace Kakoune
{
class String;
// 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);
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
{
None = 0,
Hooks = 1 << 0,
Shell = 1 << 1,
Profile = 1 << 2,
Keys = 1 << 3,
};
constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
constexpr Array<EnumDesc<DebugFlags>, 4> enum_desc(Meta::Type<DebugFlags>)
{
return { {
{ DebugFlags::Hooks, "hooks" },
{ DebugFlags::Shell, "shell" },
{ DebugFlags::Profile, "profile" },
{ DebugFlags::Keys, "keys" }
} };
}
}
#endif // option_hh_INCLUDED

View File

@ -4,8 +4,8 @@
#include "completion.hh" #include "completion.hh"
#include "containers.hh" #include "containers.hh"
#include "exception.hh" #include "exception.hh"
#include "option_types.hh"
#include "vector.hh" #include "vector.hh"
#include "option.hh"
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>

View File

@ -1,14 +1,13 @@
#ifndef option_types_hh_INCLUDED #ifndef option_types_hh_INCLUDED
#define option_types_hh_INCLUDED #define option_types_hh_INCLUDED
#include "option.hh"
#include "exception.hh" #include "exception.hh"
#include "string.hh" #include "string.hh"
#include "units.hh" #include "units.hh"
#include "coord.hh" #include "coord.hh"
#include "array_view.hh" #include "array_view.hh"
#include "hash_map.hh" #include "hash_map.hh"
#include "flags.hh"
#include "enum.hh"
#include <tuple> #include <tuple>
#include <vector> #include <vector>
@ -39,7 +38,7 @@ inline bool option_add(int& opt, StringView str)
opt += val; opt += val;
return val != 0; return val != 0;
} }
inline StringView option_type_name(Meta::Type<int>) { return "int"; } constexpr StringView option_type_name(Meta::Type<int>) { return "int"; }
inline String option_to_string(size_t opt) { return to_string(opt); } inline String option_to_string(size_t opt) { return to_string(opt); }
inline void option_from_string(StringView str, size_t& opt) { opt = str_to_int(str); } inline void option_from_string(StringView str, size_t& opt) { opt = str_to_int(str); }
@ -54,7 +53,7 @@ inline void option_from_string(StringView str, bool& opt)
else else
throw runtime_error("boolean values are either true, yes, false or no"); throw runtime_error("boolean values are either true, yes, false or no");
} }
inline StringView option_type_name(Meta::Type<bool>) { return "bool"; } constexpr StringView option_type_name(Meta::Type<bool>) { return "bool"; }
constexpr char list_separator = ':'; constexpr char list_separator = ':';
@ -233,27 +232,6 @@ inline String option_to_string(const LineAndColumn<EffectiveType, LineType, Colu
return format("{},{}", opt.line, opt.column); return format("{},{}", opt.line, opt.column);
} }
enum class DebugFlags
{
None = 0,
Hooks = 1 << 0,
Shell = 1 << 1,
Profile = 1 << 2,
Keys = 1 << 3,
};
constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
constexpr Array<EnumDesc<DebugFlags>, 4> enum_desc(Meta::Type<DebugFlags>)
{
return { {
{ DebugFlags::Hooks, "hooks" },
{ DebugFlags::Shell, "shell" },
{ DebugFlags::Profile, "profile" },
{ DebugFlags::Keys, "keys" }
} };
}
template<typename Flags, typename = decltype(enum_desc(Meta::Type<Flags>{}))> template<typename Flags, typename = decltype(enum_desc(Meta::Type<Flags>{}))>
EnableIfWithBitOps<Flags, String> option_to_string(Flags flags) EnableIfWithBitOps<Flags, String> option_to_string(Flags flags)
{ {
@ -314,25 +292,6 @@ EnableIfWithBitOps<Flags, bool> option_add(Flags& opt, StringView str)
return res != (Flags)0; return res != (Flags)0;
} }
template<typename P, typename T>
struct PrefixedList
{
P prefix;
Vector<T, MemoryDomain::Options> list;
};
template<typename P, typename T>
inline bool operator==(const PrefixedList<P, T>& lhs, const PrefixedList<P, T>& rhs)
{
return lhs.prefix == rhs.prefix and lhs.list == rhs.list;
}
template<typename P, typename T>
inline bool operator!=(const PrefixedList<P, T>& lhs, const PrefixedList<P, T>& rhs)
{
return not (lhs == rhs);
}
template<typename P, typename T> template<typename P, typename T>
inline String option_to_string(const PrefixedList<P, T>& opt) inline String option_to_string(const PrefixedList<P, T>& opt)
{ {
@ -354,9 +313,6 @@ inline bool option_add(PrefixedList<P, T>& opt, StringView str)
return option_add(opt.list, str); return option_add(opt.list, str);
} }
template<typename T>
using TimestampedList = PrefixedList<size_t, T>;
} }
#endif // option_types_hh_INCLUDED #endif // option_types_hh_INCLUDED

View File

@ -8,6 +8,7 @@
#include "face_registry.hh" #include "face_registry.hh"
#include "file.hh" #include "file.hh"
#include "flags.hh" #include "flags.hh"
#include "option.hh"
#include "regex.hh" #include "regex.hh"
#include <cstring> #include <cstring>

View File

@ -8,6 +8,7 @@
#include "input_handler.hh" #include "input_handler.hh"
#include "client.hh" #include "client.hh"
#include "buffer_utils.hh" #include "buffer_utils.hh"
#include "option.hh"
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>