From d96de590a232631bbb9a9a092f85193bd95b6da3 Mon Sep 17 00:00:00 2001 From: skaupper Date: Mon, 27 Feb 2017 09:44:50 +0100 Subject: [PATCH] add implicit conversions to std::string and const char * --- include/bkengine/Keys.h | 6 ++++++ src/Keys.cpp | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/bkengine/Keys.h b/include/bkengine/Keys.h index e779ef5..55da417 100644 --- a/include/bkengine/Keys.h +++ b/include/bkengine/Keys.h @@ -15,6 +15,9 @@ namespace bkengine Keys(const std::string &keyString) : keyString(keyString) {} bool operator==(const Keys &) const; bool operator!=(const Keys &) const; + + operator const std::string() const; + operator const char *() const; std::string toString() const; static Keys UNKNOWN; @@ -167,6 +170,9 @@ namespace bkengine Buttons(const std::string &buttonString) : buttonString(buttonString) {} bool operator==(const Buttons &) const; bool operator!=(const Buttons &) const; + + operator const std::string() const; + operator const char *() const; std::string toString(); static Buttons UNKNOWN; diff --git a/src/Keys.cpp b/src/Keys.cpp index a904836..2b4fa94 100644 --- a/src/Keys.cpp +++ b/src/Keys.cpp @@ -151,6 +151,16 @@ bool Keys::operator!=(const Keys &key) const return !(key == *this); } +Keys::operator const std::string() const +{ + return keyString; +} + +Keys::operator const char *() const +{ + return keyString.c_str(); +} + std::string Keys::toString() const { return keyString; @@ -173,6 +183,16 @@ bool Buttons::operator!=(const Buttons &button) const return !(button == *this); } +Buttons::operator const std::string() const +{ + return buttonString; +} + +Buttons::operator const char *() const +{ + return buttonString.c_str(); +} + std::string Buttons::toString() { return buttonString;