summaryrefslogtreecommitdiff
path: root/src/option.hh
blob: f4aafe3a9f59aecae9bba32f3b307d4b17ba65e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef option_hh_INCLUDED
#define option_hh_INCLUDED

#include "enum.hh"
#include "meta.hh"
#include "vector.hh"
#include "constexpr_utils.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,
    Commands = 1 << 4,
};

constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }

constexpr auto enum_desc(Meta::Type<DebugFlags>)
{
    return make_array<EnumDesc<DebugFlags>, 5>({
        { DebugFlags::Hooks, "hooks" },
        { DebugFlags::Shell, "shell" },
        { DebugFlags::Profile, "profile" },
        { DebugFlags::Keys, "keys" },
        { DebugFlags::Commands, "commands" },
    });
}

}

#endif // option_hh_INCLUDED