Added C++ operator overloads to CBotVar

master
krzys-h 2016-05-29 00:06:34 +02:00
parent 7b32f6388f
commit b56cd11c98
2 changed files with 42 additions and 0 deletions

View File

@ -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<CBotVar*>(&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

View File

@ -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