From b56cd11c9805e49957f13f7535cfbdc9c3a1dce7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 29 May 2016 00:06:34 +0200 Subject: [PATCH] Added C++ operator overloads to CBotVar --- src/CBot/CBotVar/CBotVar.cpp | 34 ++++++++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVar.h | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index fc4503ea..4e88cd69 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -741,5 +741,39 @@ CBotClass* CBotVar::GetClass() return nullptr; } +CBotVar::operator int() +{ + return GetValInt(); +} + +CBotVar::operator float() +{ + return GetValFloat(); +} + +CBotVar::operator std::string() +{ + return GetValString(); +} + +void CBotVar::operator=(const CBotVar &var) +{ + SetVal(const_cast(&var)); +} + +void CBotVar::operator=(int x) +{ + SetValInt(x); +} + +void CBotVar::operator=(float x) +{ + SetValFloat(x); +} + +void CBotVar::operator=(const std::string &x) +{ + SetValString(x); +} } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index be171783..7babb7d1 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -444,6 +444,14 @@ public: */ //@{ + operator int(); + operator float(); + operator std::string(); + void operator=(const CBotVar& var); + void operator=(int x); + void operator=(float x); + void operator=(const std::string &x); + /** * \brief Set the value * \param var Another variable to copy value from