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

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:33:59 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 f8778e8c03b9b98b9c012543fdafdc6e18220ef1
Author: Grunaka <dev at romainbreton.fr>
Date:   Wed Nov 11 17:35:09 2015 +0100

    Moving CBotExprNum class in its own header and source files.
---
 src/CBot/CBot.cpp                  | 188 +--------------------------------
 src/CBot/CBot.h                    |  19 ----
 src/CBot/CBotInstr/CBotCase.cpp    |   1 +
 src/CBot/CBotInstr/CBotExprNum.cpp | 210 +++++++++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotExprNum.h   |  78 ++++++++++++++
 src/CBot/CMakeLists.txt            |   1 +
 6 files changed, 291 insertions(+), 206 deletions(-)

diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index 8332a1b..bc3d5c5 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -44,6 +44,7 @@
 #include "CBotInstr/CBotThrow.h"
 #include "CBotInstr/CBotWhile.h"
 #include "CBotInstr/CBotExprAlpha.h"
+#include "CBotInstr/CBotExprNum.h"
 
 // Local include
 
@@ -2686,193 +2687,6 @@ void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
          m_next3->RestoreStateVar(pile, bMain);
 }
 
-//////////////////////////////////////////////////////////////////////////////////////////
-
-// converts a string into integer
-// may be of the form 0xabc123
-
-long GetNumInt(const char* p)
-{
-    long    num = 0;
-    while (*p >= '0' && *p <= '9')
-    {
-        num = num * 10 + *p - '0';
-        p++;
-    }
-    if (*p == 'x' || *p == 'X')
-    {
-        while (*++p != 0)
-        {
-            if (*p >= '0' && *p <= '9')
-            {
-                num = num * 16 + *p - '0';
-                continue;
-            }
-            if (*p >= 'A' && *p <= 'F')
-            {
-                num = num * 16 + *p - 'A' + 10;
-                continue;
-            }
-            if (*p >= 'a' && *p <= 'f')
-            {
-                num = num * 16 + *p - 'a' + 10;
-                continue;
-            }
-            break;
-        }
-    }
-    return num;
-}
-
-// converts a string into a float number
-extern float GetNumFloat(const char* p)
-{
-    double    num = 0;
-    double    div    = 10;
-    bool    bNeg = false;
-
-    if (*p == '-')
-    {
-        bNeg = true;
-        p++;
-    }
-    while (*p >= '0' && *p <= '9')
-    {
-        num = num * 10. + (*p - '0');
-        p++;
-    }
-
-    if (*p == '.')
-    {
-        p++;
-        while (*p >= '0' && *p <= '9')
-        {
-            num = num + (*p - '0') / div;
-            div = div * 10;
-            p++;
-        }
-    }
-
-    int    exp = 0;
-    if (*p == 'e' || *p == 'E')
-    {
-        char neg = 0;
-        p++;
-        if (*p == '-' || *p == '+') neg = *p++;
-
-        while (*p >= '0' && *p <= '9')
-        {
-            exp = exp * 10 + (*p - '0');
-            p++;
-        }
-        if (neg == '-') exp = -exp;
-    }
-
-    while (exp > 0)
-    {
-        num *= 10.0;
-        exp--;
-    }
-
-    while (exp < 0)
-    {
-        num /= 10.0;
-        exp++;
-    }
-
-    if (bNeg) num = -num;
-    return static_cast<float>(num);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-
-//////////////////////////////////////////////////////////////////////////////////////
-// compiles a token representing a number
-CBotExprNum::CBotExprNum()
-{
-    name    = "CBotExprNum";
-}
-
-CBotExprNum::~CBotExprNum()
-{
-}
-
-CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
-{
-    CBotCStack* pStk = pStack->TokenStack();
-
-    CBotExprNum* inst = new CBotExprNum();
-
-    inst->SetToken(p);
-    CBotString    s = p->GetString();
-
-    inst->m_numtype = CBotTypInt;
-    if (p->GetType() == TokenTypDef)
-    {
-        inst->m_valint = p->GetIdKey();
-    }
-    else
-    {
-        if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) ))
-        {
-            inst->m_numtype = CBotTypFloat;
-            inst->m_valfloat = GetNumFloat(s);
-        }
-        else
-        {
-            inst->m_valint = GetNumInt(s);
-        }
-    }
-
-    if (pStk->NextToken(p))
-    {
-        CBotVar*    var = CBotVar::Create(static_cast<CBotToken*>(nullptr), inst->m_numtype);
-        pStk->SetVar(var);
-
-        return pStack->Return(inst, pStk);
-    }
-    delete inst;
-    return pStack->Return(nullptr, pStk);
-}
-
-// execute, returns the corresponding number
-
-bool CBotExprNum::Execute(CBotStack* &pj)
-{
-    CBotStack*    pile = pj->AddStack(this);
-
-    if (pile->IfStep()) return false;
-
-    CBotVar*    var = CBotVar::Create(static_cast<CBotToken*>(nullptr), m_numtype);
-
-    CBotString    nombre ;
-    if (m_token.GetType() == TokenTypDef)
-    {
-        nombre = m_token.GetString();
-    }
-
-    switch (m_numtype)
-    {
-    case CBotTypShort:
-    case CBotTypInt:
-        var->SetValInt(m_valint, nombre);
-        break;
-    case CBotTypFloat:
-        var->SetValFloat(m_valfloat);
-        break;
-    }
-    pile->SetVar(var);                            // place on the stack
-
-    return pj->Return(pile);                        // it's ok
-}
-
-void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain)
-{
-    if (bMain) pj->RestoreStack(this);
-}
-
-
 //////////////////////////////////////////////////////////////////////////////////////
 // compile a token representing true or false
 
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index cc1436a..6fc404a 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -1006,25 +1006,6 @@ public:
     void        RestoreState(CBotStack* &pj, bool bMain) override;
 };
 
-// expression representing a number
-
-class CBotExprNum : public CBotInstr
-{
-private:
-    int            m_numtype;                    // et the type of number
-    long        m_valint;                    // value for an int
-    float        m_valfloat;                    // value for a float
-
-public:
-                CBotExprNum();
-                ~CBotExprNum();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack);
-    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/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp
index ac31103..a2b68c4 100644
--- a/src/CBot/CBotInstr/CBotCase.cpp
+++ b/src/CBot/CBotInstr/CBotCase.cpp
@@ -19,6 +19,7 @@
 
 // Modules inlcude
 #include "CBotCase.h"
+#include "CBotExprNum.h"
 
 // Local include
 
diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp
new file mode 100644
index 0000000..61cf3ea
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotExprNum.cpp
@@ -0,0 +1,210 @@
+/*
+ * 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 "CBotExprNum.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+// converts a string into integer
+// may be of the form 0xabc123
+long GetNumInt(const char* p)
+{
+    long    num = 0;
+    while (*p >= '0' && *p <= '9')
+    {
+        num = num * 10 + *p - '0';
+        p++;
+    }
+    if (*p == 'x' || *p == 'X')
+    {
+        while (*++p != 0)
+        {
+            if (*p >= '0' && *p <= '9')
+            {
+                num = num * 16 + *p - '0';
+                continue;
+            }
+            if (*p >= 'A' && *p <= 'F')
+            {
+                num = num * 16 + *p - 'A' + 10;
+                continue;
+            }
+            if (*p >= 'a' && *p <= 'f')
+            {
+                num = num * 16 + *p - 'a' + 10;
+                continue;
+            }
+            break;
+        }
+    }
+    return num;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// converts a string into a float number
+extern float GetNumFloat(const char* p)
+{
+    double    num = 0;
+    double    div    = 10;
+    bool    bNeg = false;
+
+    if (*p == '-')
+    {
+        bNeg = true;
+        p++;
+    }
+    while (*p >= '0' && *p <= '9')
+    {
+        num = num * 10. + (*p - '0');
+        p++;
+    }
+
+    if (*p == '.')
+    {
+        p++;
+        while (*p >= '0' && *p <= '9')
+        {
+            num = num + (*p - '0') / div;
+            div = div * 10;
+            p++;
+        }
+    }
+
+    int    exp = 0;
+    if (*p == 'e' || *p == 'E')
+    {
+        char neg = 0;
+        p++;
+        if (*p == '-' || *p == '+') neg = *p++;
+
+        while (*p >= '0' && *p <= '9')
+        {
+            exp = exp * 10 + (*p - '0');
+            p++;
+        }
+        if (neg == '-') exp = -exp;
+    }
+
+    while (exp > 0)
+    {
+        num *= 10.0;
+        exp--;
+    }
+
+    while (exp < 0)
+    {
+        num /= 10.0;
+        exp++;
+    }
+
+    if (bNeg) num = -num;
+    return static_cast<float>(num);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotExprNum::CBotExprNum()
+{
+    name    = "CBotExprNum";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotExprNum::~CBotExprNum()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+    CBotCStack* pStk = pStack->TokenStack();
+
+    CBotExprNum* inst = new CBotExprNum();
+
+    inst->SetToken(p);
+    CBotString    s = p->GetString();
+
+    inst->m_numtype = CBotTypInt;
+    if (p->GetType() == TokenTypDef)
+    {
+        inst->m_valint = p->GetIdKey();
+    }
+    else
+    {
+        if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) ))
+        {
+            inst->m_numtype = CBotTypFloat;
+            inst->m_valfloat = GetNumFloat(s);
+        }
+        else
+        {
+            inst->m_valint = GetNumInt(s);
+        }
+    }
+
+    if (pStk->NextToken(p))
+    {
+        CBotVar*    var = CBotVar::Create(static_cast<CBotToken*>(nullptr), inst->m_numtype);
+        pStk->SetVar(var);
+
+        return pStack->Return(inst, pStk);
+    }
+    delete inst;
+    return pStack->Return(nullptr, pStk);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotExprNum::Execute(CBotStack* &pj)
+{
+    CBotStack*    pile = pj->AddStack(this);
+
+    if (pile->IfStep()) return false;
+
+    CBotVar*    var = CBotVar::Create(static_cast<CBotToken*>(nullptr), m_numtype);
+
+    CBotString    nombre ;
+    if (m_token.GetType() == TokenTypDef)
+    {
+        nombre = m_token.GetString();
+    }
+
+    switch (m_numtype)
+    {
+    case CBotTypShort:
+    case CBotTypInt:
+        var->SetValInt(m_valint, nombre);
+        break;
+    case CBotTypFloat:
+        var->SetValFloat(m_valfloat);
+        break;
+    }
+    pile->SetVar(var);                            // place on the stack
+
+    return pj->Return(pile);                        // it's ok
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain)
+{
+    if (bMain) pj->RestoreStack(this);
+}
+
diff --git a/src/CBot/CBotInstr/CBotExprNum.h b/src/CBot/CBotInstr/CBotExprNum.h
new file mode 100644
index 0000000..dc21331
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotExprNum.h
@@ -0,0 +1,78 @@
+/*
+ * 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 CBotExprNum class Expression representing a number.
+ */
+class CBotExprNum : public CBotInstr
+{
+
+public:
+
+    /*!
+     * \brief CBotExprNum
+     */
+    CBotExprNum();
+
+    /*!
+     * \brief ~CBotExprNum
+     */
+    ~CBotExprNum();
+
+    /*!
+     * \brief Compile
+     * \param p
+     * \param pStack
+     * \return
+     */
+    static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+
+    /*!
+     * \brief Execute Execute, returns the corresponding number.
+     * \param pj
+     * \return
+     */
+    bool Execute(CBotStack* &pj) override;
+
+    /*!
+     * \brief RestoreState
+     * \param pj
+     * \param bMain
+     */
+    void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+
+    //! The type of number.
+    int m_numtype;
+    //! Value for an int.
+    long m_valint;
+    //! Value for a float.
+    float m_valfloat;
+
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 60363d3..b36e9b0 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -20,6 +20,7 @@ set(SOURCES
     CBotInstr/CBotCatch.cpp
     CBotInstr/CBotThrow.cpp
     CBotInstr/CBotExprAlpha.cpp
+    CBotInstr/CBotExprNum.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