This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch debian/master in repository colobot.
commit ade4aefb0e6855fa98f64515933b7883512e212c Author: Grunaka <d...@romainbreton.fr> Date: Sun Nov 15 21:13:50 2015 +0100 Moving CBotVarBoolean class in its own header and source files. --- src/CBot/CBot.h | 28 ------- src/CBot/CBotProgram.cpp | 10 --- src/CBot/CBotStack.cpp | 6 -- src/CBot/CBotUtils.cpp | 10 +++ src/CBot/CBotUtils.h | 8 ++ src/CBot/CBotVar.cpp | 115 +------------------------- src/CBot/CBotVar/CBotVarBoolean.cpp | 156 ++++++++++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarBoolean.h | 133 ++++++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 9 files changed, 309 insertions(+), 158 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 8c5f411..13a1191 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -344,34 +344,6 @@ public: bool Save1State(FILE* pf) override; }; -// class for the management of boolean -class CBotVarBoolean : public CBotVar -{ -private: - bool m_val; // the value - -public: - CBotVarBoolean( const CBotToken* name ); -// ~CBotVarBoolean(); - - void SetValInt(int val, const char* s = nullptr) override; - void SetValFloat(float val) override; - int GetValInt() override; - float GetValFloat() override; - CBotString GetValString() override; - - void Copy(CBotVar* pSrc, bool bName=true) override; - - void And(CBotVar* left, CBotVar* right) override; - void Or(CBotVar* left, CBotVar* right) override; - void XOr(CBotVar* left, CBotVar* right) override; - void Not() override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - - bool Save1State(FILE* pf) override; -}; - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index c06cfbe..9817f37 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -383,16 +383,6 @@ bool CBotProgram::AddFunction(const char* name, } //////////////////////////////////////////////////////////////////////////////// -bool WriteWord(FILE* pf, unsigned short w) -{ - size_t lg; - - lg = fwrite(&w, sizeof( unsigned short ), 1, pf ); - - return (lg == 1); -} - -//////////////////////////////////////////////////////////////////////////////// bool ReadWord(FILE* pf, unsigned short& w) { size_t lg; diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 1a21dd2..421bf5d 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -991,12 +991,6 @@ bool CBotVarInt::Save1State(FILE* pf) } //////////////////////////////////////////////////////////////////////////////// -bool CBotVarBoolean::Save1State(FILE* pf) -{ - return WriteWord(pf, m_val); // the value of the variable -} - -//////////////////////////////////////////////////////////////////////////////// bool CBotVarFloat::Save1State(FILE* pf) { return WriteFloat(pf, m_val); // the value of the variable diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index bb2b940..3fe76d0 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -105,3 +105,13 @@ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) } return type; } + +//////////////////////////////////////////////////////////////////////////////// +bool WriteWord(FILE* pf, unsigned short w) +{ + size_t lg; + + lg = fwrite(&w, sizeof( unsigned short ), 1, pf ); + + return (lg == 1); +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 9d452d8..47a83d7 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -51,3 +51,11 @@ CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile); * \return */ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type); + +/*! + * \brief WriteWord + * \param pf + * \param w + * \return + */ +bool WriteWord(FILE* pf, unsigned short w); diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index dc2517d..ce0c5f0 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -30,6 +30,7 @@ #include "CBotVar/CBotVarArray.h" #include "CBotVar/CBotVarPointer.h" #include "CBotVar/CBotVarClass.h" +#include "CBotVar/CBotVarBoolean.h" #include "CBotDefines.h" #include "CBotClass.h" @@ -102,22 +103,6 @@ CBotVarString::CBotVarString( const CBotToken* name ) m_val.Empty(); } -CBotVarBoolean::CBotVarBoolean( const CBotToken* name ) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypBoolean; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = 0; - - m_val = 0; -} - CBotVar::~CBotVar( ) { delete m_token; @@ -1139,104 +1124,6 @@ bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) ////////////////////////////////////////////////////////////////////////////////////// // copy a variable into another -void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarBoolean* p = static_cast<CBotVarBoolean*>(pSrc); - - if (bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - - - - -void CBotVarBoolean::SetValInt(int val, const char* s) -{ - m_val = static_cast<bool>(val); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarBoolean::SetValFloat(float val) -{ - m_val = static_cast<bool>(val); - m_binit = CBotVar::InitType::DEF; -} - -int CBotVarBoolean::GetValInt() -{ - return m_val; -} - -float CBotVarBoolean::GetValFloat() -{ - return static_cast<float>(m_val); -} - -CBotString CBotVarBoolean::GetValString() -{ - CBotString ret; - - CBotString res; - - if ( m_binit == CBotVar::InitType::UNDEF ) - { - res.LoadString(TX_UNDEF); - return res; - } - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - res.LoadString(TX_NAN); - return res; - } - - ret.LoadString( m_val > 0 ? ID_TRUE : ID_FALSE ); - return ret; -} - -void CBotVarBoolean::And(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() && right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} -void CBotVarBoolean::Or(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() || right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() ^ right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarBoolean::Not() -{ - m_val = m_val ? false : true ; -} - -bool CBotVarBoolean::Eq(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() == right->GetValInt(); -} - -bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() != right->GetValInt(); -} - -////////////////////////////////////////////////////////////////////////////////////// - -// copy a variable into another void CBotVarString::Copy(CBotVar* pSrc, bool bName) { CBotVarString* p = static_cast<CBotVarString*>(pSrc); diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp new file mode 100644 index 0000000..f1c5934 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarBoolean.cpp @@ -0,0 +1,156 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarBoolean.h" + +#include "CBotUtils.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotVarBoolean::CBotVarBoolean( const CBotToken* name ) +{ + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; + m_InitExpr = nullptr; + m_LimExpr = nullptr; + m_type = CBotTypBoolean; + m_binit = InitType::UNDEF; + m_bStatic = false; + m_mPrivate = 0; + + m_val = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName) +{ + CBotVarBoolean* p = static_cast<CBotVarBoolean*>(pSrc); + + if (bName) *m_token = *p->m_token; + m_type = p->m_type; + m_val = p->m_val; + m_binit = p->m_binit; +//- m_bStatic = p->m_bStatic; + m_next = nullptr; + m_pMyThis = nullptr;//p->m_pMyThis; + m_pUserPtr = p->m_pUserPtr; + + // keeps indentificator the same (by default) + if (m_ident == 0 ) m_ident = p->m_ident; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::SetValInt(int val, const char* s) +{ + m_val = static_cast<bool>(val); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::SetValFloat(float val) +{ + m_val = static_cast<bool>(val); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarBoolean::GetValInt() +{ + return m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +float CBotVarBoolean::GetValFloat() +{ + return static_cast<float>(m_val); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarBoolean::GetValString() +{ + CBotString ret; + + CBotString res; + + if ( m_binit == CBotVar::InitType::UNDEF ) + { + res.LoadString(TX_UNDEF); + return res; + } + if ( m_binit == CBotVar::InitType::IS_NAN ) + { + res.LoadString(TX_NAN); + return res; + } + + ret.LoadString( m_val > 0 ? ID_TRUE : ID_FALSE ); + return ret; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::And(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() && right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::Or(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() || right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() ^ right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::Not() +{ + m_val = m_val ? false : true ; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarBoolean::Eq(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() == right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() != right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarBoolean::Save1State(FILE* pf) +{ + return WriteWord(pf, m_val); // the value of the variable +} diff --git a/src/CBot/CBotVar/CBotVarBoolean.h b/src/CBot/CBotVar/CBotVarBoolean.h new file mode 100644 index 0000000..e57c22f --- /dev/null +++ b/src/CBot/CBotVar/CBotVarBoolean.h @@ -0,0 +1,133 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotToken.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarBoolean class Class for the management of boolean. + */ +class CBotVarBoolean : public CBotVar +{ +public: + + /*! + * \brief CBotVarBoolean + * \param name + */ + CBotVarBoolean( const CBotToken* name ); + + /*! + * \brief SetValInt + * \param val + * \param s + */ + void SetValInt(int val, const char* s = nullptr) override; + + /*! + * \brief SetValFloat + * \param val + */ + void SetValFloat(float val) override; + + /*! + * \brief GetValInt + * \return + */ + int GetValInt() override; + + /*! + * \brief GetValFloat + * \return + */ + float GetValFloat() override; + + /*! + * \brief GetValString + * \return + */ + CBotString GetValString() override; + + /*! + * \brief Copy Copy a variable into another. + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief And + * \param left + * \param right + */ + void And(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Or + * \param left + * \param right + */ + void Or(CBotVar* left, CBotVar* right) override; + + /*! + * \brief XOr + * \param left + * \param right + */ + void XOr(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Not + */ + void Not() override; + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + bool Eq(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + bool Ne(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + +private: + //! The value. + bool m_val; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 098868e..283e01c 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -58,6 +58,7 @@ set(SOURCES CBotVar/CBotVarArray.cpp CBotVar/CBotVarPointer.cpp CBotVar/CBotVarClass.cpp + CBotVar/CBotVarBoolean.cpp ) # Includes -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git _______________________________________________ Pkg-games-commits mailing list Pkg-games-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits