[colobot] 219/377: Refactor public classes list to std::set
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:18 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 dcc29442bd9bb4dc4bf7d74bdff5ba7740e42cba
Author: krzys-h <krzys_h at interia.pl>
Date: Thu Dec 31 16:30:54 2015 +0100
Refactor public classes list to std::set
---
src/CBot/CBotClass.cpp | 60 +++++++++++++-----------------------------------
src/CBot/CBotClass.h | 28 +++++++++++-----------
src/CBot/CBotProgram.cpp | 2 +-
3 files changed, 30 insertions(+), 60 deletions(-)
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index b0b8888..81143fa 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -42,14 +42,14 @@ namespace CBot
{
////////////////////////////////////////////////////////////////////////////////
-CBotClass* CBotClass::m_ExClass = nullptr;
+std::set<CBotClass*> CBotClass::m_publicClasses{};
////////////////////////////////////////////////////////////////////////////////
CBotClass::CBotClass(const std::string& name,
- CBotClass* pPapa,
+ CBotClass* parent,
bool bIntrinsic)
{
- m_pParent = pPapa;
+ m_pParent = parent;
m_name = name;
m_pVar = nullptr;
m_pCalls = nullptr;
@@ -59,28 +59,13 @@ CBotClass::CBotClass(const std::string& name,
m_bIntrinsic= bIntrinsic;
m_nbVar = m_pParent == nullptr ? 0 : m_pParent->m_nbVar;
- m_lockCurrentCount = 0;
- m_lockProg.clear();
-
-
- // is located alone in the list
- if (m_ExClass) m_ExClass->m_ExPrev = this;
- m_ExNext = m_ExClass;
- m_ExPrev = nullptr;
- m_ExClass = this;
-
+ m_publicClasses.insert(this);
}
////////////////////////////////////////////////////////////////////////////////
CBotClass::~CBotClass()
{
- // removes the list of class
- if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext;
- else m_ExClass = m_ExNext;
-
- if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev;
- m_ExPrev = nullptr;
- m_ExNext = nullptr;
+ m_publicClasses.erase(this);
delete m_pVar;
delete m_pCalls;
@@ -96,12 +81,9 @@ CBotClass* CBotClass::Create(const std::string& name,
}
////////////////////////////////////////////////////////////////////////////////
-void CBotClass::Free()
+void CBotClass::ClearPublic()
{
- while ( m_ExClass != nullptr )
- {
- delete m_ExClass;
- }
+ m_publicClasses.clear();
}
////////////////////////////////////////////////////////////////////////////////
@@ -159,9 +141,7 @@ void CBotClass::Unlock()
////////////////////////////////////////////////////////////////////////////////
void CBotClass::FreeLock(CBotProgram* prog)
{
- CBotClass* pClass = m_ExClass;
-
- while (pClass != nullptr)
+ for (CBotClass* pClass : m_publicClasses)
{
if (pClass->m_lockProg.size() > 0 && prog == pClass->m_lockProg[0])
{
@@ -169,8 +149,6 @@ void CBotClass::FreeLock(CBotProgram* prog)
}
pClass->m_lockProg.erase(std::remove(pClass->m_lockProg.begin(), pClass->m_lockProg.end(), prog));
-
- pClass = pClass->m_ExNext;
}
}
@@ -284,12 +262,9 @@ CBotClass* CBotClass::Find(CBotToken* &pToken)
////////////////////////////////////////////////////////////////////////////////
CBotClass* CBotClass::Find(const std::string& name)
{
- CBotClass* p = m_ExClass;
-
- while ( p != nullptr )
+ for (CBotClass* p : m_publicClasses)
{
if ( p->GetName() == name ) return p;
- p = p->m_ExNext;
}
return nullptr;
@@ -394,11 +369,9 @@ bool CBotClass::SaveStaticState(FILE* pf)
if (!WriteWord( pf, CBOTVERSION*2)) return false;
// saves the state of static variables in classes
- CBotClass* p = m_ExClass;
-
- while ( p != nullptr )
+ for (CBotClass* p : m_publicClasses)
{
- if (!WriteWord( pf, 1)) return false;
+ if (!WriteWord( pf, 1 )) return false;
// save the name of the class
if (!WriteString( pf, p->GetName() )) return false;
@@ -407,21 +380,20 @@ bool CBotClass::SaveStaticState(FILE* pf)
{
if ( pv->IsStatic() )
{
- if (!WriteWord( pf, 1)) return false;
+ if (!WriteWord( pf, 1 )) return false;
if (!WriteString( pf, pv->GetName() )) return false;
- if ( !pv->Save0State(pf)) return false; // common header
+ if ( !pv->Save0State(pf) ) return false; // common header
if ( !pv->Save1State(pf) ) return false; // saves as the child class
- if ( !WriteWord( pf, 0)) return false;
+ if ( !WriteWord( pf, 0 ) ) return false;
}
pv = pv->GetNext();
}
- if (!WriteWord( pf, 0)) return false;
- p = p->m_ExNext;
+ if (!WriteWord( pf, 0 )) return false;
}
- if (!WriteWord( pf, 0)) return false;
+ if (!WriteWord( pf, 0 )) return false;
return true;
}
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index 2589cf7..2ed9c28 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -25,6 +25,7 @@
#include <string>
#include <deque>
+#include <set>
namespace CBot
{
@@ -111,11 +112,11 @@ public:
* \brief CBotClass Constructor. Once a class is created, it is known around
* CBot intrinsic mode gives a class that is not managed by pointers.
* \param name
- * \param pParent
+ * \param parent
* \param bIntrinsic
*/
CBotClass(const std::string& name,
- CBotClass* pParent,
+ CBotClass* parent,
bool bIntrinsic = false);
/*!
@@ -318,7 +319,7 @@ public:
/*!
* \brief Free
*/
- static void Free();
+ static void ClearPublic();
/*!
* \brief SaveStaticState
@@ -363,33 +364,30 @@ public:
bool CheckCall(CBotProgram* program, CBotDefParam* pParam, CBotToken*& pToken);
private:
- //! List of classes existing at a given time.
- static CBotClass* m_ExClass;
- //! For this general list.
- CBotClass* m_ExNext;
- //! For this general list.
- CBotClass* m_ExPrev;
+ //! List of all public classes
+ static std::set<CBotClass*> m_publicClasses;
+
//! Parent class.
CBotClass* m_pParent;
//! Name of this class.
std::string m_name;
//! Number of variables in the chain.
int m_nbVar;
- //! Content of the class.
- CBotVar* m_pVar;
//! Intrinsic class.
bool m_bIntrinsic;
- //! List of methods defined in external.
+ //! Linked list of all class fields
+ CBotVar* m_pVar;
+ //! Linked list of all class external calls
CBotCallMethode* m_pCalls;
- //! Compiled list of methods.
+ //! Linked list of all class methods
CBotFunction* m_pMethod;
void (*m_rMaj) ( CBotVar* pThis, void* pUser );
friend class CBotVarClass;
//! How many times the program currently holding the lock called Lock()
- int m_lockCurrentCount;
+ int m_lockCurrentCount = 0;
//! Programs waiting for lock
- std::deque<CBotProgram*> m_lockProg;
+ std::deque<CBotProgram*> m_lockProg{};
};
} // namespace CBot
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 93093f2..81116b2 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -406,7 +406,7 @@ void CBotProgram::Free()
{
CBotToken::ClearDefineNum();
m_externalCalls->Clear();
- CBotClass::Free();
+ CBotClass::ClearPublic();
}
CBotExternalCallList* CBotProgram::GetExternalCalls()
--
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