rolmodl
C++ API for the Simple Directmedia Library 2 (SDL2)
Kb.cpp
1 #include "hpp/Kb.hpp"
2 
3 #include <stdexcept>
4 
5 namespace rolmodl::kb {
6  namespace key {
7  /*static*/ void Name::query(const Key k) noexcept {
8  instance().data_ = SDL_GetKeyName(key::unsafe::toSDLEnum(k));
9  }
10  /*static*/ const char* Name::lastQueryRes() noexcept {
11  return instance().data_;
12  }
13 
14  /*static*/ Name& Name::instance() noexcept {
15  static Name res{};
16  return res;
17  }
18 
19  Name::Name() :
20  data_(nullptr)
21  {}
22  }
23 
24  /*static*/ bool State::down(const Scancode s) {
25  const unsigned int i = scancode::unsafe::toSDLEnum(s);
26  if (i > unsafeRawL())
27  throw std::out_of_range("rolmodl::kb::State::down");
28  return static_cast<bool>(unsafeRaw()[i]);
29  }
30  /*static*/ bool State::up(const Scancode s) {
31  return !down(s);
32  }
33 
34  /*static*/ bool State::down(const Key k) {
35  return down(key::scancode(k));
36  }
37  /*static*/ bool State::up(const Key k) {
38  return !down(k);
39  }
40 
41  /*static*/ State& State::instance() noexcept {
42  static State res{};
43  return res;
44  }
45 
46  /*static*/ const uint8_t* State::unsafeRaw() noexcept {
47  return instance().data_;
48  }
49  /*static*/ unsigned int State::unsafeRawL() noexcept {
50  return instance().l_;
51  }
52 
53  State::State() noexcept :
54  data_(nullptr),
55  l_(0)
56  {
57  int tmp = 0;
58  data_ = SDL_GetKeyboardState(&tmp);
59  l_ = static_cast<unsigned int>(tmp);
60  }
61 }
stdexcept
rolmodl::sys::pwr::State
State
Indicates battery status a.k.a. the system power state.
Definition: Base.hpp:138
std::out_of_range