summaryrefslogtreecommitdiff
path: root/include/ncurses/types.hpp
blob: 16d799f93ae5c790166cf33519f627e45dd9ee95 (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
65
66
67
68
69
#ifndef INCLUDE_NCURSES_ENUMS_HPP_
#define INCLUDE_NCURSES_ENUMS_HPP_

extern "C" {
#include <ncurses.h>
}

#include <ncurses/utils/macros.hpp>

namespace NCURSES_CPP_NAMESPACE {

struct ok_type {
  NCURSES_CPP_CONSTEXPR_INLINE operator bool() const { return true; }
};

NCURSES_CPP_CONSTEXPR_INLINE const ok_type ok;

struct err_type {
  NCURSES_CPP_CONSTEXPR_INLINE operator bool() const { return false; }
};

NCURSES_CPP_CONSTEXPR_INLINE const err_type err;

class result_type {
public:
  NCURSES_CPP_CONSTEXPR result_type(int code) noexcept
      : result_(code == OK ? true : false) {}

  NCURSES_CPP_CONSTEXPR_INLINE operator bool() const { return result_; }
  NCURSES_CPP_CONSTEXPR_INLINE bool operator==(const result_type &rhs) const {
    return result_ == rhs.result_;
  }
  NCURSES_CPP_CONSTEXPR_INLINE bool operator!=(const result_type &rhs) const {
    return result_ != rhs.result_;
  }
  NCURSES_CPP_CONSTEXPR_INLINE bool operator==(const ok_type &rhs) const {
    return result_;
  }
  NCURSES_CPP_CONSTEXPR_INLINE bool operator==(const err_type &rhs) const {
    return !result_;
  }

private:
  bool result_;
};

NCURSES_CPP_CONSTEXPR bool operator==(const ok_type &ok,
                                      const result_type &result) noexcept {
  return result == ok;
}

NCURSES_CPP_CONSTEXPR bool operator!=(const ok_type &ok,
                                      const result_type &result) noexcept {
  return result != ok;
}

NCURSES_CPP_CONSTEXPR bool operator==(const err_type &err,
                                      const result_type &result) noexcept {
  return result == err;
}

NCURSES_CPP_CONSTEXPR bool operator!=(const err_type &err,
                                      const result_type &result) noexcept {
  return result != err;
}

} // namespace NCURSES_CPP_NAMESPACE

#endif // INCLUDE_NCURSES_ENUMS_HPP_