Commit cf87f10a authored by chili's avatar chili
Browse files

housekp: optional kbd evt

parent 06326223
......@@ -24,7 +24,7 @@ bool Keyboard::KeyIsPressed( unsigned char keycode ) const noexcept
return keystates[keycode];
}
Keyboard::Event Keyboard::ReadKey() noexcept
std::optional<Keyboard::Event> Keyboard::ReadKey() noexcept
{
if( keybuffer.size() > 0u )
{
......@@ -32,10 +32,7 @@ Keyboard::Event Keyboard::ReadKey() noexcept
keybuffer.pop();
return e;
}
else
{
return Keyboard::Event();
}
return {};
}
bool Keyboard::KeyIsEmpty() const noexcept
......@@ -43,7 +40,7 @@ bool Keyboard::KeyIsEmpty() const noexcept
return keybuffer.empty();
}
char Keyboard::ReadChar() noexcept
std::optional<char> Keyboard::ReadChar() noexcept
{
if( charbuffer.size() > 0u )
{
......@@ -51,10 +48,7 @@ char Keyboard::ReadChar() noexcept
charbuffer.pop();
return charcode;
}
else
{
return 0;
}
return {};
}
bool Keyboard::CharIsEmpty() const noexcept
......
......@@ -20,6 +20,7 @@
#pragma once
#include <queue>
#include <bitset>
#include <optional>
class Keyboard
{
......@@ -32,17 +33,11 @@ public:
{
Press,
Release,
Invalid
};
private:
Type type;
unsigned char code;
public:
Event() noexcept
:
type( Type::Invalid ),
code( 0u )
{}
Event( Type type,unsigned char code ) noexcept
:
type( type ),
......@@ -56,10 +51,6 @@ public:
{
return type == Type::Release;
}
bool IsValid() const noexcept
{
return type != Type::Invalid;
}
unsigned char GetCode() const noexcept
{
return code;
......@@ -71,11 +62,11 @@ public:
Keyboard& operator=( const Keyboard& ) = delete;
// key event stuff
bool KeyIsPressed( unsigned char keycode ) const noexcept;
Event ReadKey() noexcept;
std::optional<Event> ReadKey() noexcept;
bool KeyIsEmpty() const noexcept;
void FlushKey() noexcept;
// char event stuff
char ReadChar() noexcept;
std::optional<char> ReadChar() noexcept;
bool CharIsEmpty() const noexcept;
void FlushChar() noexcept;
void Flush() noexcept;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment