From 2ea94244e9b1da632b024efeb4a9bec7af1e8604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sun, 14 Aug 2022 23:47:47 +0200 Subject: [PATCH] Fixed const-correctness of getters --- src/CBot/CBotVar/CBotVar.cpp | 18 +++++++++--------- src/CBot/CBotVar/CBotVar.h | 18 +++++++++--------- src/CBot/CBotVar/CBotVarArray.cpp | 2 +- src/CBot/CBotVar/CBotVarArray.h | 2 +- src/CBot/CBotVar/CBotVarChar.h | 2 +- src/CBot/CBotVar/CBotVarClass.cpp | 2 +- src/CBot/CBotVar/CBotVarClass.h | 2 +- src/CBot/CBotVar/CBotVarInt.cpp | 2 +- src/CBot/CBotVar/CBotVarInt.h | 2 +- src/CBot/CBotVar/CBotVarPointer.cpp | 2 +- src/CBot/CBotVar/CBotVarPointer.h | 2 +- src/CBot/CBotVar/CBotVarString.h | 4 ++-- src/CBot/CBotVar/CBotVarValue.h | 16 ++++++++-------- 13 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index c975ed7b..4c268cb4 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -355,7 +355,7 @@ CBotTypResult CBotVar::GetTypResult(GetTypeMode mode) } //////////////////////////////////////////////////////////////////////////////// -CBotType CBotVar::GetType(GetTypeMode mode) +CBotType CBotVar::GetType(GetTypeMode mode) const { if ( mode == GetTypeMode::CLASS_AS_POINTER && m_type.Eq(CBotTypClass) ) return CBotTypPointer; @@ -584,43 +584,43 @@ CBotVarClass* CBotVar::GetPointer() // All these functions must be defined in the subclasses // derived from class CBotVar -signed char CBotVar::GetValByte() +signed char CBotVar::GetValByte() const { assert(0); return 0; } -short CBotVar::GetValShort() +short CBotVar::GetValShort() const { assert(0); return 0; } -uint32_t CBotVar::GetValChar() +uint32_t CBotVar::GetValChar() const { assert(0); return 0; } -int CBotVar::GetValInt() +int CBotVar::GetValInt() const { assert(0); return 0; } -long CBotVar::GetValLong() +long CBotVar::GetValLong() const { assert(0); return 0; } -float CBotVar::GetValFloat() +float CBotVar::GetValFloat() const { assert(0); return 0; } -double CBotVar::GetValDouble() +double CBotVar::GetValDouble() const { assert(0); return 0; @@ -822,7 +822,7 @@ void CBotVar::SetValString(const std::string& val) } //////////////////////////////////////////////////////////////////////////////// -std::string CBotVar::GetValString() +std::string CBotVar::GetValString() const { assert(0); return std::string(); diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index e351398d..d1d336cf 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -199,7 +199,7 @@ public: * \brief GetType Returns the base type of the variable (::CBotType) * \param mode Mode, see GetTypeMode enum */ - CBotType GetType(GetTypeMode mode = GetTypeMode::NORMAL); + CBotType GetType(GetTypeMode mode = GetTypeMode::NORMAL) const; /** * \brief Returns the complete type of the variable (CBotTypResult) @@ -508,27 +508,27 @@ public: */ virtual void SetValString(const std::string& val); - virtual signed char GetValByte(); + virtual signed char GetValByte() const; - virtual short GetValShort(); + virtual short GetValShort() const; - virtual uint32_t GetValChar(); + virtual uint32_t GetValChar() const; /** * \brief Get value as integer * \return Current value */ - virtual int GetValInt(); + virtual int GetValInt() const; - virtual long GetValLong(); + virtual long GetValLong() const; /** * \brief Get value as float * \return Current value */ - virtual float GetValFloat(); + virtual float GetValFloat() const; - virtual double GetValDouble(); + virtual double GetValDouble() const; /** * \brief Get value as string @@ -539,7 +539,7 @@ public: * * \return Current value */ - virtual std::string GetValString(); + virtual std::string GetValString() const; /** * \brief Set value for pointer types diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp index b0895448..be31ddd2 100644 --- a/src/CBot/CBotVar/CBotVarArray.cpp +++ b/src/CBot/CBotVar/CBotVarArray.cpp @@ -129,7 +129,7 @@ CBotVar* CBotVarArray::GetItemList() } //////////////////////////////////////////////////////////////////////////////// -std::string CBotVarArray::GetValString() +std::string CBotVarArray::GetValString() const { if ( m_pInstance == nullptr ) return ( std::string( "Null pointer" ) ) ; return m_pInstance->GetValString(); diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h index 46986900..144a5050 100644 --- a/src/CBot/CBotVar/CBotVarArray.h +++ b/src/CBot/CBotVar/CBotVarArray.h @@ -49,7 +49,7 @@ public: CBotVar* GetItem(int n, bool grow = false) override; CBotVar* GetItemList() override; - std::string GetValString() override; + std::string GetValString() const override; bool Save1State(std::ostream &ostr) override; diff --git a/src/CBot/CBotVar/CBotVarChar.h b/src/CBot/CBotVar/CBotVarChar.h index 7b6031d5..6bbfb9c1 100644 --- a/src/CBot/CBotVar/CBotVarChar.h +++ b/src/CBot/CBotVar/CBotVarChar.h @@ -32,7 +32,7 @@ class CBotVarChar : public CBotVarInteger public: CBotVarChar(const CBotToken &name) : CBotVarInteger(name) {} - std::string GetValString() override + std::string GetValString() const override { if (m_binit == CBotVar::InitType::UNDEF) return LoadString(TX_UNDEF); diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index c7d81cb5..5f7743e9 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -291,7 +291,7 @@ CBotVar* CBotVarClass::GetItemList() } //////////////////////////////////////////////////////////////////////////////// -std::string CBotVarClass::GetValString() +std::string CBotVarClass::GetValString() const { std::string res; diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h index 254ec88b..75abca72 100644 --- a/src/CBot/CBotVar/CBotVarClass.h +++ b/src/CBot/CBotVar/CBotVarClass.h @@ -52,7 +52,7 @@ public: CBotVar* GetItemRef(int nIdent) override; CBotVar* GetItem(int n, bool bExtend) override; CBotVar* GetItemList() override; - std::string GetValString() override; + std::string GetValString() const override; bool Save1State(std::ostream &ostr) override; diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index 8a69a9f4..7e4fdc24 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -35,7 +35,7 @@ void CBotVarInt::SetValInt(int val, const std::string& defnum) m_defnum = defnum; } -std::string CBotVarInt::GetValString() +std::string CBotVarInt::GetValString() const { if (!m_defnum.empty()) return m_defnum; return CBotVarValue::GetValString(); diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h index 62c4adeb..c41034d9 100644 --- a/src/CBot/CBotVar/CBotVarInt.h +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -33,7 +33,7 @@ public: CBotVarInt(const CBotToken &name) : CBotVarInteger(name) {} void SetValInt(int val, const std::string& s = "") override; - std::string GetValString() override; + std::string GetValString() const override; void Copy(CBotVar* pSrc, bool bName = true) override; diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp index ed5eda00..db979c97 100644 --- a/src/CBot/CBotVar/CBotVarPointer.cpp +++ b/src/CBot/CBotVar/CBotVarPointer.cpp @@ -90,7 +90,7 @@ CBotVar* CBotVarPointer::GetItemList() } //////////////////////////////////////////////////////////////////////////////// -std::string CBotVarPointer::GetValString() +std::string CBotVarPointer::GetValString() const { std::string s = "Pointer to "; if ( m_pVarClass == nullptr ) s = "Null pointer" ; diff --git a/src/CBot/CBotVar/CBotVarPointer.h b/src/CBot/CBotVar/CBotVarPointer.h index 4fa1d0ae..0d03ae44 100644 --- a/src/CBot/CBotVar/CBotVarPointer.h +++ b/src/CBot/CBotVar/CBotVarPointer.h @@ -47,7 +47,7 @@ public: CBotVar* GetItem(const std::string& name) override; CBotVar* GetItemRef(int nIdent) override; CBotVar* GetItemList() override; - std::string GetValString() override; + std::string GetValString() const override; void SetPointer(CBotVar* p) override; CBotVarClass* GetPointer() override; diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h index 679c7a9a..b4ed70e4 100644 --- a/src/CBot/CBotVar/CBotVarString.h +++ b/src/CBot/CBotVar/CBotVarString.h @@ -48,12 +48,12 @@ public: SetValString(ToString(val)); } - int GetValInt() override + int GetValInt() const override { return FromString(GetValString()); } - float GetValFloat() override + float GetValFloat() const override { return FromString(GetValString()); } diff --git a/src/CBot/CBotVar/CBotVarValue.h b/src/CBot/CBotVar/CBotVarValue.h index 0cc83104..9d1e6f4a 100644 --- a/src/CBot/CBotVar/CBotVarValue.h +++ b/src/CBot/CBotVar/CBotVarValue.h @@ -62,7 +62,7 @@ public: m_binit = CBotVar::InitType::DEF; } - std::string GetValString() override + std::string GetValString() const override { if (m_binit == CBotVar::InitType::UNDEF) return LoadString(TX_UNDEF); @@ -133,37 +133,37 @@ public: this->SetValue(static_cast(val)); } - signed char GetValByte() override + signed char GetValByte() const override { return static_cast(this->m_val); } - short GetValShort() override + short GetValShort() const override { return static_cast(this->m_val); } - uint32_t GetValChar() override + uint32_t GetValChar() const override { return static_cast(this->m_val); } - int GetValInt() override + int GetValInt() const override { return static_cast(this->m_val); } - long GetValLong() override + long GetValLong() const override { return static_cast(this->m_val); } - float GetValFloat() override + float GetValFloat() const override { return static_cast(this->m_val); } - double GetValDouble() override + double GetValDouble() const override { return static_cast(this->m_val); }