From 5f7464d90d0bfe641dd2c7bbbca6e78d92d9d818 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 16 Mar 2017 09:57:39 +0000 Subject: [PATCH] Try to clean up option include a bit --- src/buffer.hh | 1 + src/client.cc | 1 + src/commands.cc | 1 + src/highlighters.cc | 2 +- src/hook_manager.cc | 1 + src/insert_completer.hh | 1 + src/main.cc | 9 ++++--- src/meta.hh | 2 +- src/option.hh | 59 +++++++++++++++++++++++++++++++++++++++++ src/option_manager.hh | 2 +- src/option_types.hh | 50 +++------------------------------- src/shell_manager.cc | 1 + src/window.cc | 1 + 13 files changed, 77 insertions(+), 54 deletions(-) create mode 100644 src/option.hh diff --git a/src/buffer.hh b/src/buffer.hh index 7e4b54be..6393dc17 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -3,6 +3,7 @@ #include "clock.hh" #include "coord.hh" +#include "enum.hh" #include "safe_ptr.hh" #include "scope.hh" #include "shared_string.hh" diff --git a/src/client.cc b/src/client.cc index e9da59ff..3ce8436d 100644 --- a/src/client.cc +++ b/src/client.cc @@ -6,6 +6,7 @@ #include "buffer_utils.hh" #include "file.hh" #include "remote.hh" +#include "option.hh" #include "client_manager.hh" #include "command_manager.hh" #include "event_manager.hh" diff --git a/src/commands.cc b/src/commands.cc index a57e8031..ec8cd6ca 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1339,6 +1339,7 @@ const CommandDesc declare_option_cmd = { auto docstring = parser.get_switch("docstring").value_or(StringView{}).str(); OptionsRegistry& reg = GlobalScope::instance().option_registry(); + if (parser[0] == "int") opt = ®.declare_option(parser[1], docstring, 0, flags); else if (parser[0] == "bool") diff --git a/src/highlighters.cc b/src/highlighters.cc index 8fef89ca..e68f2088 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -10,7 +10,7 @@ #include "face_registry.hh" #include "highlighter_group.hh" #include "line_modification.hh" -#include "option_types.hh" +#include "option.hh" #include "parameters_parser.hh" #include "register_manager.hh" #include "regex.hh" diff --git a/src/hook_manager.cc b/src/hook_manager.cc index a5f2f7e0..ad30c350 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -7,6 +7,7 @@ #include "display_buffer.hh" #include "face_registry.hh" #include "regex.hh" +#include "option.hh" namespace Kakoune { diff --git a/src/insert_completer.hh b/src/insert_completer.hh index d7061c37..b0bd13ef 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -2,6 +2,7 @@ #define insert_completer_hh_INCLUDED #include "option_manager.hh" +#include "option.hh" #include "display_buffer.hh" #include "vector.hh" diff --git a/src/main.cc b/src/main.cc index 426e7809..2c6b996d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ #include "assert.hh" -#include "buffer.hh" #include "backtrace.hh" +#include "buffer.hh" #include "buffer_manager.hh" #include "buffer_utils.hh" #include "client_manager.hh" @@ -13,14 +13,15 @@ #include "file.hh" #include "highlighters.hh" #include "insert_completer.hh" -#include "shared_string.hh" -#include "ncurses_ui.hh" #include "json_ui.hh" +#include "ncurses_ui.hh" +#include "option_types.hh" #include "parameters_parser.hh" +#include "regex.hh" #include "register_manager.hh" #include "remote.hh" -#include "regex.hh" #include "scope.hh" +#include "shared_string.hh" #include "shell_manager.hh" #include "string.hh" #include "unit_tests.hh" diff --git a/src/meta.hh b/src/meta.hh index 32f28dbb..768556eb 100644 --- a/src/meta.hh +++ b/src/meta.hh @@ -3,7 +3,7 @@ namespace Kakoune { -namespace Meta +inline namespace Meta { template struct Type {}; diff --git a/src/option.hh b/src/option.hh new file mode 100644 index 00000000..c54de083 --- /dev/null +++ b/src/option.hh @@ -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 +struct PrefixedList +{ + P prefix; + Vector 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 +using TimestampedList = PrefixedList; + +enum class DebugFlags +{ + None = 0, + Hooks = 1 << 0, + Shell = 1 << 1, + Profile = 1 << 2, + Keys = 1 << 3, +}; + +constexpr bool with_bit_ops(Meta::Type) { return true; } + +constexpr Array, 4> enum_desc(Meta::Type) +{ + return { { + { DebugFlags::Hooks, "hooks" }, + { DebugFlags::Shell, "shell" }, + { DebugFlags::Profile, "profile" }, + { DebugFlags::Keys, "keys" } + } }; +} + +} + +#endif // option_hh_INCLUDED diff --git a/src/option_manager.hh b/src/option_manager.hh index b20303b0..e19ae44a 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -4,8 +4,8 @@ #include "completion.hh" #include "containers.hh" #include "exception.hh" -#include "option_types.hh" #include "vector.hh" +#include "option.hh" #include #include diff --git a/src/option_types.hh b/src/option_types.hh index 0193c821..ec7796f6 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -1,14 +1,13 @@ #ifndef option_types_hh_INCLUDED #define option_types_hh_INCLUDED +#include "option.hh" #include "exception.hh" #include "string.hh" #include "units.hh" #include "coord.hh" #include "array_view.hh" #include "hash_map.hh" -#include "flags.hh" -#include "enum.hh" #include #include @@ -39,7 +38,7 @@ inline bool option_add(int& opt, StringView str) opt += val; return val != 0; } -inline StringView option_type_name(Meta::Type) { return "int"; } +constexpr StringView option_type_name(Meta::Type) { return "int"; } 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); } @@ -54,7 +53,7 @@ inline void option_from_string(StringView str, bool& opt) else throw runtime_error("boolean values are either true, yes, false or no"); } -inline StringView option_type_name(Meta::Type) { return "bool"; } +constexpr StringView option_type_name(Meta::Type) { return "bool"; } constexpr char list_separator = ':'; @@ -233,27 +232,6 @@ inline String option_to_string(const LineAndColumn) { return true; } - -constexpr Array, 4> enum_desc(Meta::Type) -{ - return { { - { DebugFlags::Hooks, "hooks" }, - { DebugFlags::Shell, "shell" }, - { DebugFlags::Profile, "profile" }, - { DebugFlags::Keys, "keys" } - } }; -} - template{}))> EnableIfWithBitOps option_to_string(Flags flags) { @@ -314,25 +292,6 @@ EnableIfWithBitOps option_add(Flags& opt, StringView str) return res != (Flags)0; } -template -struct PrefixedList -{ - P prefix; - Vector list; -}; - -template -inline bool operator==(const PrefixedList& lhs, const PrefixedList& rhs) -{ - return lhs.prefix == rhs.prefix and lhs.list == rhs.list; -} - -template -inline bool operator!=(const PrefixedList& lhs, const PrefixedList& rhs) -{ - return not (lhs == rhs); -} - template inline String option_to_string(const PrefixedList& opt) { @@ -354,9 +313,6 @@ inline bool option_add(PrefixedList& opt, StringView str) return option_add(opt.list, str); } -template -using TimestampedList = PrefixedList; - } #endif // option_types_hh_INCLUDED diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 78147d76..ad7f18ed 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -8,6 +8,7 @@ #include "face_registry.hh" #include "file.hh" #include "flags.hh" +#include "option.hh" #include "regex.hh" #include diff --git a/src/window.cc b/src/window.cc index fc099c45..3ba1a8ee 100644 --- a/src/window.cc +++ b/src/window.cc @@ -8,6 +8,7 @@ #include "input_handler.hh" #include "client.hh" #include "buffer_utils.hh" +#include "option.hh" #include #include