From 85756b4da15386af93c1d69c450018bb9767e978 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 17:47:44 +0100 Subject: [PATCH] Moving CBotExprNan class in its own header and source files. --- src/CBot/CBot.cpp | 33 +---------------- src/CBot/CBot.h | 12 ------ src/CBot/CBotInstr/CBotExprNan.cpp | 55 ++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprNan.h | 59 ++++++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 116 insertions(+), 44 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprNan.cpp create mode 100644 src/CBot/CBotInstr/CBotExprNan.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 4c705eb3..b69af068 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -46,6 +46,7 @@ #include "CBotInstr/CBotExprAlpha.h" #include "CBotInstr/CBotExprNum.h" #include "CBotInstr/CBotNew.h" +#include "CBotInstr/CBotExprNan.h" // Local include @@ -2773,38 +2774,6 @@ void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain) if (bMain) pj->RestoreStack(this); } -////////////////////////////////////////////////////////////////////////////////////////// - -// management of the operand "nan" - -CBotExprNan::CBotExprNan() -{ - name = "CBotExprNan"; -} - -CBotExprNan::~CBotExprNan() -{ -} - -// executes, returns null pointer - -bool CBotExprNan::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->IfStep()) return false; - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypInt); - - var->SetInit(CBotVar::InitType::IS_NAN); // nan - pile->SetVar(var); // put on the stack - return pj->Return(pile); // forward below -} - -void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) pj->RestoreStack(this); -} - ////////////////////////////////////////////////////////////////////////////////////// // compile a variable name // check that it is known on the stack diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 76549b0f..1e0f91e1 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -976,18 +976,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotExprNan : public CBotInstr -{ -private: - -public: - CBotExprNan(); - ~CBotExprNan(); - - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprNan.cpp b/src/CBot/CBotInstr/CBotExprNan.cpp new file mode 100644 index 00000000..3eebb74a --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNan.cpp @@ -0,0 +1,55 @@ +/* + * 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 "CBotExprNan.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotExprNan::CBotExprNan() +{ + name = "CBotExprNan"; +} +//////////////////////////////////////////////////////////////////////////////// +CBotExprNan::~CBotExprNan() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprNan::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->IfStep()) return false; + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypInt); + + var->SetInit(CBotVar::InitType::IS_NAN); // nan + pile->SetVar(var); // put on the stack + return pj->Return(pile); // forward below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) pj->RestoreStack(this); +} diff --git a/src/CBot/CBotInstr/CBotExprNan.h b/src/CBot/CBotInstr/CBotExprNan.h new file mode 100644 index 00000000..0d6bbf6f --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNan.h @@ -0,0 +1,59 @@ +/* + * 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 "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotExprNan class Management of the operand "nan". + */ +class CBotExprNan : public CBotInstr +{ +public: + + /*! + * \brief CBotExprNan + */ + CBotExprNan(); + + /*! + * \brief ~CBotExprNan + */ + ~CBotExprNan(); + + /*! + * \brief Execute Executes, returns null pointer. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 6b2aeab5..c45dd1c4 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -22,6 +22,7 @@ set(SOURCES CBotInstr/CBotExprAlpha.cpp CBotInstr/CBotExprNum.cpp CBotInstr/CBotNew.cpp + CBotInstr/CBotExprNan.cpp ) # Includes