Move NestedBool to utils.hh

This commit is contained in:
Maxime Coste 2017-06-07 11:55:42 +01:00
parent 21da24235a
commit 87477cf2bb
2 changed files with 33 additions and 32 deletions

View File

@ -3,6 +3,7 @@
#include "selection.hh"
#include "optional.hh"
#include "utils.hh"
namespace Kakoune
{
@ -16,38 +17,6 @@ class DisplayLine;
class KeymapManager;
class AliasRegistry;
// bool that can be set (to true) multiple times, and will
// be false only when unset the same time;
struct NestedBool
{
void set() { m_count++; }
void unset() { kak_assert(m_count > 0); m_count--; }
operator bool() const { return m_count > 0; }
private:
int m_count = 0;
};
struct ScopedSetBool
{
ScopedSetBool(NestedBool& nested_bool, bool condition = true)
: m_nested_bool(nested_bool), m_condition(condition)
{
if (m_condition)
m_nested_bool.set();
}
~ScopedSetBool()
{
if (m_condition)
m_nested_bool.unset();
}
private:
NestedBool& m_nested_bool;
bool m_condition;
};
struct JumpList
{
void push(SelectionList jump);

View File

@ -79,6 +79,38 @@ OnScopeEnd<T> on_scope_end(T t)
return OnScopeEnd<T>{std::move(t)};
}
// bool that can be set (to true) multiple times, and will
// be false only when unset the same time;
struct NestedBool
{
void set() { m_count++; }
void unset() { kak_assert(m_count > 0); m_count--; }
operator bool() const { return m_count > 0; }
private:
int m_count = 0;
};
struct ScopedSetBool
{
ScopedSetBool(NestedBool& nested_bool, bool condition = true)
: m_nested_bool(nested_bool), m_condition(condition)
{
if (m_condition)
m_nested_bool.set();
}
~ScopedSetBool()
{
if (m_condition)
m_nested_bool.unset();
}
private:
NestedBool& m_nested_bool;
bool m_condition;
};
// *** Misc helper functions ***
template<typename T, typename... Args>