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

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:03 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 63ab9d730149bcd12e586321382e5437cd3d5c47
Author: Grunaka <dev at romainbreton.fr>
Date:   Sun Nov 15 17:04:27 2015 +0100

    Moving CBotVarArray class in its own header and source files.
---
 src/CBot/CBot.h                      |  33 ---------
 src/CBot/CBotDefines.h               |  28 +++++++
 src/CBot/CBotInstr/CBotExprVar.cpp   |   2 +
 src/CBot/CBotInstr/CBotIndexExpr.cpp |   2 +
 src/CBot/CBotInstr/CBotInstArray.cpp |   2 +
 src/CBot/CBotInstr/CBotLeftExpr.cpp  |   2 +
 src/CBot/CBotVar.cpp                 | 115 +---------------------------
 src/CBot/CBotVar/CBotVarArray.cpp    | 140 +++++++++++++++++++++++++++++++++++
 src/CBot/CBotVar/CBotVarArray.h      | 102 +++++++++++++++++++++++++
 src/CBot/CMakeLists.txt              |   1 +
 10 files changed, 283 insertions(+), 144 deletions(-)

diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 5e944d1..c5fc9de 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -468,39 +468,6 @@ public:
     bool        Ne(CBotVar* left, CBotVar* right) override;
 };
 
-
-// classe pour les tableaux
-
-#define    MAXARRAYSIZE    9999
-
-class CBotVarArray : public CBotVar
-{
-private:
-    CBotVarClass*
-                m_pInstance;                // instance manager of table
-
-    friend class CBotVar;                    // my daddy is a buddy
-
-public:
-                CBotVarArray( const CBotToken* name, CBotTypResult& type );
-                ~CBotVarArray();
-
-    void        SetPointer(CBotVar* p) override;
-    CBotVarClass*
-                GetPointer() override;
-
-    void        Copy(CBotVar* pSrc, bool bName=true) override;
-    CBotVar*    GetItem(int n, bool bGrow=false) override;    // makes an element according to its numeric index
-                                                // enlarged the table if necessary if bExtend
-//    CBotVar*    GetItem(const char* name);        // makes a element by  literal index
-    CBotVar*    GetItemList() override;                    // gives the first item in the list
-
-    CBotString    GetValString() override;                    // gets the contents of the array into a string
-
-    bool        Save1State(FILE* pf) override;
-};
-
-
 extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars);
 
 extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 );
diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h
new file mode 100644
index 0000000..2c6e34d
--- /dev/null
+++ b/src/CBot/CBotDefines.h
@@ -0,0 +1,28 @@
+/*
+ * 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
+
+// Local include
+
+// Global include
+
+#define    MAXARRAYSIZE    9999
diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp
index 0e531fa..344ce85 100644
--- a/src/CBot/CBotInstr/CBotExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotExprVar.cpp
@@ -26,6 +26,8 @@
 
 #include "CBotStack.h"
 
+#include "CBotVar/CBotVarArray.h"
+
 // Local include
 
 // Global include
diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp
index f4882c0..2bc37f1 100644
--- a/src/CBot/CBotInstr/CBotIndexExpr.cpp
+++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp
@@ -22,6 +22,8 @@
 
 #include "CBotStack.h"
 
+#include "CBotVar/CBotVarArray.h"
+
 // Local include
 
 // Global include
diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp
index e1327a5..4bf2fd1 100644
--- a/src/CBot/CBotInstr/CBotInstArray.cpp
+++ b/src/CBot/CBotInstr/CBotInstArray.cpp
@@ -27,6 +27,8 @@
 
 #include "CBotStack.h"
 
+#include "CBotDefines.h"
+
 // Local include
 
 // Global include
diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp
index 84c7b73..0785dd2 100644
--- a/src/CBot/CBotInstr/CBotLeftExpr.cpp
+++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp
@@ -25,6 +25,8 @@
 
 #include "CBotStack.h"
 
+#include "CBotVar/CBotVarArray.h"
+
 // Local include
 
 // Global include
diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp
index 75e26e6..490af3f 100644
--- a/src/CBot/CBotVar.cpp
+++ b/src/CBot/CBotVar.cpp
@@ -27,6 +27,10 @@
 
 #include "CBotStack.h"
 
+#include "CBotVar/CBotVarArray.h"
+
+#include "CBotDefines.h"
+
 #include <cassert>
 #include <cmath>
 #include <cstdio>
@@ -1775,117 +1779,6 @@ bool CBotVarClass::Ne(CBotVar* left, CBotVar* right)
 }
 
 /////////////////////////////////////////////////////////////////////////////
-// management of arrays
-
-CBotVarArray::CBotVarArray(const CBotToken* name, CBotTypResult& type )
-{
-    if ( !type.Eq(CBotTypArrayPointer) &&
-         !type.Eq(CBotTypArrayBody)) assert(0);
-
-    m_token        = new CBotToken(name);
-    m_next        = nullptr;
-    m_pMyThis    = nullptr;
-    m_pUserPtr    = nullptr;
-
-    m_type        = type;
-    m_type.SetType(CBotTypArrayPointer);
-    m_binit        = CBotVar::InitType::UNDEF;
-
-    m_pInstance    = nullptr;                        // the list of the array elements
-}
-
-CBotVarArray::~CBotVarArray()
-{
-    if ( m_pInstance != nullptr ) m_pInstance->DecrementUse();    // the lowest reference
-}
-
-// copy a variable into another
-void CBotVarArray::Copy(CBotVar* pSrc, bool bName)
-{
-    if ( pSrc->GetType() != CBotTypArrayPointer )
-        assert(0);
-
-    CBotVarArray*    p = static_cast<CBotVarArray*>(pSrc);
-
-    if ( bName) *m_token    = *p->m_token;
-    m_type        = p->m_type;
-    m_pInstance = p->GetPointer();
-
-    if ( m_pInstance != nullptr )
-         m_pInstance->IncrementUse();            // a reference increase
-
-    m_binit        = p->m_binit;
-//-    m_bStatic    = p->m_bStatic;
-    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 CBotVarArray::SetPointer(CBotVar* pVarClass)
-{
-    m_binit = CBotVar::InitType::DEF;         // init, even on a null pointer
-
-    if ( m_pInstance == pVarClass) return;    // Special, not decrement and reincrement
-                                            // because the decrement can destroy the object
-
-    if ( pVarClass != nullptr )
-    {
-        if ( pVarClass->GetType() == CBotTypArrayPointer )
-             pVarClass = pVarClass->GetPointer();    // the real pointer to the object
-
-        if ( !pVarClass->m_type.Eq(CBotTypClass) &&
-             !pVarClass->m_type.Eq(CBotTypArrayBody))
-            assert(0);
-
-        (static_cast<CBotVarClass*>(pVarClass))->IncrementUse();            // incement the reference
-    }
-
-    if ( m_pInstance != nullptr ) m_pInstance->DecrementUse();
-    m_pInstance = static_cast<CBotVarClass*>(pVarClass);
-}
-
-
-CBotVarClass* CBotVarArray::GetPointer()
-{
-    if ( m_pInstance == nullptr ) return nullptr;
-    return m_pInstance->GetPointer();
-}
-
-CBotVar* CBotVarArray::GetItem(int n, bool bExtend)
-{
-    if ( m_pInstance == nullptr )
-    {
-        if ( !bExtend ) return nullptr;
-        // creates an instance of the table
-
-        CBotVarClass* instance = new CBotVarClass(nullptr, m_type);
-        SetPointer( instance );
-    }
-    return m_pInstance->GetItem(n, bExtend);
-}
-
-CBotVar* CBotVarArray::GetItemList()
-{
-    if ( m_pInstance == nullptr) return nullptr;
-    return m_pInstance->GetItemList();
-}
-
-CBotString CBotVarArray::GetValString()
-{
-    if ( m_pInstance == nullptr ) return ( CBotString( "Null pointer" ) ) ;
-    return m_pInstance->GetValString();
-}
-
-bool CBotVarArray::Save1State(FILE* pf)
-{
-    if ( !WriteType(pf, m_type) ) return false;
-    return SaveVar(pf, m_pInstance);                        // saves the instance that manages the table
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
 // gestion des pointeurs à une instance donnée
 // TODO management of pointers to a given instance
 
diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp
new file mode 100644
index 0000000..35f55a5
--- /dev/null
+++ b/src/CBot/CBotVar/CBotVarArray.cpp
@@ -0,0 +1,140 @@
+/*
+ * 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 "CBotVarArray.h"
+
+// Local include
+
+// Global include
+#include <cassert>
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVarArray::CBotVarArray(const CBotToken* name, CBotTypResult& type )
+{
+    if ( !type.Eq(CBotTypArrayPointer) &&
+         !type.Eq(CBotTypArrayBody)) assert(0);
+
+    m_token        = new CBotToken(name);
+    m_next        = nullptr;
+    m_pMyThis    = nullptr;
+    m_pUserPtr    = nullptr;
+
+    m_type        = type;
+    m_type.SetType(CBotTypArrayPointer);
+    m_binit        = CBotVar::InitType::UNDEF;
+
+    m_pInstance    = nullptr;                        // the list of the array elements
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVarArray::~CBotVarArray()
+{
+    if ( m_pInstance != nullptr ) m_pInstance->DecrementUse();    // the lowest reference
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotVarArray::Copy(CBotVar* pSrc, bool bName)
+{
+    if ( pSrc->GetType() != CBotTypArrayPointer )
+        assert(0);
+
+    CBotVarArray*    p = static_cast<CBotVarArray*>(pSrc);
+
+    if ( bName) *m_token    = *p->m_token;
+    m_type        = p->m_type;
+    m_pInstance = p->GetPointer();
+
+    if ( m_pInstance != nullptr )
+         m_pInstance->IncrementUse();            // a reference increase
+
+    m_binit        = p->m_binit;
+//-    m_bStatic    = p->m_bStatic;
+    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 CBotVarArray::SetPointer(CBotVar* pVarClass)
+{
+    m_binit = CBotVar::InitType::DEF;         // init, even on a null pointer
+
+    if ( m_pInstance == pVarClass) return;    // Special, not decrement and reincrement
+                                            // because the decrement can destroy the object
+
+    if ( pVarClass != nullptr )
+    {
+        if ( pVarClass->GetType() == CBotTypArrayPointer )
+             pVarClass = pVarClass->GetPointer();    // the real pointer to the object
+
+        if ( !pVarClass->m_type.Eq(CBotTypClass) &&
+             !pVarClass->m_type.Eq(CBotTypArrayBody))
+            assert(0);
+
+        (static_cast<CBotVarClass*>(pVarClass))->IncrementUse();            // incement the reference
+    }
+
+    if ( m_pInstance != nullptr ) m_pInstance->DecrementUse();
+    m_pInstance = static_cast<CBotVarClass*>(pVarClass);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVarClass* CBotVarArray::GetPointer()
+{
+    if ( m_pInstance == nullptr ) return nullptr;
+    return m_pInstance->GetPointer();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVar* CBotVarArray::GetItem(int n, bool bExtend)
+{
+    if ( m_pInstance == nullptr )
+    {
+        if ( !bExtend ) return nullptr;
+        // creates an instance of the table
+
+        CBotVarClass* instance = new CBotVarClass(nullptr, m_type);
+        SetPointer( instance );
+    }
+    return m_pInstance->GetItem(n, bExtend);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVar* CBotVarArray::GetItemList()
+{
+    if ( m_pInstance == nullptr) return nullptr;
+    return m_pInstance->GetItemList();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotString CBotVarArray::GetValString()
+{
+    if ( m_pInstance == nullptr ) return ( CBotString( "Null pointer" ) ) ;
+    return m_pInstance->GetValString();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarArray::Save1State(FILE* pf)
+{
+    if ( !WriteType(pf, m_type) ) return false;
+    return SaveVar(pf, m_pInstance);                        // saves the instance that manages the table
+}
diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h
new file mode 100644
index 0000000..158cdf8
--- /dev/null
+++ b/src/CBot/CBotVar/CBotVarArray.h
@@ -0,0 +1,102 @@
+/*
+ * 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"
+#include "CBotDefines.h"
+
+// Local include
+
+// Global include
+
+
+/*!
+ * \brief The CBotVarArray class Classe pour les tableaux.
+ */
+class CBotVarArray : public CBotVar
+{
+public:
+
+    /*!
+     * \brief CBotVarArray
+     * \param name
+     * \param type
+     */
+    CBotVarArray( const CBotToken* name, CBotTypResult& type );
+
+    /*!
+     * \brief ~CBotVarArray
+     */
+    ~CBotVarArray();
+
+    /*!
+     * \brief SetPointer
+     * \param p
+     */
+    void SetPointer(CBotVar* p) override;
+
+    /*!
+     * \brief GetPointer
+     * \return
+     */
+    CBotVarClass* GetPointer() override;
+
+    /*!
+     * \brief Copy Copy a variable into another.
+     * \param pSrc
+     * \param bName
+     */
+    void Copy(CBotVar* pSrc, bool bName=true) override;
+
+    /*!
+     * \brief GetItem Makes an element according to its numeric index enlarged
+     * the table if necessary if bExtend.
+     * \param n
+     * \param bGrow
+     * \return
+     */
+    CBotVar* GetItem(int n, bool bGrow=false) override;
+
+    /*!
+     * \brief GetItemList Gives the first item in the list.
+     * \return
+     */
+    CBotVar* GetItemList() override;
+
+    /*!
+     * \brief GetValString Gets the contents of the array into a string.
+     * \return
+     */
+    CBotString GetValString() override;
+
+    /*!
+     * \brief Save1State
+     * \param pf
+     * \return
+     */
+    bool Save1State(FILE* pf) override;
+
+private:
+    //! Instance manager of table.
+    CBotVarClass* m_pInstance;
+    //! My daddy is a buddy.
+    friend class CBotVar;
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index bf7deef..5bb6ad7 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -53,6 +53,7 @@ set(SOURCES
     CBotInstr/CBotListArray.cpp
     CBotInstr/CBotInstArray.cpp
     CBotInstr/CBotInt.cpp
+    CBotVar/CBotVarArray.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