[colobot] 63/377: Moving CBotCase class in its own header and source files.

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:33:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 6d2fbf3ea4107ccdd6f80e8edae110ce3db189fb
Author: Grunaka <dev at romainbreton.fr>
Date:   Sun Nov 8 19:12:03 2015 +0100

    Moving CBotCase class in its own header and source files.
---
 src/CBot/CBot.h                   | 15 -------
 src/CBot/CBotInstr/CBotCase.cpp   | 88 +++++++++++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotCase.h     | 83 ++++++++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotSwitch.cpp |  1 +
 src/CBot/CBotWhile.cpp            | 70 -------------------------------
 src/CBot/CMakeLists.txt           |  1 +
 6 files changed, 173 insertions(+), 85 deletions(-)

diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 01a874d..45260f2 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -511,21 +511,6 @@ public:
     void        RestoreState(CBotStack* &pj, bool bMain) override;
 };
 
-class CBotCase : public CBotInstr
-{
-private:
-    CBotInstr*    m_Value;            // value to compare
-
-public:
-                CBotCase();
-                ~CBotCase();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack);
-    bool        Execute(CBotStack* &pj) override;
-    void        RestoreState(CBotStack* &pj, bool bMain) override;
-    bool        CompCase(CBotStack* &pj, int val) override;
-};
-
 class CBotCatch : public CBotInstr
 {
 private:
diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp
new file mode 100644
index 0000000..ac31103
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotCase.cpp
@@ -0,0 +1,88 @@
+/*
+ * 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 "CBotCase.h"
+
+// Local include
+
+// Global include
+
+////////////////////////////////////////////////////////////////////////////////
+CBotCase::CBotCase()
+{
+    m_Value     = nullptr;     // nullptr so that delete is not possible further
+    name = "CBotCase";      // debug
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotCase::~CBotCase()
+{
+    delete  m_Value;        // frees the value
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+    CBotCase*   inst = new CBotCase();          // creates the object
+    CBotToken*  pp = p;                         // preserves at the ^ token (starting position)
+
+    inst->SetToken(p);
+    if (!IsOfType(p, ID_CASE, ID_DEFAULT)) return nullptr;     // should never happen
+
+    if ( pp->GetType() == ID_CASE )
+    {
+        pp = p;
+        inst->m_Value = CBotExprNum::Compile(p, pStack);
+        if ( inst->m_Value == nullptr )
+        {
+            pStack->SetError( TX_BADNUM, pp );
+            delete inst;
+            return nullptr;
+        }
+    }
+    if ( !IsOfType( p, ID_DOTS ))
+    {
+        pStack->SetError( TX_MISDOTS, p->GetStart() );
+        delete inst;
+        return nullptr;
+    }
+
+    return inst;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotCase::Execute(CBotStack* &pj)
+{
+    return true;                                // the "case" statement does nothing!
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCase::RestoreState(CBotStack* &pj, bool bMain)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotCase::CompCase(CBotStack* &pile, int val)
+{
+    if ( m_Value == nullptr ) return true;         // "default" case
+
+    while (!m_Value->Execute(pile));            // puts the value on the correspondent stack (without interruption)
+    return (pile->GetVal() == val);             // compared with the given value
+}
diff --git a/src/CBot/CBotInstr/CBotCase.h b/src/CBot/CBotInstr/CBotCase.h
new file mode 100644
index 0000000..9ba1b86
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotCase.h
@@ -0,0 +1,83 @@
+/*
+ * 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 CBotCase class Compiles instruction "case" we are bound to the
+ * statement block "switch".
+ */
+class CBotCase : public CBotInstr
+{
+
+public:
+
+    /*!
+     * \brief CBotCase
+     */
+    CBotCase();
+
+    /*!
+     * \brief ~CBotCase
+     */
+    ~CBotCase();
+
+    /*!
+     * \brief Compile
+     * \param p
+     * \param pStack
+     * \return
+     */
+    static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+
+    /*!
+     * \brief Execute Execution of instruction "case".
+     * \param pj
+     * \return
+     */
+    bool Execute(CBotStack* &pj) override;
+
+    /*!
+     * \brief RestoreState
+     * \param pj
+     * \param bMain
+     */
+    void RestoreState(CBotStack* &pj, bool bMain) override;
+
+    /*!
+     * \brief CompCase Routine to find the entry point of "case" corresponding
+     * to the value seen.
+     * \param pj
+     * \param val
+     * \return
+     */
+    bool CompCase(CBotStack* &pj, int val) override;
+
+private:
+    //! Value to compare.
+    CBotInstr*    m_Value;
+};
diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp
index f9510d9..c0c7997 100644
--- a/src/CBot/CBotInstr/CBotSwitch.cpp
+++ b/src/CBot/CBotInstr/CBotSwitch.cpp
@@ -21,6 +21,7 @@
 
 // Modules inlcude
 #include "CBotSwitch.h"
+#include "CBotCase.h"
 
 // Local include
 
diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp
index 3f77dbe..680dd71 100644
--- a/src/CBot/CBotWhile.cpp
+++ b/src/CBot/CBotWhile.cpp
@@ -157,76 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain)
     }
 }
 
-
-///////////////////////////////////////////////////////////////////////////
-// compiles instruction "case"
-// we are bound to the statement block "switch"
-
-CBotCase::CBotCase()
-{
-    m_Value     = nullptr;     // nullptr so that delete is not possible further
-    name = "CBotCase";      // debug
-}
-
-CBotCase::~CBotCase()
-{
-    delete  m_Value;        // frees the value
-}
-
-
-CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
-{
-    CBotCase*   inst = new CBotCase();          // creates the object
-    CBotToken*  pp = p;                         // preserves at the ^ token (starting position)
-
-    inst->SetToken(p);
-    if (!IsOfType(p, ID_CASE, ID_DEFAULT)) return nullptr;     // should never happen
-
-    if ( pp->GetType() == ID_CASE )
-    {
-        pp = p;
-        inst->m_Value = CBotExprNum::Compile(p, pStack);
-        if ( inst->m_Value == nullptr )
-        {
-            pStack->SetError( TX_BADNUM, pp );
-            delete inst;
-            return nullptr;
-        }
-    }
-    if ( !IsOfType( p, ID_DOTS ))
-    {
-        pStack->SetError( TX_MISDOTS, p->GetStart() );
-        delete inst;
-        return nullptr;
-    }
-
-    return inst;
-}
-
-// execution of instruction "case"
-
-bool CBotCase::Execute(CBotStack* &pj)
-{
-    return true;                                // the "case" statement does nothing!
-}
-
-void CBotCase::RestoreState(CBotStack* &pj, bool bMain)
-{
-}
-
-// routine to find the entry point of "case"
-// corresponding to the value seen
-
-bool CBotCase::CompCase(CBotStack* &pile, int val)
-{
-    if ( m_Value == nullptr ) return true;         // "default" case
-
-    while (!m_Value->Execute(pile));            // puts the value on the correspondent stack (without interruption)
-    return (pile->GetVal() == val);             // compared with the given value
-}
-
-///////////////////////////////////////////////////////////////////////////
-
 ///////////////////////////////////////////////////////////////////////////
 // compiles instruction "break" or "continu"
 
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 212a6dc..ac39e66 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -14,6 +14,7 @@ set(SOURCES
     CBotInstr/CBotFor.cpp
     CBotInstr/CBotListExpression.cpp
     CBotInstr/CBotSwitch.cpp
+    CBotInstr/CBotCase.cpp
 )
 
 # Includes

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list