CBotVar::ProtectionLevel enum
parent
fa77dd5414
commit
2519825104
|
@ -211,7 +211,7 @@ void CBotClass::FreeLock(CBotProgram* p)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CBotClass::AddItem(std::string name,
|
||||
CBotTypResult type,
|
||||
int mPrivate)
|
||||
CBotVar::ProtectionLevel mPrivate)
|
||||
{
|
||||
CBotClass* pClass = type.GetClass();
|
||||
|
||||
|
@ -589,7 +589,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
|
|||
bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
||||
{
|
||||
bool bStatic = false;
|
||||
int mProtect = PR_PUBLIC;
|
||||
CBotVar::ProtectionLevel mProtect = CBotVar::ProtectionLevel::Public;
|
||||
bool bSynchro = false;
|
||||
|
||||
while (IsOfType(p, ID_SEP)) ;
|
||||
|
@ -600,9 +600,9 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
CBotToken* pBase = p;
|
||||
|
||||
if ( IsOfType(p, ID_STATIC) ) bStatic = true;
|
||||
if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC;
|
||||
if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE;
|
||||
if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT;
|
||||
if ( IsOfType(p, ID_PUBLIC) ) mProtect = CBotVar::ProtectionLevel::Public;
|
||||
if ( IsOfType(p, ID_PRIVATE) ) mProtect = CBotVar::ProtectionLevel::Private;
|
||||
if ( IsOfType(p, ID_PROTECTED) ) mProtect = CBotVar::ProtectionLevel::Protected;
|
||||
if ( IsOfType(p, ID_STATIC) ) bStatic = true;
|
||||
|
||||
// CBotClass* pClass = nullptr;
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
|
||||
// Modules inlcude
|
||||
#include "CBot/CBotDefines.h"
|
||||
|
||||
#include "CBot/CBotTypResult.h"
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
|||
#include <string>
|
||||
|
||||
// Forward declaration
|
||||
class CBotVar;
|
||||
class CBotClass;
|
||||
class CBotCallMethode;
|
||||
class CBotFunction;
|
||||
|
@ -107,7 +106,8 @@ public:
|
|||
* \param mPrivate
|
||||
* \return
|
||||
*/
|
||||
bool AddItem(std::string name, CBotTypResult type, int mPrivate = PR_PUBLIC);
|
||||
bool AddItem(std::string name, CBotTypResult type,
|
||||
CBotVar::ProtectionLevel mPrivate = CBotVar::ProtectionLevel::Public);
|
||||
|
||||
/*!
|
||||
* \brief AddItem Adds an item by passing the pointer to an instance of a
|
||||
|
|
|
@ -19,13 +19,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// Modules inlcude
|
||||
|
||||
// Local include
|
||||
|
||||
// Global include
|
||||
|
||||
|
||||
#define STACKMEM 1 /// \def preserve memory for the execution stack
|
||||
#define MAXSTACK 990 /// \def stack size reserved
|
||||
|
||||
|
@ -33,12 +26,6 @@
|
|||
|
||||
#define MAXARRAYSIZE 9999
|
||||
|
||||
// variable type SetPrivate / IsPrivate
|
||||
#define PR_PUBLIC 0 // public variable
|
||||
#define PR_READ 1 // read only
|
||||
#define PR_PROTECT 2 // protected (inheritance)
|
||||
#define PR_PRIVATE 3 // strictly private
|
||||
|
||||
//! Define the current CBot version
|
||||
#define CBOTVERSION 104
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ CBotExprVar::~CBotExprVar()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat)
|
||||
CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, CBotVar::ProtectionLevel privat)
|
||||
{
|
||||
// CBotToken* pDebut = p;
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "CBot/CBotDefines.h"
|
||||
|
||||
#include "CBot/CBotInstr/CBotInstr.h"
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
@ -54,7 +55,8 @@ public:
|
|||
* \param privat
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int privat=PR_PROTECT);
|
||||
static CBotInstr* Compile(CBotToken*& p, CBotCStack* pStack,
|
||||
CBotVar::ProtectionLevel privat = CBotVar::ProtectionLevel::Protected);
|
||||
|
||||
/*!
|
||||
* \brief CompileMethode
|
||||
|
|
|
@ -67,7 +67,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
inst->m_nIdent = var->GetUniqNum();
|
||||
if (inst->m_nIdent > 0 && inst->m_nIdent < 9000)
|
||||
{
|
||||
if ( var->IsPrivate(PR_READ) &&
|
||||
if ( var->IsPrivate(CBotVar::ProtectionLevel::ReadOnly) &&
|
||||
!pStk->GetBotCall()->m_bCompileClass)
|
||||
{
|
||||
pStk->SetError(CBotErrPrivate, p);
|
||||
|
@ -131,7 +131,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
var = var->GetItem(p->GetString()); // get item correspondent
|
||||
if (var != nullptr)
|
||||
{
|
||||
if ( var->IsPrivate(PR_READ) &&
|
||||
if ( var->IsPrivate(CBotVar::ProtectionLevel::ReadOnly) &&
|
||||
!pStk->GetBotCall()->m_bCompileClass)
|
||||
{
|
||||
pStk->SetError(CBotErrPrivate, pp);
|
||||
|
|
|
@ -102,7 +102,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
// recompile the variable for read-only
|
||||
delete inst;
|
||||
p = pvar;
|
||||
inst = CBotExprVar::Compile(p, pStk, PR_READ);
|
||||
inst = CBotExprVar::Compile(p, pStk, CBotVar::ProtectionLevel::ReadOnly);
|
||||
p = p->GetNext();
|
||||
|
||||
CBotPostIncExpr* i = new CBotPostIncExpr();
|
||||
|
@ -122,7 +122,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
|
||||
if (p->GetType() == TokenTypVar)
|
||||
{
|
||||
if (nullptr != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ)))
|
||||
if (nullptr != (i->m_Instr = CBotExprVar::Compile(p, pStk, CBotVar::ProtectionLevel::ReadOnly)))
|
||||
{
|
||||
if (pStk->GetType() >= CBotTypBoolean)
|
||||
{
|
||||
|
|
|
@ -943,7 +943,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CBotVar::Save0State(FILE* pf)
|
||||
{
|
||||
if (!WriteWord(pf, 100+m_mPrivate))return false; // private variable?
|
||||
if (!WriteWord(pf, 100+static_cast<int>(m_mPrivate)))return false; // private variable?
|
||||
if (!WriteWord(pf, m_bStatic))return false; // static variable?
|
||||
if (!WriteWord(pf, m_type.GetType()))return false; // saves the type (always non-zero)
|
||||
if (!WriteWord(pf, static_cast<unsigned short>(m_binit))) return false; // variable defined?
|
||||
|
@ -1106,7 +1106,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
|||
|
||||
pNew->m_binit = initType; // pNew->SetInit(wi);
|
||||
pNew->SetStatic(st);
|
||||
pNew->SetPrivate(prv-100);
|
||||
pNew->SetPrivate(static_cast<ProtectionLevel>(prv-100));
|
||||
pPrev = pNew;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -58,7 +58,7 @@ CBotVar::CBotVar( )
|
|||
m_binit = InitType::UNDEF;
|
||||
m_ident = 0;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_mPrivate = ProtectionLevel::Public;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -509,7 +509,7 @@ void CBotVar::SetStatic(bool bStatic)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotVar::SetPrivate(int mPrivate)
|
||||
void CBotVar::SetPrivate(ProtectionLevel mPrivate)
|
||||
{
|
||||
m_mPrivate = mPrivate;
|
||||
}
|
||||
|
@ -521,13 +521,13 @@ bool CBotVar::IsStatic()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CBotVar::IsPrivate(int mode)
|
||||
bool CBotVar::IsPrivate(ProtectionLevel mode)
|
||||
{
|
||||
return m_mPrivate >= mode;
|
||||
return static_cast<int>(m_mPrivate) >= static_cast<int>(mode);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CBotVar::GetPrivate()
|
||||
CBotVar::ProtectionLevel CBotVar::GetPrivate()
|
||||
{
|
||||
return m_mPrivate;
|
||||
}
|
||||
|
|
|
@ -219,24 +219,32 @@ public:
|
|||
*/
|
||||
bool IsStatic();
|
||||
|
||||
enum class ProtectionLevel
|
||||
{
|
||||
Public = 0, //!< public variable
|
||||
ReadOnly = 1, //!< read only (can't be set from CBot, only from the engine)
|
||||
Protected = 2, //!< protected (inheritance)
|
||||
Private = 3 //!< private
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief SetPrivate
|
||||
* \param mPrivate
|
||||
*/
|
||||
void SetPrivate(int mPrivate);
|
||||
void SetPrivate(ProtectionLevel mPrivate);
|
||||
|
||||
/*!
|
||||
* \brief IsPrivate
|
||||
* \param mode
|
||||
* \return
|
||||
*/
|
||||
bool IsPrivate(int mode = PR_PROTECT);
|
||||
bool IsPrivate(ProtectionLevel mode = ProtectionLevel::Protected);
|
||||
|
||||
/*!
|
||||
* \brief GetPrivate
|
||||
* \return
|
||||
*/
|
||||
int GetPrivate();
|
||||
ProtectionLevel GetPrivate();
|
||||
|
||||
/*!
|
||||
* \brief ConstructorSet
|
||||
|
@ -590,7 +598,7 @@ protected:
|
|||
//! Static element (in class).
|
||||
bool m_bStatic;
|
||||
//! Element public, protected or private.
|
||||
int m_mPrivate;
|
||||
ProtectionLevel m_mPrivate;
|
||||
//! Expression for the original content.
|
||||
CBotInstr* m_InitExpr;
|
||||
//! List of limits for a table.
|
||||
|
|
|
@ -41,7 +41,7 @@ CBotVarBoolean::CBotVarBoolean( const CBotToken* name )
|
|||
m_type = CBotTypBoolean;
|
||||
m_binit = InitType::UNDEF;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_mPrivate = ProtectionLevel::Public;
|
||||
m_val = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ CBotVarClass::CBotVarClass( const CBotToken* name, const CBotTypResult& type)
|
|||
m_pParent = nullptr;
|
||||
m_binit = InitType::UNDEF;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_mPrivate = ProtectionLevel::Public;
|
||||
m_bConstructor = false;
|
||||
m_CptUse = 0;
|
||||
m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum();
|
||||
|
|
|
@ -43,7 +43,7 @@ CBotVarFloat::CBotVarFloat( const CBotToken* name )
|
|||
m_type = CBotTypFloat;
|
||||
m_binit = InitType::UNDEF;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_mPrivate = ProtectionLevel::Public;
|
||||
|
||||
m_val = 0;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ CBotVarInt::CBotVarInt( const CBotToken* name )
|
|||
m_type = CBotTypInt;
|
||||
m_binit = InitType::UNDEF;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_mPrivate = ProtectionLevel::Public;
|
||||
|
||||
m_val = 0;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ CBotVarString::CBotVarString( const CBotToken* name )
|
|||
m_type = CBotTypString;
|
||||
m_binit = InitType::UNDEF;
|
||||
m_bStatic = false;
|
||||
m_mPrivate = 0;
|
||||
m_mPrivate = ProtectionLevel::Public;
|
||||
|
||||
m_val.clear();
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ void InitFileFunctions()
|
|||
// adds the component ".filename"
|
||||
bc->AddItem("filename", CBotTypString);
|
||||
// adds the component ".handle"
|
||||
bc->AddItem("handle", CBotTypInt, PR_PRIVATE);
|
||||
bc->AddItem("handle", CBotTypInt, CBotVar::ProtectionLevel::Private);
|
||||
|
||||
// define a constructor and a destructor
|
||||
bc->AddFunction("file", rfconstruct, cfconstruct);
|
||||
|
|
|
@ -3183,21 +3183,21 @@ void CScriptFunctions::Init()
|
|||
|
||||
// Adds the class Object.
|
||||
bc = CBotClass::Create("object", nullptr);
|
||||
bc->AddItem("category", CBotTypResult(CBotTypInt), PR_READ);
|
||||
bc->AddItem("position", CBotTypResult(CBotTypClass, "point"), PR_READ);
|
||||
bc->AddItem("orientation", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("pitch", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("roll", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("energyLevel", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("shieldLevel", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("temperature", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("altitude", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("lifeTime", CBotTypResult(CBotTypFloat), PR_READ);
|
||||
bc->AddItem("energyCell", CBotTypResult(CBotTypPointer, "object"), PR_READ);
|
||||
bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), PR_READ);
|
||||
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
|
||||
bc->AddItem("team", CBotTypResult(CBotTypInt), PR_READ);
|
||||
bc->AddItem("velocity", CBotTypResult(CBotTypClass, "point"), PR_READ);
|
||||
bc->AddItem("category", CBotTypResult(CBotTypInt), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("position", CBotTypResult(CBotTypClass, "point"), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("orientation", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("pitch", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("roll", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("energyLevel", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("shieldLevel", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("temperature", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("altitude", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("lifeTime", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("energyCell", CBotTypResult(CBotTypPointer, "object"), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("id", CBotTypResult(CBotTypInt), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("team", CBotTypResult(CBotTypInt), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("velocity", CBotTypResult(CBotTypClass, "point"), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddFunction("busy", rBusy, cBusy);
|
||||
bc->AddFunction("factory", rFactory, cFactory);
|
||||
bc->AddFunction("research", rResearch, cClassOneFloat);
|
||||
|
|
Loading…
Reference in New Issue