Moving CBotVarClass class in its own header and source files.
parent
bd20f6303c
commit
c624d65649
|
@ -373,65 +373,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
// class management class instances
|
||||
class CBotVarClass : public CBotVar
|
||||
{
|
||||
private:
|
||||
static
|
||||
CBotVarClass* m_ExClass; // list of existing instances at some point
|
||||
CBotVarClass* m_ExNext; // for this general list
|
||||
CBotVarClass* m_ExPrev; // for this general list
|
||||
|
||||
private:
|
||||
CBotClass* m_pClass; // the class definition
|
||||
CBotVarClass* m_pParent; // the instance of a parent class
|
||||
CBotVar* m_pVar; // contents
|
||||
friend class CBotVar; // my daddy is a buddy WHAT? :D(\TODO mon papa est un copain )
|
||||
friend class CBotVarPointer; // and also the pointer
|
||||
int m_CptUse; // counter usage
|
||||
long m_ItemIdent; // identifier (unique) of an instance
|
||||
bool m_bConstructor; // set if a constructor has been called
|
||||
|
||||
public:
|
||||
CBotVarClass( const CBotToken* name, const CBotTypResult& type );
|
||||
// CBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent );
|
||||
~CBotVarClass();
|
||||
// void InitCBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent );
|
||||
|
||||
void Copy(CBotVar* pSrc, bool bName=true) override;
|
||||
void SetClass(CBotClass* pClass) override; //, int &nIdent);
|
||||
CBotClass* GetClass() override;
|
||||
CBotVar* GetItem(const char* name) override; // return an element of a class according to its name (*)
|
||||
CBotVar* GetItemRef(int nIdent) override;
|
||||
|
||||
CBotVar* GetItem(int n, bool bExtend) override;
|
||||
CBotVar* GetItemList() override;
|
||||
|
||||
CBotString GetValString() override;
|
||||
|
||||
bool Save1State(FILE* pf) override;
|
||||
void Maj(void* pUser, bool bContinue) override;
|
||||
|
||||
void IncrementUse(); // a reference to incrementation
|
||||
void DecrementUse(); // a reference to decrementation
|
||||
|
||||
CBotVarClass*
|
||||
GetPointer() override;
|
||||
void SetItemList(CBotVar* pVar);
|
||||
|
||||
void SetIdent(long n) override;
|
||||
|
||||
static CBotVarClass* Find(long id);
|
||||
|
||||
|
||||
// CBotVar* GetMyThis();
|
||||
|
||||
bool Eq(CBotVar* left, CBotVar* right) override;
|
||||
bool Ne(CBotVar* left, CBotVar* right) override;
|
||||
|
||||
void ConstructorSet() override;
|
||||
};
|
||||
|
||||
extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars);
|
||||
|
||||
extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 );
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "CBotUtils.h"
|
||||
|
||||
#include "CBotVar/CBotVarClass.h"
|
||||
|
||||
// Local include
|
||||
|
||||
// Global include
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "CBotClass.h"
|
||||
|
||||
#include "CBotVar/CBotVarPointer.h"
|
||||
#include "CBotVar/CBotVarClass.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "CBotStack.h"
|
||||
#include "CBotClass.h"
|
||||
|
||||
#include "CBotVar/CBotVarClass.h"
|
||||
|
||||
// Local include
|
||||
|
||||
// Global include
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "CBotInstr/CBotFunction.h"
|
||||
|
||||
#include "CBotVar/CBotVarPointer.h"
|
||||
#include "CBotVar/CBotVarClass.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "CBotVar/CBotVarArray.h"
|
||||
#include "CBotVar/CBotVarPointer.h"
|
||||
#include "CBotVar/CBotVarClass.h"
|
||||
|
||||
#include "CBotDefines.h"
|
||||
#include "CBotClass.h"
|
||||
|
@ -117,97 +118,6 @@ CBotVarBoolean::CBotVarBoolean( const CBotToken* name )
|
|||
m_val = 0;
|
||||
}
|
||||
|
||||
CBotVarClass* CBotVarClass::m_ExClass = nullptr;
|
||||
|
||||
CBotVarClass::CBotVarClass( const CBotToken* name, const CBotTypResult& type)
|
||||
{
|
||||
/*
|
||||
// int nIdent = 0;
|
||||
InitCBotVarClass( name, type ) //, nIdent );
|
||||
}
|
||||
|
||||
CBotVarClass::CBotVarClass( const CBotToken* name, CBotTypResult& type) //, int &nIdent )
|
||||
{
|
||||
InitCBotVarClass( name, type ); //, nIdent );
|
||||
}
|
||||
|
||||
void CBotVarClass::InitCBotVarClass( const CBotToken* name, CBotTypResult& type ) //, int &nIdent )
|
||||
{*/
|
||||
if ( !type.Eq(CBotTypClass) &&
|
||||
!type.Eq(CBotTypIntrinsic) && // by convenience there accepts these types
|
||||
!type.Eq(CBotTypPointer) &&
|
||||
!type.Eq(CBotTypArrayPointer) &&
|
||||
!type.Eq(CBotTypArrayBody)) assert(0);
|
||||
|
||||
m_token = new CBotToken(name);
|
||||
m_next = nullptr;
|
||||
m_pMyThis = nullptr;
|
||||
m_pUserPtr = OBJECTCREATED;//nullptr;
|
||||
m_InitExpr = nullptr;
|
||||
m_LimExpr = nullptr;
|
||||
m_pVar = nullptr;
|
||||
m_type = type;
|
||||
if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody );
|
||||
else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass );
|
||||
// officel type for this object
|
||||
|
||||
m_pClass = nullptr;
|
||||
m_pParent = nullptr;
|
||||
m_binit = InitType::UNDEF;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_bConstructor = false;
|
||||
m_CptUse = 0;
|
||||
m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum();
|
||||
|
||||
// se place tout seul dans la liste
|
||||
// TODO stands alone in the list (stands only in a list)
|
||||
if (m_ExClass) m_ExClass->m_ExPrev = this;
|
||||
m_ExNext = m_ExClass;
|
||||
m_ExPrev = nullptr;
|
||||
m_ExClass = this;
|
||||
|
||||
CBotClass* pClass = type.GetClass();
|
||||
CBotClass* pClass2 = pClass->GetParent();
|
||||
if ( pClass2 != nullptr )
|
||||
{
|
||||
// also creates an instance of the parent class
|
||||
m_pParent = new CBotVarClass(name, CBotTypResult(type.GetType(),pClass2) ); //, nIdent);
|
||||
}
|
||||
|
||||
SetClass( pClass ); //, nIdent );
|
||||
|
||||
}
|
||||
|
||||
CBotVarClass::~CBotVarClass( )
|
||||
{
|
||||
if ( m_CptUse != 0 )
|
||||
assert(0);
|
||||
|
||||
if ( m_pParent ) delete m_pParent;
|
||||
m_pParent = nullptr;
|
||||
|
||||
// frees the indirect object if necessary
|
||||
// if ( m_Indirect != nullptr )
|
||||
// m_Indirect->DecrementUse();
|
||||
|
||||
// removes the class list
|
||||
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;
|
||||
|
||||
delete m_pVar;
|
||||
}
|
||||
|
||||
void CBotVarClass::ConstructorSet()
|
||||
{
|
||||
m_bConstructor = true;
|
||||
}
|
||||
|
||||
|
||||
CBotVar::~CBotVar( )
|
||||
{
|
||||
delete m_token;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
// Modules inlcude
|
||||
#include "CBotVarArray.h"
|
||||
#include "CBotVarClass.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* 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 "CBotVarClass.h"
|
||||
|
||||
#include "CBotClass.h"
|
||||
|
||||
// Local include
|
||||
|
||||
// Global include
|
||||
#include <cassert>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotVarClass* CBotVarClass::m_ExClass = nullptr;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotVarClass::CBotVarClass( const CBotToken* name, const CBotTypResult& type)
|
||||
{
|
||||
if ( !type.Eq(CBotTypClass) &&
|
||||
!type.Eq(CBotTypIntrinsic) && // by convenience there accepts these types
|
||||
!type.Eq(CBotTypPointer) &&
|
||||
!type.Eq(CBotTypArrayPointer) &&
|
||||
!type.Eq(CBotTypArrayBody)) assert(0);
|
||||
|
||||
m_token = new CBotToken(name);
|
||||
m_next = nullptr;
|
||||
m_pMyThis = nullptr;
|
||||
m_pUserPtr = OBJECTCREATED;//nullptr;
|
||||
m_InitExpr = nullptr;
|
||||
m_LimExpr = nullptr;
|
||||
m_pVar = nullptr;
|
||||
m_type = type;
|
||||
if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody );
|
||||
else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass );
|
||||
// officel type for this object
|
||||
|
||||
m_pClass = nullptr;
|
||||
m_pParent = nullptr;
|
||||
m_binit = InitType::UNDEF;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_bConstructor = false;
|
||||
m_CptUse = 0;
|
||||
m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum();
|
||||
|
||||
// se place tout seul dans la liste
|
||||
// TODO stands alone in the list (stands only in a list)
|
||||
if (m_ExClass) m_ExClass->m_ExPrev = this;
|
||||
m_ExNext = m_ExClass;
|
||||
m_ExPrev = nullptr;
|
||||
m_ExClass = this;
|
||||
|
||||
CBotClass* pClass = type.GetClass();
|
||||
CBotClass* pClass2 = pClass->GetParent();
|
||||
if ( pClass2 != nullptr )
|
||||
{
|
||||
// also creates an instance of the parent class
|
||||
m_pParent = new CBotVarClass(name, CBotTypResult(type.GetType(),pClass2) ); //, nIdent);
|
||||
}
|
||||
|
||||
SetClass( pClass ); //, nIdent );
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotVarClass::~CBotVarClass( )
|
||||
{
|
||||
if ( m_CptUse != 0 )
|
||||
assert(0);
|
||||
|
||||
if ( m_pParent ) delete m_pParent;
|
||||
m_pParent = nullptr;
|
||||
|
||||
// frees the indirect object if necessary
|
||||
// if ( m_Indirect != nullptr )
|
||||
// m_Indirect->DecrementUse();
|
||||
|
||||
// removes the class list
|
||||
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;
|
||||
|
||||
delete m_pVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotVarClass::ConstructorSet()
|
||||
{
|
||||
m_bConstructor = true;
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
/*
|
||||
* 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 CBotVarClass class Class management class instances.
|
||||
*/
|
||||
class CBotVarClass : public CBotVar
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief CBotVarClass
|
||||
* \param name
|
||||
* \param type
|
||||
*/
|
||||
CBotVarClass( const CBotToken* name, const CBotTypResult& type );
|
||||
|
||||
/*!
|
||||
* \brief ~CBotVarClass
|
||||
*/
|
||||
~CBotVarClass();
|
||||
|
||||
/*!
|
||||
* \brief Copy
|
||||
* \param pSrc
|
||||
* \param bName
|
||||
*/
|
||||
void Copy(CBotVar* pSrc, bool bName=true) override;
|
||||
|
||||
/*!
|
||||
* \brief SetClass
|
||||
* \param pClass
|
||||
*/
|
||||
void SetClass(CBotClass* pClass) override;
|
||||
|
||||
/*!
|
||||
* \brief GetClass
|
||||
* \return
|
||||
*/
|
||||
CBotClass* GetClass() override;
|
||||
|
||||
/*!
|
||||
* \brief GetItem Return an element of a class according to its name (*).
|
||||
* \param name
|
||||
* \return
|
||||
*/
|
||||
CBotVar* GetItem(const char* name) override;
|
||||
|
||||
/*!
|
||||
* \brief GetItemRef
|
||||
* \param nIdent
|
||||
* \return
|
||||
*/
|
||||
CBotVar* GetItemRef(int nIdent) override;
|
||||
|
||||
/*!
|
||||
* \brief GetItem
|
||||
* \param n
|
||||
* \param bExtend
|
||||
* \return
|
||||
*/
|
||||
CBotVar* GetItem(int n, bool bExtend) override;
|
||||
|
||||
/*!
|
||||
* \brief GetItemList
|
||||
* \return
|
||||
*/
|
||||
CBotVar* GetItemList() override;
|
||||
|
||||
/*!
|
||||
* \brief GetValString
|
||||
* \return
|
||||
*/
|
||||
CBotString GetValString() override;
|
||||
|
||||
/*!
|
||||
* \brief Save1State
|
||||
* \param pf
|
||||
* \return
|
||||
*/
|
||||
bool Save1State(FILE* pf) override;
|
||||
|
||||
/*!
|
||||
* \brief Maj
|
||||
* \param pUser
|
||||
* \param bContinue
|
||||
*/
|
||||
void Maj(void* pUser, bool bContinue) override;
|
||||
|
||||
/*!
|
||||
* \brief IncrementUse A reference to incrementation.
|
||||
*/
|
||||
void IncrementUse();
|
||||
|
||||
/*!
|
||||
* \brief DecrementUse A reference to decrementation.
|
||||
*/
|
||||
void DecrementUse();
|
||||
|
||||
/*!
|
||||
* \brief GetPointer
|
||||
* \return
|
||||
*/
|
||||
CBotVarClass* GetPointer() override;
|
||||
|
||||
/*!
|
||||
* \brief SetItemList
|
||||
* \param pVar
|
||||
*/
|
||||
void SetItemList(CBotVar* pVar);
|
||||
|
||||
/*!
|
||||
* \brief SetIdent
|
||||
* \param n
|
||||
*/
|
||||
void SetIdent(long n) override;
|
||||
|
||||
/*!
|
||||
* \brief Find
|
||||
* \param id
|
||||
* \return
|
||||
*/
|
||||
static CBotVarClass* Find(long id);
|
||||
|
||||
/*!
|
||||
* \brief Eq
|
||||
* \param left
|
||||
* \param right
|
||||
* \return
|
||||
*/
|
||||
bool Eq(CBotVar* left, CBotVar* right) override;
|
||||
|
||||
/*!
|
||||
* \brief Ne
|
||||
* \param left
|
||||
* \param right
|
||||
* \return
|
||||
*/
|
||||
bool Ne(CBotVar* left, CBotVar* right) override;
|
||||
|
||||
/*!
|
||||
* \brief ConstructorSet
|
||||
*/
|
||||
void ConstructorSet() override;
|
||||
|
||||
private:
|
||||
//! List of existing instances at some point.
|
||||
static CBotVarClass* m_ExClass;
|
||||
//! For this general list.
|
||||
CBotVarClass* m_ExNext;
|
||||
//! For this general list.
|
||||
CBotVarClass* m_ExPrev;
|
||||
//! The class definition.
|
||||
CBotClass* m_pClass;
|
||||
//! The instance of a parent class.
|
||||
CBotVarClass* m_pParent;
|
||||
//! Contents.
|
||||
CBotVar* m_pVar;
|
||||
//! Counter usage.
|
||||
int m_CptUse;
|
||||
//! Identifier (unique) of an instance.
|
||||
long m_ItemIdent;
|
||||
//! Set if a constructor has been called.
|
||||
bool m_bConstructor;
|
||||
|
||||
friend class CBotVar;
|
||||
friend class CBotVarPointer;
|
||||
};
|
|
@ -22,7 +22,7 @@
|
|||
#include "CBotToken.h"
|
||||
#include "CBot.h"
|
||||
#include "CBotClass.h"
|
||||
|
||||
#include "CBotVarClass.h"
|
||||
// Local include
|
||||
|
||||
// Global include
|
||||
|
|
|
@ -57,6 +57,7 @@ set(SOURCES
|
|||
CBotInstr/CBotFunction.cpp
|
||||
CBotVar/CBotVarArray.cpp
|
||||
CBotVar/CBotVarPointer.cpp
|
||||
CBotVar/CBotVarClass.cpp
|
||||
)
|
||||
|
||||
# Includes
|
||||
|
|
Loading…
Reference in New Issue