Refactored CBotString and const char* to std::string in CBot engine

A lot of changes, so it needs lots of testing
dev-time-step
krzys-h 2015-12-20 16:19:10 +01:00
parent 87a34ba1ff
commit 9ec61d93e5
64 changed files with 421 additions and 1344 deletions

View File

@ -25,7 +25,6 @@
// Modules inlcude // Modules inlcude
#include "CBot/CBotFileUtils.h" #include "CBot/CBotFileUtils.h"
#include "CBot/CBotString.h"
#include "CBot/CBotClass.h" #include "CBot/CBotClass.h"
#include "CBot/CBotToken.h" #include "CBot/CBotToken.h"
#include "CBot/CBotProgram.h" #include "CBot/CBotProgram.h"

View File

@ -174,7 +174,7 @@ void CBotCStack::SetType(CBotTypResult& type)
CBotVar* CBotCStack::FindVar(CBotToken* &pToken) CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
{ {
CBotCStack* p = this; CBotCStack* p = this;
CBotString name = pToken->GetString(); std::string name = pToken->GetString();
while (p != nullptr) while (p != nullptr)
{ {
@ -332,7 +332,7 @@ void CBotCStack::AddVar(CBotVar* pVar)
bool CBotCStack::CheckVarLocal(CBotToken* &pToken) bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
{ {
CBotCStack* p = this; CBotCStack* p = this;
CBotString name = pToken->GetString(); std::string name = pToken->GetString();
while (p != nullptr) while (p != nullptr)
{ {
@ -373,7 +373,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
{ {
CBotString name = pToken->GetString(); std::string name = pToken->GetString();
if ( CBotCall::CheckCall(name) ) return true; if ( CBotCall::CheckCall(name) ) return true;

View File

@ -27,6 +27,7 @@
// Global include // Global include
class CBotInstr; class CBotInstr;
class CBotDefParam; class CBotDefParam;
class CBotToken;
/*! /*!
* \brief The CBotCStack class Management of the stack of compilation. * \brief The CBotCStack class Management of the stack of compilation.

View File

@ -40,9 +40,9 @@ CBotCall* CBotCall::m_ListCalls = nullptr;
void* CBotCall::m_pUser = nullptr; void* CBotCall::m_pUser = nullptr;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotCall::CBotCall(const char* name, CBotCall::CBotCall(const std::string& name,
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) CBotTypResult rCompile(CBotVar*& pVar, void* pUser))
{ {
m_name = name; m_name = name;
m_rExec = rExec; m_rExec = rExec;
@ -65,9 +65,9 @@ void CBotCall::Free()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotCall::AddFunction(const char* name, bool CBotCall::AddFunction(const std::string& name,
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) CBotTypResult rCompile(CBotVar*& pVar, void* pUser))
{ {
CBotCall* p = m_ListCalls; CBotCall* p = m_ListCalls;
CBotCall* pp = nullptr; CBotCall* pp = nullptr;
@ -102,7 +102,7 @@ CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack*
{ {
nIdent = 0; nIdent = 0;
CBotCall* pt = m_ListCalls; CBotCall* pt = m_ListCalls;
CBotString name = p->GetString(); std::string name = p->GetString();
while ( pt != nullptr ) while ( pt != nullptr )
{ {
@ -136,7 +136,7 @@ void CBotCall::SetPUser(void* pUser)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotCall::CheckCall(const char* name) bool CBotCall::CheckCall(const std::string& name)
{ {
CBotCall* p = m_ListCalls; CBotCall* p = m_ListCalls;
@ -149,7 +149,7 @@ bool CBotCall::CheckCall(const char* name)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotCall::GetName() std::string CBotCall::GetName()
{ {
return m_name; return m_name;
} }
@ -178,7 +178,7 @@ int CBotCall::DoCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack*
if ( token != nullptr ) if ( token != nullptr )
{ {
CBotString name = token->GetString(); std::string name = token->GetString();
while ( pt != nullptr ) while ( pt != nullptr )
{ {
if ( pt->m_name == name ) if ( pt->m_name == name )
@ -260,7 +260,7 @@ bool CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBot
CBotCall* pt = m_ListCalls; CBotCall* pt = m_ListCalls;
{ {
CBotString name = token->GetString(); std::string name = token->GetString();
while ( pt != nullptr ) while ( pt != nullptr )
{ {
if ( pt->m_name == name ) if ( pt->m_name == name )

View File

@ -20,14 +20,18 @@
#pragma once #pragma once
// Modules inlcude // Modules inlcude
#include "CBot/CBotString.h"
// Local include // Local include
// Global include // Global include
#include <string>
// Forward declaration // Forward declaration
class CBotStack; class CBotStack;
class CBotCStack;
class CBotVar;
class CBotTypResult;
class CBotToken;
#define STACKRUN 1 //! \def return execution directly on a suspended routine #define STACKRUN 1 //! \def return execution directly on a suspended routine
@ -44,9 +48,9 @@ public:
* \param rExec * \param rExec
* \param rCompile * \param rCompile
*/ */
CBotCall(const char* name, CBotCall(const std::string& name,
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); CBotTypResult rCompile(CBotVar*& pVar, void* pUser));
/*! /*!
* \brief ~CBotCall * \brief ~CBotCall
@ -60,9 +64,9 @@ public:
* \param rCompile * \param rCompile
* \return * \return
*/ */
static bool AddFunction(const char* name, static bool AddFunction(const std::string& name,
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); CBotTypResult rCompile(CBotVar*& pVar, void* pUser));
/*! /*!
* \brief CompileCall Is acceptable by a call procedure name and given * \brief CompileCall Is acceptable by a call procedure name and given
@ -80,7 +84,7 @@ public:
* \param name * \param name
* \return * \return
*/ */
static bool CheckCall(const char* name); static bool CheckCall(const std::string& name);
/*! /*!
* \brief DoCall * \brief DoCall
@ -117,7 +121,7 @@ public:
* \brief GetName * \brief GetName
* \return * \return
*/ */
CBotString GetName(); std::string GetName();
/*! /*!
* \brief Next * \brief Next
@ -142,7 +146,7 @@ private:
static void* m_pUser; static void* m_pUser;
long m_nFuncIdent; long m_nFuncIdent;
CBotString m_name; std::string m_name;
bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser); bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser);
CBotTypResult (*m_rComp) (CBotVar* &pVar, void* pUser); CBotTypResult (*m_rComp) (CBotVar* &pVar, void* pUser);
CBotCall* m_next; CBotCall* m_next;

View File

@ -32,9 +32,9 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotCallMethode::CBotCallMethode(const char* name, CBotCallMethode::CBotCallMethode(const std::string& name,
bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar))
{ {
m_name = name; m_name = name;
m_rExec = rExec; m_rExec = rExec;
@ -51,7 +51,7 @@ CBotCallMethode::~CBotCallMethode()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotTypResult CBotCallMethode::CompileCall(const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppVar, CBotVar** ppVar,
CBotCStack* pStack, CBotCStack* pStack,
@ -82,7 +82,7 @@ CBotTypResult CBotCallMethode::CompileCall(const char* name,
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotCallMethode::GetName() std::string CBotCallMethode::GetName()
{ {
return m_name; return m_name;
} }
@ -104,10 +104,10 @@ void CBotCallMethode::AddNext(CBotCallMethode* pt)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CBotCallMethode::DoCall(long& nIdent, int CBotCallMethode::DoCall(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppVars, CBotVar** ppVars,
CBotVar* &pResult, CBotVar*& pResult,
CBotStack* pStack, CBotStack* pStack,
CBotToken* pToken) CBotToken* pToken)
{ {

View File

@ -21,7 +21,6 @@
// Modules inlcude // Modules inlcude
#include "CBot/CBotTypResult.h" #include "CBot/CBotTypResult.h"
#include "CBot/CBotString.h"
// Local include // Local include
@ -45,9 +44,9 @@ public:
* \param rExec * \param rExec
* \param rCompile * \param rCompile
*/ */
CBotCallMethode(const char* name, CBotCallMethode(const std::string& name,
bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar));
/*! /*!
* \brief ~CBotCallMethode * \brief ~CBotCallMethode
@ -64,7 +63,7 @@ public:
* \param nIdent * \param nIdent
* \return * \return
*/ */
CBotTypResult CompileCall(const char* name, CBotTypResult CompileCall(const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppVars, CBotVar** ppVars,
CBotCStack* pStack, CBotCStack* pStack,
@ -82,10 +81,10 @@ public:
* \return * \return
*/ */
int DoCall(long& nIdent, int DoCall(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppVars, CBotVar** ppVars,
CBotVar* &pResult, CBotVar*& pResult,
CBotStack* pStack, CBotStack* pStack,
CBotToken* pFunc); CBotToken* pFunc);
@ -93,7 +92,7 @@ public:
* \brief GetName * \brief GetName
* \return * \return
*/ */
CBotString GetName(); std::string GetName();
/*! /*!
* \brief Next * \brief Next
@ -108,7 +107,7 @@ public:
void AddNext(CBotCallMethode* p); void AddNext(CBotCallMethode* p);
private: private:
CBotString m_name; std::string m_name;
bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user);
CBotTypResult (*m_rComp) (CBotVar* pThis, CBotVar* &pVar); CBotTypResult (*m_rComp) (CBotVar* pThis, CBotVar* &pVar);
CBotCallMethode* m_next; CBotCallMethode* m_next;

View File

@ -46,7 +46,7 @@
CBotClass* CBotClass::m_ExClass = nullptr; CBotClass* CBotClass::m_ExClass = nullptr;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotClass::CBotClass(const char* name, CBotClass::CBotClass(const std::string& name,
CBotClass* pPapa, CBotClass* pPapa,
bool bIntrinsic) bool bIntrinsic)
{ {
@ -96,7 +96,7 @@ CBotClass::~CBotClass()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotClass* CBotClass::Create(const char* name, CBotClass* CBotClass::Create(const std::string& name,
CBotClass* parent, CBotClass* parent,
bool intrinsic) bool intrinsic)
{ {
@ -209,11 +209,11 @@ void CBotClass::FreeLock(CBotProgram* p)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotClass::AddItem(CBotString name, bool CBotClass::AddItem(std::string name,
CBotTypResult type, CBotTypResult type,
int mPrivate) int mPrivate)
{ {
CBotToken token(name, CBotString()); CBotToken token(name, std::string());
CBotClass* pClass = type.GetClass(); CBotClass* pClass = type.GetClass();
CBotVar* pVar = CBotVar::Create( name, type ); CBotVar* pVar = CBotVar::Create( name, type );
@ -255,7 +255,7 @@ void CBotClass::AddNext(CBotClass* pClass)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotClass::GetName() std::string CBotClass::GetName()
{ {
return m_name; return m_name;
} }
@ -286,7 +286,7 @@ CBotVar* CBotClass::GetVar()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotClass::GetItem(const char* name) CBotVar* CBotClass::GetItem(const std::string& name)
{ {
CBotVar* p = m_pVar; CBotVar* p = m_pVar;
@ -326,7 +326,7 @@ CBotClass* CBotClass::Find(CBotToken* &pToken)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotClass* CBotClass::Find(const char* name) CBotClass* CBotClass::Find(const std::string& name)
{ {
CBotClass* p = m_ExClass; CBotClass* p = m_ExClass;
@ -340,9 +340,9 @@ CBotClass* CBotClass::Find(const char* name)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotClass::AddFunction(const char* name, bool CBotClass::AddFunction(const std::string& name,
bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar))
{ {
// stores pointers to the two functions // stores pointers to the two functions
CBotCallMethode* p = m_pCalls; CBotCallMethode* p = m_pCalls;
@ -377,7 +377,7 @@ bool CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotClass::CompileMethode(const char* name, CBotTypResult CBotClass::CompileMethode(const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppParams, CBotVar** ppParams,
CBotCStack* pStack, CBotCStack* pStack,
@ -400,11 +400,11 @@ CBotTypResult CBotClass::CompileMethode(const char* name,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotClass::ExecuteMethode(long& nIdent, bool CBotClass::ExecuteMethode(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppParams, CBotVar** ppParams,
CBotVar* &pResult, CBotVar*& pResult,
CBotStack* &pStack, CBotStack*& pStack,
CBotToken* pToken) CBotToken* pToken)
{ {
int ret = m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken); int ret = m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken);
@ -424,10 +424,10 @@ bool CBotClass::ExecuteMethode(long& nIdent,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotClass::RestoreMethode(long& nIdent, void CBotClass::RestoreMethode(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppParams, CBotVar** ppParams,
CBotStack* &pStack) CBotStack*& pStack)
{ {
m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this); m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this);
} }
@ -472,7 +472,7 @@ bool CBotClass::SaveStaticState(FILE* pf)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotClass::RestoreStaticState(FILE* pf) bool CBotClass::RestoreStaticState(FILE* pf)
{ {
CBotString ClassName, VarName; std::string ClassName, VarName;
CBotClass* pClass; CBotClass* pClass;
unsigned short w; unsigned short w;
@ -511,7 +511,7 @@ bool CBotClass::RestoreStaticState(FILE* pf)
bool CBotClass::CheckCall(CBotToken* &pToken, bool CBotClass::CheckCall(CBotToken* &pToken,
CBotDefParam* pParam) CBotDefParam* pParam)
{ {
CBotString name = pToken->GetString(); std::string name = pToken->GetString();
if ( CBotCall::CheckCall(name) ) return true; if ( CBotCall::CheckCall(name) ) return true;
@ -541,7 +541,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
if ( !IsOfType(p, ID_CLASS) ) return nullptr; if ( !IsOfType(p, ID_CLASS) ) return nullptr;
CBotString name = p->GetString(); std::string name = p->GetString();
CBotClass* pOld = CBotClass::Find(name); CBotClass* pOld = CBotClass::Find(name);
if ( pOld != nullptr && pOld->m_IsDef ) if ( pOld != nullptr && pOld->m_IsDef )
@ -556,7 +556,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
CBotClass* pPapa = nullptr; CBotClass* pPapa = nullptr;
if ( IsOfType( p, ID_EXTENDS ) ) if ( IsOfType( p, ID_EXTENDS ) )
{ {
CBotString name = p->GetString(); std::string name = p->GetString();
pPapa = CBotClass::Find(name); pPapa = CBotClass::Find(name);
if (!IsOfType(p, TokenTypVar) || pPapa == nullptr ) if (!IsOfType(p, TokenTypVar) || pPapa == nullptr )
@ -680,7 +680,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
CBotCStack* pile = pStack->TokenStack(nullptr, true); CBotCStack* pile = pStack->TokenStack(nullptr, true);
// make "this" known // make "this" known
CBotToken TokenThis(CBotString("this"), CBotString()); CBotToken TokenThis(std::string("this"), std::string());
CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) ); CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) );
pThis->SetUniqNum(-2); pThis->SetUniqNum(-2);
pile->AddVar(pThis); pile->AddVar(pThis);
@ -688,7 +688,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
if ( m_pParent ) if ( m_pParent )
{ {
// makes "super" known // makes "super" known
CBotToken TokenSuper(CBotString("super"), CBotString()); CBotToken TokenSuper(std::string("super"), std::string());
CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) ); CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) );
pThis->SetUniqNum(-3); pThis->SetUniqNum(-3);
pile->AddVar(pThis); pile->AddVar(pThis);
@ -796,7 +796,7 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack)
if ( !IsOfType(p, ID_PUBLIC) ) return nullptr; if ( !IsOfType(p, ID_PUBLIC) ) return nullptr;
if ( !IsOfType(p, ID_CLASS) ) return nullptr; if ( !IsOfType(p, ID_CLASS) ) return nullptr;
CBotString name = p->GetString(); std::string name = p->GetString();
// a name for the class is there? // a name for the class is there?
if (IsOfType(p, TokenTypVar)) if (IsOfType(p, TokenTypVar))
@ -807,7 +807,7 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack)
if ( IsOfType( p, ID_EXTENDS ) ) if ( IsOfType( p, ID_EXTENDS ) )
{ {
// TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h // TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h
CBotString name = p->GetString(); std::string name = p->GetString();
CBotClass* pPapa = CBotClass::Find(name); CBotClass* pPapa = CBotClass::Find(name);
if (!IsOfType(p, TokenTypVar) || pPapa == nullptr) if (!IsOfType(p, TokenTypVar) || pPapa == nullptr)

View File

@ -24,11 +24,10 @@
#include "CBot/CBotTypResult.h" #include "CBot/CBotTypResult.h"
#include "CBot/CBotString.h"
// Local include // Local include
// Global include // Global include
#include <string>
// Forward declaration // Forward declaration
class CBotVar; class CBotVar;
@ -38,6 +37,8 @@ class CBotFunction;
class CBotProgram; class CBotProgram;
class CBotStack; class CBotStack;
class CBotDefParam; class CBotDefParam;
class CBotToken;
class CBotCStack;
/*! /*!
* \brief The CBotClass class Class to define new classes in the language CBOT * \brief The CBotClass class Class to define new classes in the language CBOT
@ -57,9 +58,9 @@ public:
* \param pParent * \param pParent
* \param bIntrinsic * \param bIntrinsic
*/ */
CBotClass( const char* name, CBotClass(const std::string& name,
CBotClass* pParent, CBotClass* pParent,
bool bIntrinsic = false ); bool bIntrinsic = false);
/*! /*!
* \brief CBotClass Destructor. * \brief CBotClass Destructor.
@ -73,7 +74,7 @@ public:
* \param intrinsic * \param intrinsic
* \return * \return
*/ */
static CBotClass* Create(const char* name, static CBotClass* Create(const std::string& name,
CBotClass* parent, CBotClass* parent,
bool intrinsic = false); bool intrinsic = false);
@ -86,9 +87,9 @@ public:
* \param rCompile * \param rCompile
* \return * \return
*/ */
bool AddFunction(const char* name, bool AddFunction(const std::string& name,
bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar));
/*! /*!
* \brief AddUpdateFunc Defines routine to be called to update the elements * \brief AddUpdateFunc Defines routine to be called to update the elements
@ -106,7 +107,7 @@ public:
* \param mPrivate * \param mPrivate
* \return * \return
*/ */
bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC); bool AddItem(std::string name, CBotTypResult type, int mPrivate = PR_PUBLIC);
/*! /*!
* \brief AddItem Adds an item by passing the pointer to an instance of a * \brief AddItem Adds an item by passing the pointer to an instance of a
@ -126,7 +127,7 @@ public:
* \brief GetName Gives the name of the class. * \brief GetName Gives the name of the class.
* \return * \return
*/ */
CBotString GetName(); std::string GetName();
/*! /*!
* \brief GetParent Gives the parent class (or nullptr). * \brief GetParent Gives the parent class (or nullptr).
@ -153,7 +154,7 @@ public:
* \param name * \param name
* \return * \return
*/ */
static CBotClass* Find(const char* name); static CBotClass* Find(const std::string& name);
/*! /*!
* \brief GetVar Return the list of variables. * \brief GetVar Return the list of variables.
@ -165,7 +166,7 @@ public:
* \param name * \param name
* \return * \return
*/ */
CBotVar* GetItem(const char* name); CBotVar* GetItem(const std::string& name);
/*! /*!
* \brief GetItemRef * \brief GetItemRef
@ -184,7 +185,7 @@ public:
* \param nIdent * \param nIdent
* \return * \return
*/ */
CBotTypResult CompileMethode(const char* name, CBotTypResult CompileMethode(const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppParams, CBotVar** ppParams,
CBotCStack* pStack, CBotCStack* pStack,
@ -202,11 +203,11 @@ public:
* \return * \return
*/ */
bool ExecuteMethode(long& nIdent, bool ExecuteMethode(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppParams, CBotVar** ppParams,
CBotVar* &pResult, CBotVar*& pResult,
CBotStack* &pStack, CBotStack*& pStack,
CBotToken* pToken); CBotToken* pToken);
/*! /*!
@ -218,10 +219,10 @@ public:
* \param pStack * \param pStack
*/ */
void RestoreMethode(long& nIdent, void RestoreMethode(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppParams, CBotVar** ppParams,
CBotStack* &pStack); CBotStack*& pStack);
/*! /*!
* \brief Compile Compiles a class declared by the user. * \brief Compile Compiles a class declared by the user.
@ -319,7 +320,7 @@ private:
//! Parent class. //! Parent class.
CBotClass* m_pParent; CBotClass* m_pParent;
//! Name of this class. //! Name of this class.
CBotString m_name; std::string m_name;
//! Number of variables in the chain. //! Number of variables in the chain.
int m_nbVar; int m_nbVar;
//! Content of the class. //! Content of the class.
@ -357,7 +358,7 @@ private:
For example, a routine which calculates the mean of a parameter list For example, a routine which calculates the mean of a parameter list
int cMean(CBotVar* &pVar, CBotString& ClassName) int cMean(CBotVar* &pVar, std::string& ClassName)
{ {
if ( pVar == nullptr ) return 6001; // there is no parameter! if ( pVar == nullptr ) return 6001; // there is no parameter!
while ( pVar != nullptr ) while ( pVar != nullptr )

View File

@ -196,9 +196,9 @@ CBotDefParam* CBotDefParam::GetNext()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotDefParam::GetParamString() std::string CBotDefParam::GetParamString()
{ {
CBotString param; std::string param;
param = m_typename; param = m_typename;
param += ' '; param += ' ';

View File

@ -99,13 +99,13 @@ public:
* \brief GetParamString * \brief GetParamString
* \return * \return
*/ */
CBotString GetParamString(); std::string GetParamString();
private: private:
//! Name of the parameter. //! Name of the parameter.
CBotToken m_token; CBotToken m_token;
//! Type name. //! Type name.
CBotString m_typename; std::string m_typename;
//! Type of paramteter. //! Type of paramteter.
CBotTypResult m_type; CBotTypResult m_type;
//! Next parameter. //! Next parameter.

View File

@ -20,10 +20,9 @@
// Modules inlcude // Modules inlcude
#include "CBot/CBotFileUtils.h" #include "CBot/CBotFileUtils.h"
#include "CBot/CBotString.h"
#include "CBot/CBotClass.h" #include "CBot/CBotClass.h"
#include "CBot/CBotEnums.h" #include "CBot/CBotEnums.h"
#include "CBot/CBotUtils.h"
// Local include // Local include
@ -108,7 +107,7 @@ bool ReadLong(FILE* pf, long& w)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool ReadString(FILE* pf, CBotString& s) bool ReadString(FILE* pf, std::string& s)
{ {
unsigned short w; unsigned short w;
char buf[1000]; char buf[1000];
@ -157,7 +156,7 @@ bool ReadType(FILE* pf, CBotTypResult &type)
if ( type.Eq( CBotTypClass ) ) if ( type.Eq( CBotTypClass ) )
{ {
CBotString s; std::string s;
if ( !ReadString(pf, s) ) return false; if ( !ReadString(pf, s) ) return false;
type = CBotTypResult( w, s ); type = CBotTypResult( w, s );
} }

View File

@ -24,11 +24,11 @@
// Local include // Local include
// Global include // Global include
#include <cstdio> #include <cstdio>
#include <string>
// Forward declaration // Forward declaration
class CBotVar; class CBotVar;
class CBotString;
class CBotTypResult; class CBotTypResult;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -137,7 +137,7 @@ bool ReadFloat(FILE* pf, float& w);
* \param s * \param s
* \return * \return
*/ */
bool ReadString(FILE* pf, CBotString& s); bool ReadString(FILE* pf, std::string& s);
/*! /*!
* \brief WriteType * \brief WriteType

View File

@ -46,7 +46,7 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
if (!IsOfType(p, ID_BREAK, ID_CONTINUE)) return nullptr; // should never happen if (!IsOfType(p, ID_BREAK, ID_CONTINUE)) return nullptr; // should never happen
if ( !ChkLvl(CBotString(), type ) ) if ( !ChkLvl(std::string(), type ) )
{ {
pStack->SetError(TX_BREAK, pp); pStack->SetError(TX_BREAK, pp);
return nullptr; // no object, the error is on the stack return nullptr; // no object, the error is on the stack

View File

@ -70,6 +70,6 @@ public:
private: private:
//! A label if there is //! A label if there is
CBotString m_label; std::string m_label;
}; };

View File

@ -82,7 +82,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
inst = new CBotClassInst(); inst = new CBotClassInst();
/// TODO Need to be revised and fixed after adding unit tests /// TODO Need to be revised and fixed after adding unit tests
CBotToken token(pClass->GetName(), CBotString(), p->GetStart(), p->GetEnd()); CBotToken token(pClass->GetName(), std::string(), p->GetStart(), p->GetEnd());
inst->SetToken(&token); inst->SetToken(&token);
CBotToken* vartoken = p; CBotToken* vartoken = p;
@ -137,7 +137,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
if ( inst->m_hasParams ) if ( inst->m_hasParams )
{ {
// the constructor is there? // the constructor is there?
// CBotString noname; // std::string noname;
CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent); CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent);
delete pStk->TokenStack(); // releases the supplement stack delete pStk->TokenStack(); // releases the supplement stack
int typ = r.GetType(); int typ = r.GetType();
@ -242,7 +242,7 @@ bool CBotClassInst::Execute(CBotStack* &pj)
if ( pile->GetState()==0) if ( pile->GetState()==0)
{ {
CBotString name = m_var->m_token.GetString(); std::string name = m_var->m_token.GetString();
if ( bIntrincic ) if ( bIntrincic )
{ {
pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass )); pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass ));
@ -371,7 +371,7 @@ void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
// creates the variable of type pointer to the object // creates the variable of type pointer to the object
{ {
CBotString name = m_var->m_token.GetString(); std::string name = m_var->m_token.GetString();
pThis = pile->FindVar(name); pThis = pile->FindVar(name);
pThis->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent); // its attribute a unique number pThis->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent); // its attribute a unique number
} }

View File

@ -69,5 +69,5 @@ private:
//! Conditions //! Conditions
CBotInstr* m_Condition; CBotInstr* m_Condition;
//! A label if there is //! A label if there is
CBotString m_label; std::string m_label;
}; };

View File

@ -65,8 +65,8 @@ bool CBotExprAlpha::Execute(CBotStack* &pj)
CBotVar* var = CBotVar::Create(static_cast<CBotToken*>(nullptr), CBotTypString); CBotVar* var = CBotVar::Create(static_cast<CBotToken*>(nullptr), CBotTypString);
CBotString chaine = m_token.GetString(); std::string chaine = m_token.GetString();
chaine = chaine.Mid(1, chaine.GetLength()-2); // removes the quotes chaine = chaine.substr(1, chaine.length()-2); // removes the quotes
var->SetValString(chaine); // value of the number var->SetValString(chaine); // value of the number

View File

@ -25,6 +25,8 @@
#include "CBot/CBotVar/CBotVar.h" #include "CBot/CBotVar/CBotVar.h"
#include "CBot/CBotUtils.h"
// Local include // Local include
// Global include // Global include
@ -48,7 +50,7 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
CBotExprNum* inst = new CBotExprNum(); CBotExprNum* inst = new CBotExprNum();
inst->SetToken(p); inst->SetToken(p);
CBotString s = p->GetString(); std::string s = p->GetString();
inst->m_numtype = CBotTypInt; inst->m_numtype = CBotTypInt;
if (p->GetType() == TokenTypDef) if (p->GetType() == TokenTypDef)
@ -57,7 +59,7 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
} }
else else
{ {
if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) )) if (s.find('.') != std::string::npos || ( s.find('x') == std::string::npos && ( s.find_first_of("eE") != std::string::npos ) ))
{ {
inst->m_numtype = CBotTypFloat; inst->m_numtype = CBotTypFloat;
inst->m_valfloat = GetNumFloat(s); inst->m_valfloat = GetNumFloat(s);
@ -88,7 +90,7 @@ bool CBotExprNum::Execute(CBotStack* &pj)
CBotVar* var = CBotVar::Create(static_cast<CBotToken*>(nullptr), m_numtype); CBotVar* var = CBotVar::Create(static_cast<CBotToken*>(nullptr), m_numtype);
CBotString nombre ; std::string nombre ;
if (m_token.GetType() == TokenTypDef) if (m_token.GetType() == TokenTypDef)
{ {
nombre = m_token.GetString(); nombre = m_token.GetString();

View File

@ -77,5 +77,5 @@ private:
//! Instructions //! Instructions
CBotInstr* m_Block; CBotInstr* m_Block;
//! A label if there is //! A label if there is
CBotString m_label; std::string m_label;
}; };

View File

@ -182,7 +182,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
if ( IsOfType(p, ID_NOT) ) if ( IsOfType(p, ID_NOT) )
{ {
CBotToken d(CBotString("~") + p->GetString()); CBotToken d(std::string("~") + p->GetString());
func->m_token = d; func->m_token = d;
} }
@ -207,7 +207,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
{ {
pStk->SetRetType(func->m_retTyp); // for knowledge what type returns pStk->SetRetType(func->m_retTyp); // for knowledge what type returns
if (!func->m_MasterClass.IsEmpty()) if (!func->m_MasterClass.empty())
{ {
// return "this" known // return "this" known
CBotVar* pThis = CBotVar::Create("this", CBotTypResult( CBotTypClass, func->m_MasterClass )); CBotVar* pThis = CBotVar::Create("this", CBotTypResult( CBotTypClass, func->m_MasterClass ));
@ -356,7 +356,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
pile->IncState(); pile->IncState();
} }
if ( pile->GetState() == 1 && !m_MasterClass.IsEmpty() ) if ( pile->GetState() == 1 && !m_MasterClass.empty() )
{ {
// makes "this" known // makes "this" known
CBotVar* pThis = nullptr; CBotVar* pThis = nullptr;
@ -411,7 +411,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
m_Param->RestoreState(pile2, true); // parameters m_Param->RestoreState(pile2, true); // parameters
if ( !m_MasterClass.IsEmpty() ) if ( !m_MasterClass.empty() )
{ {
CBotVar* pThis = pile->FindVar("this"); CBotVar* pThis = pile->FindVar("this");
pThis->SetInit(CBotVar::InitType::IS_POINTER); pThis->SetInit(CBotVar::InitType::IS_POINTER);
@ -431,7 +431,7 @@ void CBotFunction::AddNext(CBotFunction* p)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long& nIdent) CBotTypResult CBotFunction::CompileCall(const std::string& name, CBotVar** ppVars, long& nIdent)
{ {
nIdent = 0; nIdent = 0;
CBotTypResult type; CBotTypResult type;
@ -442,7 +442,8 @@ CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic) CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& name, CBotVar** ppVars,
CBotTypResult& TypeOrError, bool bPublic)
{ {
TypeOrError.SetType(TX_UNDEFCALL); // no routine of the name TypeOrError.SetType(TX_UNDEFCALL); // no routine of the name
CBotFunction* pt; CBotFunction* pt;
@ -470,7 +471,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB
} }
} }
if ( name == nullptr ) return nullptr; if ( name.empty() ) return nullptr;
int delta = 99999; // seeks the lowest signature int delta = 99999; // seeks the lowest signature
CBotFunction* pFunc = nullptr; // the best function found CBotFunction* pFunc = nullptr; // the best function found
@ -595,7 +596,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken) int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken)
{ {
CBotTypResult type; CBotTypResult type;
CBotFunction* pt = nullptr; CBotFunction* pt = nullptr;
@ -617,7 +618,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS
if ( pStk1->GetState() == 0 ) if ( pStk1->GetState() == 0 )
{ {
if ( !pt->m_MasterClass.IsEmpty() ) if ( !pt->m_MasterClass.empty() )
{ {
CBotVar* pInstance = m_pProg->m_pInstance; CBotVar* pInstance = m_pProg->m_pInstance;
// make "this" known // make "this" known
@ -665,7 +666,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack) void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack)
{ {
CBotTypResult type; CBotTypResult type;
CBotFunction* pt = nullptr; CBotFunction* pt = nullptr;
@ -699,7 +700,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars,
// preparing parameters on the stack // preparing parameters on the stack
{ {
if ( !pt->m_MasterClass.IsEmpty() ) if ( !pt->m_MasterClass.empty() )
{ {
// CBotVar* pInstance = m_pProg->m_pInstance; // CBotVar* pInstance = m_pProg->m_pInstance;
// make "this" known // make "this" known
@ -722,7 +723,8 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars,
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass) int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack,
CBotToken* pToken, CBotClass* pClass)
{ {
CBotTypResult type; CBotTypResult type;
CBotProgram* pProgCurrent = pStack->GetBotCall(); CBotProgram* pProgCurrent = pStack->GetBotCall();
@ -803,7 +805,8 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass) void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars,
CBotStack* pStack, CBotClass* pClass)
{ {
CBotTypResult type; CBotTypResult type;
CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type); CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type);
@ -851,17 +854,17 @@ bool CBotFunction::CheckParam(CBotDefParam* pParam)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotFunction::GetName() std::string CBotFunction::GetName()
{ {
return m_token.GetString(); return m_token.GetString();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotFunction::GetParams() std::string CBotFunction::GetParams()
{ {
if ( m_Param == nullptr ) return CBotString("()"); if ( m_Param == nullptr ) return std::string("()");
CBotString params = "( "; std::string params = "( ";
CBotDefParam* p = m_Param; // list of parameters CBotDefParam* p = m_Param; // list of parameters
while (p != nullptr) while (p != nullptr)

View File

@ -104,7 +104,7 @@ public:
* \param nIdent * \param nIdent
* \return * \return
*/ */
CBotTypResult CompileCall(const char* name, CBotTypResult CompileCall(const std::string& name,
CBotVar** ppVars, CBotVar** ppVars,
long& nIdent); long& nIdent);
@ -118,7 +118,7 @@ public:
* \param bPublic * \param bPublic
* \return * \return
*/ */
CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, CBotFunction* FindLocalOrPublic(long& nIdent, const std::string& name,
CBotVar** ppVars, CBotVar** ppVars,
CBotTypResult& TypeOrError, CBotTypResult& TypeOrError,
bool bPublic = true); bool bPublic = true);
@ -134,7 +134,7 @@ public:
*/ */
int DoCall(long& nIdent, int DoCall(long& nIdent,
const char* name, const std::string& name,
CBotVar** ppVars, CBotVar** ppVars,
CBotStack* pStack, CBotStack* pStack,
CBotToken* pToken); CBotToken* pToken);
@ -147,7 +147,7 @@ public:
* \param pStack * \param pStack
*/ */
void RestoreCall(long& nIdent, void RestoreCall(long& nIdent,
const char* name, const std::string& name,
CBotVar** ppVars, CBotVar** ppVars,
CBotStack* pStack); CBotStack* pStack);
@ -164,7 +164,7 @@ public:
* \return * \return
*/ */
int DoCall(long& nIdent, int DoCall(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppVars, CBotVar** ppVars,
CBotStack* pStack, CBotStack* pStack,
@ -181,7 +181,7 @@ public:
* \param pClass * \param pClass
*/ */
void RestoreCall(long& nIdent, void RestoreCall(long& nIdent,
const char* name, const std::string& name,
CBotVar* pThis, CBotVar* pThis,
CBotVar** ppVars, CBotVar** ppVars,
CBotStack* pStack, CBotStack* pStack,
@ -204,13 +204,13 @@ public:
* \brief GetName * \brief GetName
* \return * \return
*/ */
CBotString GetName(); std::string GetName();
/*! /*!
* \brief GetParams * \brief GetParams
* \return * \return
*/ */
CBotString GetParams(); std::string GetParams();
/*! /*!
* \brief IsPublic * \brief IsPublic
@ -263,7 +263,7 @@ private:
//! Extern function. //! Extern function.
bool m_bExtern; bool m_bExtern;
//! Name of the class we derive. //! Name of the class we derive.
CBotString m_MasterClass; std::string m_MasterClass;
CBotProgram* m_pProg; CBotProgram* m_pProg;
//! For the position of the word "extern". //! For the position of the word "extern".
CBotToken m_extern; CBotToken m_extern;

View File

@ -50,7 +50,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CBotInstr::m_LoopLvl = 0; int CBotInstr::m_LoopLvl = 0;
std::vector<CBotString> CBotInstr::m_labelLvl = std::vector<CBotString>(); std::vector<std::string> CBotInstr::m_labelLvl = std::vector<std::string>();
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotInstr::CBotInstr() CBotInstr::CBotInstr()
@ -72,7 +72,7 @@ CBotInstr::~CBotInstr()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotInstr::IncLvl(CBotString& label) void CBotInstr::IncLvl(std::string& label)
{ {
m_labelLvl.resize(m_LoopLvl+1); m_labelLvl.resize(m_LoopLvl+1);
m_labelLvl[m_LoopLvl] = label; m_labelLvl[m_LoopLvl] = label;
@ -91,24 +91,24 @@ void CBotInstr::IncLvl()
void CBotInstr::DecLvl() void CBotInstr::DecLvl()
{ {
m_LoopLvl--; m_LoopLvl--;
m_labelLvl[m_LoopLvl].Empty(); m_labelLvl[m_LoopLvl].clear();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotInstr::ChkLvl(const CBotString& label, int type) bool CBotInstr::ChkLvl(const std::string& label, int type)
{ {
int i = m_LoopLvl; int i = m_LoopLvl;
while (--i>=0) while (--i>=0)
{ {
if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue; if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue;
if (label.IsEmpty()) return true; if (label.empty()) return true;
if (m_labelLvl[i] == label) return true; if (m_labelLvl[i] == label) return true;
} }
return false; return false;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotInstr::IsOfClass(CBotString n) bool CBotInstr::IsOfClass(const std::string& n)
{ {
return name == n; return name == n;
} }
@ -284,7 +284,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotInstr::Execute(CBotStack* &pj) bool CBotInstr::Execute(CBotStack* &pj)
{ {
CBotString ClassManquante = name; std::string ClassManquante = name;
assert(0); // should never go through this routine assert(0); // should never go through this routine
// but use the routines of the subclasses // but use the routines of the subclasses
return false; return false;
@ -301,7 +301,7 @@ bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotInstr::RestoreState(CBotStack* &pj, bool bMain) void CBotInstr::RestoreState(CBotStack* &pj, bool bMain)
{ {
CBotString ClassManquante = name; std::string ClassManquante = name;
assert(0); // should never go through this routine assert(0); // should never go through this routine
// but use the routines of the subclasses // but use the routines of the subclasses
} }

View File

@ -208,7 +208,7 @@ public:
* \brief IncLvl Adds a level with a label. * \brief IncLvl Adds a level with a label.
* \param label * \param label
*/ */
static void IncLvl(CBotString& label); static void IncLvl(std::string& label);
/*! /*!
* \brief IncLvl Adds a level (switch statement). * \brief IncLvl Adds a level (switch statement).
@ -226,21 +226,21 @@ public:
* \param type * \param type
* \return * \return
*/ */
static bool ChkLvl(const CBotString& label, int type); static bool ChkLvl(const std::string& label, int type);
/*! /*!
* \brief IsOfClass * \brief IsOfClass
* \param name * \param name
* \return * \return
*/ */
bool IsOfClass(CBotString name); bool IsOfClass(const std::string& name);
protected: protected:
//! Keeps the token. //! Keeps the token.
CBotToken m_token; CBotToken m_token;
//! Debug. //! Debug.
CBotString name; std::string name;
//! Linked command. //! Linked command.
CBotInstr* m_next; CBotInstr* m_next;
//! Second list definition chain. //! Second list definition chain.
@ -258,5 +258,5 @@ protected:
private: private:
//! List of labels used. //! List of labels used.
static std::vector<CBotString> m_labelLvl; static std::vector<std::string> m_labelLvl;
}; };

View File

@ -84,9 +84,9 @@ private:
//! Complete type of the result. //! Complete type of the result.
CBotTypResult m_typRes; CBotTypResult m_typRes;
//! Name of the method. //! Name of the method.
CBotString m_NomMethod; std::string m_NomMethod;
//! Identifier of the method. //! Identifier of the method.
long m_MethodeIdent; long m_MethodeIdent;
//! Name of the class. //! Name of the class.
CBotString m_ClassName; std::string m_ClassName;
}; };

View File

@ -97,7 +97,7 @@ bool CBotReturn::Execute(CBotStack* &pj)
if ( pile->IfStep() ) return false; if ( pile->IfStep() ) return false;
pile->SetBreak(3, CBotString()); pile->SetBreak(3, std::string());
return pj->Return(pile); return pj->Return(pile);
} }

View File

@ -74,6 +74,6 @@ private:
//! Instructions //! Instructions
CBotInstr* m_Block; CBotInstr* m_Block;
//! A label if there is //! A label if there is
CBotString m_label; std::string m_label;
}; };

View File

@ -4,7 +4,7 @@
//! \brief Keeps the string corresponding to keyword ID //! \brief Keeps the string corresponding to keyword ID
// Map is filled with id-string pars that are needed for CBot language parsing // Map is filled with id-string pars that are needed for CBot language parsing
static const std::map<EID, const char*> s_keywordString = { static const std::map<EID, const std::string> s_keywordString = {
{ID_IF, "if"}, {ID_IF, "if"},
{ID_ELSE, "else"}, {ID_ELSE, "else"},
{ID_WHILE, "while"}, {ID_WHILE, "while"},
@ -94,9 +94,8 @@ static const std::map<EID, const char*> s_keywordString = {
{TX_NAN, "not a number"} {TX_NAN, "not a number"}
}; };
static const char emptyString[] = ""; static const std::string emptyString = "";
const std::string& LoadString(EID id)
const char* LoadString(EID id)
{ {
if (s_keywordString.find(id) != s_keywordString.end()) if (s_keywordString.find(id) != s_keywordString.end())
{ {

View File

@ -2,9 +2,11 @@
#include "CBotEnums.h" #include "CBotEnums.h"
#include <string>
/** /**
* \brief LoadString Maps given ID to its string equivalent. * \brief LoadString Maps given ID to its string equivalent.
* \param id Provided identifier. * \param id Provided identifier.
* \return String if found, else NullString. * \return String if found, else NullString.
*/ */
const char* LoadString(EID id); const std::string& LoadString(EID id);

View File

@ -81,7 +81,7 @@ CBotProgram::~CBotProgram()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotProgram::Compile( const char* program, std::vector<CBotString>& ListFonctions, void* pUser ) bool CBotProgram::Compile(const std::string& program, std::vector<std::string>& ListFonctions, void* pUser)
{ {
int error = 0; int error = 0;
Stop(); Stop();
@ -176,7 +176,7 @@ bool CBotProgram::Compile( const char* program, std::vector<CBotString>& ListFon
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotProgram::Start(const char* name) bool CBotProgram::Start(const std::string& name)
{ {
#if STACKMEM #if STACKMEM
m_pStack->Delete(); m_pStack->Delete();
@ -210,7 +210,7 @@ bool CBotProgram::Start(const char* name)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet modestart, CBotGet modestop) bool CBotProgram::GetPosition(const std::string& name, int& start, int& stop, CBotGet modestart, CBotGet modestop)
{ {
CBotFunction* p = m_Prog; CBotFunction* p = m_Prog;
while (p != nullptr) while (p != nullptr)
@ -293,7 +293,7 @@ void CBotProgram::Stop()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end) bool CBotProgram::GetRunPos(std::string& FunctionName, int& start, int& end)
{ {
FunctionName = nullptr; FunctionName = nullptr;
start = end = 0; start = end = 0;
@ -304,7 +304,7 @@ bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotProgram::GetStackVars(const char* &FunctionName, int level) CBotVar* CBotProgram::GetStackVars(std::string& FunctionName, int level)
{ {
FunctionName = nullptr; FunctionName = nullptr;
if (m_pStack == nullptr) return nullptr; if (m_pStack == nullptr) return nullptr;
@ -356,11 +356,11 @@ bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotProgram::GetErrorText(int code) std::string CBotProgram::GetErrorText(int code)
{ {
CBotString TextError = LoadString(static_cast<EID>(code)); std::string TextError = LoadString(static_cast<EID>(code));
if (TextError.IsEmpty()) if (TextError.empty())
{ {
char buf[100]; char buf[100];
sprintf(buf, "Exception numéro %d.", code); sprintf(buf, "Exception numéro %d.", code);
@ -376,9 +376,9 @@ CBotFunction* CBotProgram::GetFunctions()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotProgram::AddFunction(const char* name, bool CBotProgram::AddFunction(const std::string& name,
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) CBotTypResult rCompile(CBotVar*& pVar, void* pUser))
{ {
// stores pointers to the two functions // stores pointers to the two functions
return CBotCall::AddFunction(name, rExec, rCompile); return CBotCall::AddFunction(name, rExec, rCompile);
@ -412,7 +412,7 @@ CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotProgram::DefineNum(const char* name, long val) bool CBotProgram::DefineNum(const std::string& name, long val)
{ {
return CBotToken::DefineNum(name, val); return CBotToken::DefineNum(name, val);
} }
@ -440,7 +440,7 @@ bool CBotProgram::SaveState(FILE* pf)
bool CBotProgram::RestoreState(FILE* pf) bool CBotProgram::RestoreState(FILE* pf)
{ {
unsigned short w; unsigned short w;
CBotString s; std::string s;
Stop(); Stop();

View File

@ -21,7 +21,6 @@
// Modules inlcude // Modules inlcude
#include "CBot/CBotTypResult.h" #include "CBot/CBotTypResult.h"
#include "CBot/CBotString.h"
#include "CBot/CBotEnums.h" #include "CBot/CBotEnums.h"
@ -84,7 +83,7 @@ public:
* \return false if an error at compile. * \return false if an error at compile.
* \see GetCompileError() to retrieve the error. * \see GetCompileError() to retrieve the error.
*/ */
bool Compile( const char* program, std::vector<CBotString>& ListFonctions, void* pUser = nullptr); bool Compile(const std::string& program, std::vector<std::string>& ListFonctions, void* pUser = nullptr);
/*! /*!
* \brief SetIdent Associates an identifier with the instance CBotProgram. * \brief SetIdent Associates an identifier with the instance CBotProgram.
@ -128,7 +127,7 @@ public:
* \param code * \param code
* \return * \return
*/ */
static CBotString GetErrorText(int code); static std::string GetErrorText(int code);
/*! /*!
* \brief Start Defines what function should be executed. The program does * \brief Start Defines what function should be executed. The program does
@ -136,7 +135,7 @@ public:
* \param name * \param name
* \return false if the funtion name is not found * \return false if the funtion name is not found
*/ */
bool Start(const char* name); bool Start(const std::string& name);
/*! /*!
* \brief Run Executes the program. * \brief Run Executes the program.
@ -154,7 +153,7 @@ public:
* \param end * \param end
* \return false if it is not running (program completion) * \return false if it is not running (program completion)
*/ */
bool GetRunPos(const char* &FunctionName, int &start, int &end); bool GetRunPos(std::string& FunctionName, int& start, int& end);
/*! /*!
* \brief GetStackVars provides the pointer to the variables on the * \brief GetStackVars provides the pointer to the variables on the
@ -168,7 +167,7 @@ public:
* \param level * \param level
* \return * \return
*/ */
CBotVar* GetStackVars(const char* &FunctionName, int level); CBotVar* GetStackVars(std::string& FunctionName, int level);
/*! /*!
* \brief Stop stops execution of the program therefore quits "suspend" mode * \brief Stop stops execution of the program therefore quits "suspend" mode
@ -193,9 +192,9 @@ public:
* \param rCompile * \param rCompile
* \return * \return
*/ */
static bool AddFunction(const char* name, static bool AddFunction(const std::string& name,
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); CBotTypResult rCompile(CBotVar*& pVar, void* pUser));
/*! /*!
* \brief DefineNum * \brief DefineNum
@ -203,7 +202,7 @@ public:
* \param val * \param val
* \return * \return
*/ */
static bool DefineNum(const char* name, long val); static bool DefineNum(const std::string& name, long val);
/*! /*!
* \brief SaveState Backup the execution status in the file the file must * \brief SaveState Backup the execution status in the file the file must
@ -233,11 +232,11 @@ public:
* \param modestop * \param modestop
* \return * \return
*/ */
bool GetPosition(const char* name, bool GetPosition(const std::string& name,
int& start, int& start,
int& stop, int& stop,
CBotGet modestart = GetPosExtern, CBotGet modestart = GetPosExtern,
CBotGet modestop = GetPosBloc); CBotGet modestop = GetPosBloc);
/*! /*!
* \brief GetFunctions * \brief GetFunctions
@ -286,7 +285,7 @@ private:
For example, a routine which calculates the mean of a parameter list For example, a routine which calculates the mean of a parameter list
int cMean(CBotVar* &pVar, CBotString& ClassName) int cMean(CBotVar* &pVar, std::string& ClassName)
{ {
if ( pVar == nullptr ) return 6001; // there is no parameter! if ( pVar == nullptr ) return 6001; // there is no parameter!
while ( pVar != nullptr ) while ( pVar != nullptr )

View File

@ -27,6 +27,7 @@
#include "CBot/CBotVar/CBotVarClass.h" #include "CBot/CBotVar/CBotVarClass.h"
#include "CBot/CBotFileUtils.h" #include "CBot/CBotFileUtils.h"
#include "CBot/CBotUtils.h"
// Local include // Local include
@ -44,7 +45,7 @@ CBotVar* CBotStack::m_retvar = nullptr;
int CBotStack::m_error = 0; int CBotStack::m_error = 0;
int CBotStack::m_start = 0; int CBotStack::m_start = 0;
int CBotStack::m_end = 0; int CBotStack::m_end = 0;
CBotString CBotStack::m_labelBreak=""; std::string CBotStack::m_labelBreak="";
void* CBotStack::m_pUser = nullptr; void* CBotStack::m_pUser = nullptr;
#if STACKMEM #if STACKMEM
@ -381,7 +382,7 @@ void CBotStack::Reset(void* pUser)
m_error = 0; m_error = 0;
// m_start = 0; // m_start = 0;
// m_end = 0; // m_end = 0;
m_labelBreak.Empty(); m_labelBreak.clear();
m_pUser = pUser; m_pUser = pUser;
} }
@ -414,36 +415,36 @@ bool CBotStack::IfStep()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotStack::BreakReturn(CBotStack* pfils, const char* name) bool CBotStack::BreakReturn(CBotStack* pfils, const std::string& name)
{ {
if ( m_error>=0 ) return false; // normal output if ( m_error>=0 ) return false; // normal output
if ( m_error==-3 ) return false; // normal output (return current) if ( m_error==-3 ) return false; // normal output (return current)
if (!m_labelBreak.IsEmpty() && (name[0] == 0 || m_labelBreak != name)) if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name))
return false; // it's not for me return false; // it's not for me
m_error = 0; m_error = 0;
m_labelBreak.Empty(); m_labelBreak.clear();
return Return(pfils); return Return(pfils);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotStack::IfContinue(int state, const char* name) bool CBotStack::IfContinue(int state, const std::string& name)
{ {
if ( m_error != -2 ) return false; if ( m_error != -2 ) return false;
if (!m_labelBreak.IsEmpty() && (name == nullptr || m_labelBreak != name)) if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name))
return false; // it's not for me return false; // it's not for me
m_state = state; // where again? m_state = state; // where again?
m_error = 0; m_error = 0;
m_labelBreak.Empty(); m_labelBreak.clear();
if ( m_next != EOX ) m_next->Delete(); // purge above stack if ( m_next != EOX ) m_next->Delete(); // purge above stack
return true; return true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetBreak(int val, const char* name) void CBotStack::SetBreak(int val, const std::string& name)
{ {
m_error = -val; // reacts as an Exception m_error = -val; // reacts as an Exception
m_labelBreak = name; m_labelBreak = name;
@ -502,7 +503,7 @@ void CBotStack::SetType(CBotTypResult& type)
CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif) CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif)
{ {
CBotStack* p = this; CBotStack* p = this;
CBotString name = pToken->GetString(); std::string name = pToken->GetString();
while (p != nullptr) while (p != nullptr)
{ {
@ -524,7 +525,7 @@ CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::FindVar(const char* name) CBotVar* CBotStack::FindVar(const std::string& name)
{ {
CBotStack* p = this; CBotStack* p = this;
while (p != nullptr) while (p != nullptr)
@ -814,7 +815,7 @@ bool SaveVar(FILE* pf, CBotVar* pVar)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) void CBotStack::GetRunPos(std::string& FunctionName, int& start, int& end)
{ {
CBotProgram* prog = m_prog; // Current program CBotProgram* prog = m_prog; // Current program
@ -849,7 +850,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) CBotVar* CBotStack::GetStackVars(std::string& FunctionName, int level)
{ {
CBotProgram* prog = m_prog; // current program CBotProgram* prog = m_prog; // current program
FunctionName = nullptr; FunctionName = nullptr;
@ -1005,7 +1006,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
{ {
unsigned short w, wi, prv, st; unsigned short w, wi, prv, st;
float ww; float ww;
CBotString name, s; std::string name, s;
delete pVar; delete pVar;
@ -1018,7 +1019,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if (!ReadWord(pf, w)) return false; // private or type? if (!ReadWord(pf, w)) return false; // private or type?
if ( w == 0 ) return true; if ( w == 0 ) return true;
CBotString defnum; std::string defnum;
if ( w == 200 ) if ( w == 200 )
{ {
if (!ReadString(pf, defnum)) return false; // number with identifier if (!ReadString(pf, defnum)) return false; // number with identifier
@ -1039,7 +1040,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if (!ReadWord(pf, wi) || !ParseInitType(wi, &initType)) return false; // init ? if (!ReadWord(pf, wi) || !ParseInitType(wi, &initType)) return false; // init ?
if (!ReadString(pf, name)) return false; // variable name if (!ReadString(pf, name)) return false; // variable name
CBotToken token(name, CBotString()); CBotToken token(name, std::string());
switch (w) switch (w)
{ {

View File

@ -22,12 +22,12 @@
// Modules inlcude // Modules inlcude
#include "CBot/CBotDefines.h" #include "CBot/CBotDefines.h"
#include "CBot/CBotTypResult.h" #include "CBot/CBotTypResult.h"
#include "CBot/CBotString.h"
// Local include // Local include
// Global include // Global include
#include <cstdio> #include <cstdio>
#include <string>
// Forward declaration // Forward declaration
class CBotInstr; class CBotInstr;
@ -150,7 +150,7 @@ public:
* \param [in] name Name of variable to find * \param [in] name Name of variable to find
* \return Found variable * \return Found variable
*/ */
CBotVar* FindVar(const char* name); CBotVar* FindVar(const std::string& name);
/** /**
* \brief Fetch a variable on the stack according to its identification number * \brief Fetch a variable on the stack according to its identification number
@ -180,9 +180,9 @@ public:
CBotStack* AddStack2(UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack CBotStack* AddStack2(UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack
bool Return(CBotStack* pFils); // transmits the result over bool Return(CBotStack* pFils); // transmits the result over
bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack
bool BreakReturn(CBotStack* pfils, const char* name = nullptr); bool BreakReturn(CBotStack* pfils, const std::string& name = nullptr);
// in case of eventual break // in case of eventual break
bool IfContinue(int state, const char* name); bool IfContinue(int state, const std::string& name);
// or "continue" // or "continue"
bool IsOk(); bool IsOk();
@ -204,7 +204,7 @@ public:
void SetError(int n, CBotToken* token = nullptr); void SetError(int n, CBotToken* token = nullptr);
void SetPosError(CBotToken* token); void SetPosError(CBotToken* token);
void ResetError(int n, int start, int end); void ResetError(int n, int start, int end);
void SetBreak(int val, const char* name); void SetBreak(int val, const std::string& name);
void SetBotCall(CBotProgram* p); void SetBotCall(CBotProgram* p);
CBotProgram* GetBotCall(bool bFirst = false); CBotProgram* GetBotCall(bool bFirst = false);
@ -221,8 +221,8 @@ public:
static static
void SetTimer(int n); void SetTimer(int n);
void GetRunPos(const char* &FunctionName, int &start, int &end); void GetRunPos(std::string& FunctionName, int& start, int& end);
CBotVar* GetStackVars(const char* &FunctionName, int level); CBotVar* GetStackVars(std::string& FunctionName, int level);
private: private:
CBotStack* m_next; CBotStack* m_next;
@ -254,7 +254,7 @@ private:
static static
int m_timer; int m_timer;
static static
CBotString m_labelBreak; std::string m_labelBreak;
static static
void* m_pUser; void* m_pUser;

View File

@ -1,236 +0,0 @@
/*
* 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
*/
/////////////////////////////////////////////////////
#include "CBot/CBotString.h"
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <boost/algorithm/string.hpp>
CBotString::CBotString()
{
m_str = "";
}
CBotString::~CBotString()
{
}
CBotString::CBotString(const char* p)
{
m_str = p;
}
CBotString::CBotString(const std::string &p)
{
m_str = p;
}
CBotString::CBotString(const CBotString& srcString)
{
m_str = srcString.m_str;
}
int CBotString::GetLength()
{
return m_str.length();
}
CBotString CBotString::Left(int nCount) const
{
return CBotString(m_str.substr(0, nCount));
}
CBotString CBotString::Right(int nCount) const
{
return CBotString(m_str.substr(m_str.length()-nCount, std::string::npos));
}
CBotString CBotString::Mid(int start, int lg)
{
return CBotString(m_str.substr(start, lg));
}
int CBotString::Find(const char c)
{
std::size_t pos = m_str.find(c);
return pos != std::string::npos ? pos : -1;
}
int CBotString::Find(const char * lpsz)
{
std::size_t pos = m_str.find(lpsz);
return pos != std::string::npos ? pos : -1;
}
int CBotString::ReverseFind(const char c)
{
std::size_t pos = m_str.rfind(c);
return pos != std::string::npos ? pos : -1;
}
int CBotString::ReverseFind(const char * lpsz)
{
std::size_t pos = m_str.rfind(lpsz);
return pos != std::string::npos ? pos : -1;
}
void CBotString::MakeUpper()
{
boost::to_upper(m_str);
}
void CBotString::MakeLower()
{
boost::to_lower(m_str);
}
const CBotString& CBotString::operator=(const CBotString& stringSrc)
{
m_str = stringSrc.m_str;
return *this;
}
CBotString CBotString::operator+(const CBotString& stringSrc)
{
CBotString s(*this);
s += stringSrc;
return s;
}
const CBotString& CBotString::operator=(const char ch)
{
m_str = ch;
return *this;
}
const CBotString& CBotString::operator=(const char* pString)
{
if (pString != nullptr)
m_str = pString;
else
m_str.clear();
return *this;
}
const CBotString& CBotString::operator+=(const char ch)
{
m_str += ch;
return *this;
}
const CBotString& CBotString::operator+=(const CBotString& str)
{
m_str += str.m_str;
return *this;
}
bool CBotString::operator==(const CBotString& str)
{
return m_str == str.m_str;
}
bool CBotString::operator==(const char* p)
{
return m_str == p;
}
bool CBotString::operator!=(const CBotString& str)
{
return m_str != str.m_str;
}
bool CBotString::operator!=(const char* p)
{
return m_str != p;
}
bool CBotString::operator>(const CBotString& str)
{
return m_str > str.m_str;
}
bool CBotString::operator>(const char* p)
{
return m_str > p;
}
bool CBotString::operator>=(const CBotString& str)
{
return m_str >= str.m_str;
}
bool CBotString::operator>=(const char* p)
{
return m_str >= p;
}
bool CBotString::operator<(const CBotString& str)
{
return m_str < str.m_str;
}
bool CBotString::operator<(const char* p)
{
return m_str < p;
}
bool CBotString::operator<=(const CBotString& str)
{
return m_str <= str.m_str;
}
bool CBotString::operator<=(const char* p)
{
return m_str <= p;
}
bool CBotString::IsEmpty() const
{
return m_str.empty();
}
void CBotString::Empty()
{
m_str.clear();
}
static char emptyString[] = "";
CBotString::operator const char * () const
{
if (this == nullptr) return emptyString; // TODO: can this be removed?
return m_str.c_str();
}
const char* CBotString::CStr() const
{
if (this == nullptr) return emptyString; // TODO: can this be removed?
return m_str.c_str();
}

View File

@ -1,194 +0,0 @@
/*
* 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/CBotUtils.h"
#include "CBot/CBotEnums.h"
// Local include
// Global include
#include <map>
/**
* \brief CBotString Class used to work on strings
* TODO: do not use this class, code should be refactored to use std::string instead
*/
class CBotString
{
public:
/**
* \brief CBotString Creates an empty string
*/
CBotString();
/**
* \brief CBotString
* \param p
*/
CBotString(const char* p);
/**
* \brief CBotString
* \param p
*/
CBotString(const std::string& p);
/**
* \brief CBotString
* \param p
*/
CBotString(const CBotString& p);
/**
* \brief CBotString Destructor.
*/
~CBotString();
/**
* \brief Empty Clear the internal string.
*/
void Empty();
/**
* \brief IsEmpty Check if the string is empty.
* \return True if the sting is empty false otherwise.
*/
bool IsEmpty() const;
/**
* \brief GetLength Get the string length.
* \return The size of the string.
*/
int GetLength();
/**
* \brief Find Find the position of a character in a string starting from
* the beginning of the string.
* \param c The character to find.
* \return The position of the character or -1 if the character was not
* found.
* \see ReverseFind(const char c)
*/
int Find(const char c);
/**
* \brief Find Find the position of a string in a string starting from the
* beginning of the string.
* \param lpsz The string to find.
* \return The position of the string or -1 if the string was not
* found.
* \see ReverseFind(const char* lpsz)
*/
int Find(const char* lpsz);
/**
* \brief Find Find the position of a character in a string starting from
* the end of the string.
* \param c The character to find.
* \return The position of the character or -1 if the character was not
* found.
* \see Find(const char c)
*/
int ReverseFind(const char c);
/**
* \brief Find Find the position of a string in a string starting from the
* end of the string.
* \param lpsz The string to find.
* \return The string of the character or -1 if the string was not
* found.
* \see Find(const char* lpsz)
*/
int ReverseFind(const char* lpsz);
/**
* \brief Mid Return a part of a string from a starting index and until
* the end of the string with a limited size.
* \param nFirst The start index of the character in the string.
* \param lg The size limit. Default value is 2000.
* \return The exctracted string.
*/
CBotString Mid(int start, int lg=-1);
/**
* \brief Left Return a part of a string starting from the left.
* \param nCount The number of character to retreive.
* \return The exctracted string.
*/
CBotString Left(int nCount) const;
/**
* \brief Right Return a part of a string starting from the right.
* \param nCount The number of character to retreive.
* \return The exctracted string.
*/
CBotString Right(int nCount) const;
/**
* \brief MakeUpper Uppercase the string.
*/
void MakeUpper();
/**
* \brief MakeLower Lowercase the string.
*/
void MakeLower();
/**
* @brief CStr Convert the CBotString to a C string.
* @return A C string string.
*/
const char* CStr() const;
/**
* \brief Overloaded oprators to work on CBotString classes
*/
const CBotString& operator=(const CBotString& stringSrc);
const CBotString& operator=(const char ch);
const CBotString& operator=(const char* pString);
CBotString operator+(const CBotString& str);
const CBotString& operator+=(const char ch);
const CBotString& operator+=(const CBotString& str);
bool operator==(const CBotString& str);
bool operator==(const char* p);
bool operator!=(const CBotString& str);
bool operator!=(const char* p);
bool operator>(const CBotString& str);
bool operator>(const char* p);
bool operator>=(const CBotString& str);
bool operator>=(const char* p);
bool operator<(const CBotString& str);
bool operator<(const char* p);
bool operator<=(const CBotString& str);
bool operator<=(const char* p);
operator const char*() const; // as a C string
private:
//! \brief String
std::string m_str;
};

View File

@ -27,9 +27,9 @@
#include <cstdarg> #include <cstdarg>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::vector<CBotString> CBotToken::m_ListKeyWords; std::vector<std::string> CBotToken::m_ListKeyWords;
int CBotToken::m_ListIdKeyWords[200]; int CBotToken::m_ListIdKeyWords[200];
std::vector<CBotString> CBotToken::m_ListKeyDefine; std::vector<std::string> CBotToken::m_ListKeyDefine;
long CBotToken::m_ListKeyNums[MAXDEFNUM]; long CBotToken::m_ListKeyNums[MAXDEFNUM];
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -47,8 +47,8 @@ CBotToken::CBotToken(const CBotToken* pSrc)
m_next = nullptr; m_next = nullptr;
m_prev = nullptr; m_prev = nullptr;
m_Text.Empty(); m_Text.clear();
m_Sep.Empty(); m_Sep.clear();
m_type = 0; m_type = 0;
m_IdKeyWord = 0; m_IdKeyWord = 0;
@ -71,7 +71,7 @@ CBotToken::CBotToken(const CBotToken* pSrc)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotToken::CBotToken(const CBotString& mot, const CBotString& sep, int start, int end) CBotToken::CBotToken(const std::string& mot, const std::string& sep, int start, int end)
{ {
m_Text = mot; // word (mot) found as token m_Text = mot; // word (mot) found as token
m_Sep = sep; // separator m_Sep = sep; // separator
@ -84,17 +84,6 @@ CBotToken::CBotToken(const CBotString& mot, const CBotString& sep, int start, in
m_IdKeyWord = -1; m_IdKeyWord = -1;
} }
CBotToken::CBotToken(const char* mot, const char* sep)
{
m_Text = mot;
if ( sep != nullptr ) m_Sep = sep;
m_next = nullptr;
m_prev = nullptr;
m_type = TokenTypVar; // at the beginning a default variable type
m_IdKeyWord = -1;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotToken::~CBotToken() CBotToken::~CBotToken()
{ {
@ -155,19 +144,19 @@ CBotToken* CBotToken::GetPrev()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotToken::GetString() std::string CBotToken::GetString()
{ {
return m_Text; return m_Text;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotToken::GetSep() std::string CBotToken::GetSep()
{ {
return m_Sep; return m_Sep;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotToken::SetString(const char* name) void CBotToken::SetString(const std::string& name)
{ {
m_Text = name; m_Text = name;
} }
@ -229,8 +218,8 @@ static char nch[] = "\"\r\n\t"; // forbidden in cha
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotToken* CBotToken::NextToken(char* &program, int& error, bool first) CBotToken* CBotToken::NextToken(char* &program, int& error, bool first)
{ {
CBotString mot; // the word which is found std::string mot; // the word which is found
CBotString sep; // separators that are after std::string sep; // separators that are after
char c; char c;
bool stop = first; bool stop = first;
@ -315,7 +304,7 @@ cc: mot += c;
if (CharInList(mot[0], sep3)) // an operational separator? if (CharInList(mot[0], sep3)) // an operational separator?
{ {
CBotString motc = mot; std::string motc = mot;
while (motc += c, c != 0 && GetKeyWords(motc)>0) // operand seeks the longest possible while (motc += c, c != 0 && GetKeyWords(motc)>0) // operand seeks the longest possible
{ {
mot += c; // build the word mot += c; // build the word
@ -332,7 +321,7 @@ cc: mot += c;
{ {
if (stop || c == 0 || CharInList(c, sep1)) if (stop || c == 0 || CharInList(c, sep1))
{ {
if (!first && mot.IsEmpty()) return nullptr; // end of the analysis if (!first && mot.empty()) return nullptr; // end of the analysis
bis: bis:
while (CharInList(c, sep2)) while (CharInList(c, sep2))
{ {
@ -387,10 +376,10 @@ bis:
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotToken* CBotToken::CompileTokens(const char* program, int& error) CBotToken* CBotToken::CompileTokens(const std::string& program, int& error)
{ {
CBotToken *nxt, *prv, *tokenbase; CBotToken *nxt, *prv, *tokenbase;
char* p = const_cast<char*> ( program); char* p = const_cast<char*> (program.c_str());
int pos = 0; int pos = 0;
error = 0; error = 0;
@ -399,9 +388,9 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error)
if (tokenbase == nullptr) return nullptr; if (tokenbase == nullptr) return nullptr;
tokenbase->m_start = pos; tokenbase->m_start = pos;
pos += tokenbase->m_Text.GetLength(); pos += tokenbase->m_Text.length();
tokenbase->m_end = pos; tokenbase->m_end = pos;
pos += tokenbase->m_Sep.GetLength(); pos += tokenbase->m_Sep.length();
char* pp = p; char* pp = p;
while (nullptr != (nxt = NextToken(p, error))) while (nullptr != (nxt = NextToken(p, error)))
@ -415,7 +404,7 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error)
nxt->m_end = pos; nxt->m_end = pos;
pos += nxt->m_Sep.GetLength();*/ pos += nxt->m_Sep.GetLength();*/
pos += (p - pp); // total size pos += (p - pp); // total size
nxt->m_end = pos - nxt->m_Sep.GetLength(); nxt->m_end = pos - nxt->m_Sep.length();
pp = p; pp = p;
} }
@ -436,7 +425,7 @@ void CBotToken::Delete(CBotToken* pToken)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CBotToken::GetKeyWords(const char* w) int CBotToken::GetKeyWords(const std::string& w)
{ {
int i; int i;
int l = m_ListKeyWords.size(); int l = m_ListKeyWords.size();
@ -456,7 +445,7 @@ int CBotToken::GetKeyWords(const char* w)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token) bool CBotToken::GetKeyDefNum(const std::string& w, CBotToken*& token)
{ {
int i; int i;
int l = m_ListKeyDefine.size(); int l = m_ListKeyDefine.size();
@ -477,18 +466,18 @@ bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotToken::LoadKeyWords() void CBotToken::LoadKeyWords()
{ {
CBotString s; std::string s;
int i, n = 0; int i, n = 0;
i = TokenKeyWord; //start with keywords of the language i = TokenKeyWord; //start with keywords of the language
while (!(s = LoadString(static_cast<EID>(i))).IsEmpty()) while (!(s = LoadString(static_cast<EID>(i))).empty())
{ {
m_ListKeyWords.push_back(s); m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++; m_ListIdKeyWords[n++] = i++;
} }
i = TokenKeyDeclare; //keywords of declarations i = TokenKeyDeclare; //keywords of declarations
while (!(s = LoadString(static_cast<EID>(i))).IsEmpty()) while (!(s = LoadString(static_cast<EID>(i))).empty())
{ {
m_ListKeyWords.push_back(s); m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++; m_ListIdKeyWords[n++] = i++;
@ -496,14 +485,14 @@ void CBotToken::LoadKeyWords()
i = TokenKeyVal; //keywords of values i = TokenKeyVal; //keywords of values
while (!(s = LoadString(static_cast<EID>(i))).IsEmpty()) while (!(s = LoadString(static_cast<EID>(i))).empty())
{ {
m_ListKeyWords.push_back(s); m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++; m_ListIdKeyWords[n++] = i++;
} }
i = TokenKeyOp; //operators i = TokenKeyOp; //operators
while (!(s = LoadString(static_cast<EID>(i))).IsEmpty()) while (!(s = LoadString(static_cast<EID>(i))).empty())
{ {
m_ListKeyWords.push_back(s); m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++; m_ListIdKeyWords[n++] = i++;
@ -511,7 +500,7 @@ void CBotToken::LoadKeyWords()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotToken::DefineNum(const char* name, long val) bool CBotToken::DefineNum(const std::string& name, long val)
{ {
int i; int i;
int l = m_ListKeyDefine.size(); int l = m_ListKeyDefine.size();

View File

@ -19,9 +19,8 @@
#pragma once #pragma once
#include "CBot/CBotString.h"
#include <vector> #include <vector>
#include <string>
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// Token management (tokens) // Token management (tokens)
@ -69,11 +68,10 @@ public:
*/ */
CBotToken(); CBotToken();
CBotToken(const CBotToken* pSrc); CBotToken(const CBotToken* pSrc);
CBotToken(const CBotString& mot, CBotToken(const std::string& mot,
const CBotString& sep, const std::string& sep = "",
int start=0, int start=0,
int end=0); int end=0);
CBotToken(const char* mot, const char* sep = nullptr);
/*! /*!
* \brief ~CBotToken Destructor. Be careful when you delete a CBotToken that * \brief ~CBotToken Destructor. Be careful when you delete a CBotToken that
@ -92,20 +90,20 @@ public:
* \return The token string if a string has been set. An empty string * \return The token string if a string has been set. An empty string
* otherwise. * otherwise.
*/ */
CBotString GetString(); std::string GetString();
/*! /*!
* \brief SetString Set the token string. * \brief SetString Set the token string.
* \param [in] name The new string to set. * \param [in] name The new string to set.
*/ */
void SetString(const char* name); void SetString(const std::string& name);
/*! /*!
* \brief GetSep Return the token separator. * \brief GetSep Return the token separator.
* \return The token separator a separator has been set. An empty separator * \return The token separator a separator has been set. An empty separator
* otherwise. * otherwise.
*/ */
CBotString GetSep(); std::string GetSep();
/*! /*!
* \brief GetStart Return the start position of the string token in the * \brief GetStart Return the start position of the string token in the
@ -165,7 +163,7 @@ public:
* \return The first token of the linked liste. * \return The first token of the linked liste.
* \todo Replace the error code by an enum. * \todo Replace the error code by an enum.
*/ */
static CBotToken* CompileTokens(const char* p, int& error); static CBotToken* CompileTokens(const std::string& p, int& error);
/*! /*!
* \brief NextToken Looking for the next token in the string. The string must * \brief NextToken Looking for the next token in the string. The string must
@ -191,7 +189,7 @@ public:
* \param [in] val The number associated with the keyword. * \param [in] val The number associated with the keyword.
* \return Ture if the number is available false oterhwise. * \return Ture if the number is available false oterhwise.
*/ */
static bool DefineNum(const char* name, long val); static bool DefineNum(const std::string& name, long val);
/*! /*!
* \brief Free Free the array created with DefineNum. * \brief Free Free the array created with DefineNum.
@ -211,9 +209,9 @@ private:
long m_IdKeyWord; long m_IdKeyWord;
//! The token string //! The token string
CBotString m_Text; std::string m_Text;
//! The token separator //! The token separator
CBotString m_Sep; std::string m_Sep;
//! The strat position of the token in the CBotProgram //! The strat position of the token in the CBotProgram
int m_start; int m_start;
@ -225,7 +223,7 @@ private:
* \param w The word to compare. * \param w The word to compare.
* \return -1 if this is not a keyword the keyword number otherwise. * \return -1 if this is not a keyword the keyword number otherwise.
*/ */
static int GetKeyWords(const char* w); // is it a keyword? static int GetKeyWords(const std::string& w); // is it a keyword?
/*! /*!
* \brief GetKeyDefNum Check if this is a defined word and set the defined * \brief GetKeyDefNum Check if this is a defined word and set the defined
@ -234,18 +232,18 @@ private:
* \param [out] token The token in which the type will be set. * \param [out] token The token in which the type will be set.
* \return True if the defined word is found false otherwise. * \return True if the defined word is found false otherwise.
*/ */
static bool GetKeyDefNum(const char* w, CBotToken* &token); static bool GetKeyDefNum(const std::string& w, CBotToken*& token);
/*! /*!
* \brief LoadKeyWords Loads the list of keywords. The list of keyword is * \brief LoadKeyWords Loads the list of keywords. The list of keyword is
* CBotString::s_keywordString. This keywords are keywords languages (if, +, * std::string::s_keywordString. This keywords are keywords languages (if, +,
* for, while, case, extern ...) * for, while, case, extern ...)
* \todo Fixme Figure out how this should work. * \todo Fixme Figure out how this should work.
*/ */
static void LoadKeyWords(); static void LoadKeyWords();
//! List of keywords of the CBot language (if, +, for, while, case, extern ...) //! List of keywords of the CBot language (if, +, for, while, case, extern ...)
static std::vector<CBotString> m_ListKeyWords; static std::vector<std::string> m_ListKeyWords;
//! List of id correponding to the keywords of the CBot language //! List of id correponding to the keywords of the CBot language
static int m_ListIdKeyWords[200]; static int m_ListIdKeyWords[200];
@ -253,7 +251,7 @@ private:
//! This keywords are defined in : //! This keywords are defined in :
//! - void CScriptFunctions::Init() //! - void CScriptFunctions::Init()
//! - void CBotProgram::Init() //! - void CBotProgram::Init()
static std::vector<CBotString> m_ListKeyDefine; static std::vector<std::string> m_ListKeyDefine;
//! List of id correponding to the defined words //! List of id correponding to the defined words
static long m_ListKeyNums[MAXDEFNUM]; static long m_ListKeyNums[MAXDEFNUM];

View File

@ -43,7 +43,7 @@ CBotTypResult::CBotTypResult(int type)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotTypResult::CBotTypResult(int type, const char* name) CBotTypResult::CBotTypResult(int type, const std::string& name)
{ {
m_type = type; m_type = type;
m_pNext = nullptr; m_pNext = nullptr;

View File

@ -24,6 +24,7 @@
// Local include // Local include
// Global include // Global include
#include <string>
class CBotClass; class CBotClass;
@ -55,7 +56,7 @@ public:
// for simple types (CBotTypInt à CBotTypString) // for simple types (CBotTypInt à CBotTypString)
CBotTypResult(int type, const char* name); CBotTypResult(int type, const std::string& name);
// for pointer types and intrinsic classes // for pointer types and intrinsic classes
CBotTypResult(int type, CBotClass* pClass); CBotTypResult(int type, CBotClass* pClass);

View File

@ -120,14 +120,14 @@ bool WriteWord(FILE* pf, unsigned short w)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool WriteString(FILE* pf, CBotString s) bool WriteString(FILE* pf, std::string s)
{ {
size_t lg1, lg2; size_t lg1, lg2;
lg1 = s.GetLength(); lg1 = s.size();
if (!WriteWord(pf, lg1)) return false; if (!WriteWord(pf, lg1)) return false;
lg2 = fwrite(s, 1, lg1, pf ); lg2 = fwrite(s.c_str(), 1, lg1, pf );
return (lg1 == lg2); return (lg1 == lg2);
} }
@ -142,46 +142,9 @@ bool WriteFloat(FILE* pf, float w)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ConstructElement(CBotString* pNewData) long GetNumInt(const std::string& str)
{
memset(pNewData, 0, sizeof(CBotString));
}
////////////////////////////////////////////////////////////////////////////////
void DestructElement(CBotString* pOldData)
{
pOldData->~CBotString();
}
////////////////////////////////////////////////////////////////////////////////
void CopyElement(CBotString* pSrc, CBotString* pDest)
{
*pSrc = *pDest;
}
////////////////////////////////////////////////////////////////////////////////
void ConstructElements(CBotString* pNewData, int nCount)
{
while (nCount--)
{
ConstructElement(pNewData);
pNewData++;
}
}
////////////////////////////////////////////////////////////////////////////////
void DestructElements(CBotString* pOldData, int nCount)
{
while (nCount--)
{
DestructElement(pOldData);
pOldData++;
}
}
////////////////////////////////////////////////////////////////////////////////
long GetNumInt(const char* p)
{ {
const char* p = str.c_str();
long num = 0; long num = 0;
while (*p >= '0' && *p <= '9') while (*p >= '0' && *p <= '9')
{ {
@ -214,8 +177,9 @@ long GetNumInt(const char* p)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
float GetNumFloat(const char* p) float GetNumFloat(const std::string& str)
{ {
const char* p = str.c_str();
double num = 0; double num = 0;
double div = 10; double div = 10;
bool bNeg = false; bool bNeg = false;

View File

@ -20,16 +20,15 @@
#pragma once #pragma once
// Modules inlcude // Modules inlcude
#include "CBot/CBotString.h"
#include "CBot/CBotTypResult.h" #include "CBot/CBotTypResult.h"
// Local include // Local include
// Global include // Global include
#include <cstdio> #include <cstdio>
#include <string>
// Forward declaration // Forward declaration
class CBotString;
class CBotVar; class CBotVar;
class CBotToken; class CBotToken;
class CBotCStack; class CBotCStack;
@ -74,7 +73,7 @@ bool WriteWord(FILE* pf, unsigned short w);
* \param s * \param s
* \return * \return
*/ */
bool WriteString(FILE* pf, CBotString s); bool WriteString(FILE* pf, std::string s);
/*! /*!
* \brief WriteFloat * \brief WriteFloat
@ -84,50 +83,17 @@ bool WriteString(FILE* pf, CBotString s);
*/ */
bool WriteFloat(FILE* pf, float w); bool WriteFloat(FILE* pf, float w);
/*!
* \brief ConstructElement
* \param pNewData
*/
void ConstructElement(CBotString* pNewData);
/*!
* \brief DestructElement
* \param pOldData
*/
void DestructElement(CBotString* pOldData);
/*!
* \brief CopyElement
* \param pSrc
* \param pDest
*/
void CopyElement(CBotString* pSrc, CBotString* pDest);
/*!
* \brief ConstructElements
* \param pNewData
* \param nCount
*/
void ConstructElements(CBotString* pNewData, int nCount);
/*!
* \brief DestructElements
* \param pOldData
* \param nCount
*/
void DestructElements(CBotString* pOldData, int nCount);
/*! /*!
* \brief GetNumInt Converts a string into integer may be of the form 0xabc123. * \brief GetNumInt Converts a string into integer may be of the form 0xabc123.
* \param p * \param p
* \return * \return
*/ */
long GetNumInt(const char* p); long GetNumInt(const std::string& p);
/*! /*!
* \brief GetNumFloat Converts a string into a float number. * \brief GetNumFloat Converts a string into a float number.
* \param p * \param p
* \return * \return
*/ */
float GetNumFloat(const char* p); float GetNumFloat(const std::string& str);

View File

@ -41,6 +41,7 @@
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
#include <string>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
long CBotVar::m_identcpt = 0; long CBotVar::m_identcpt = 0;
@ -71,7 +72,7 @@ CBotVar::~CBotVar( )
void CBotVar::debug() void CBotVar::debug()
{ {
// const char* p = static_cast<const char*>( m_token->GetString()); // const char* p = static_cast<const char*>( m_token->GetString());
CBotString s = static_cast<const char*>( GetValString()); std::string s = GetValString();
// const char* v = static_cast<const char*> (s); // const char* v = static_cast<const char*> (s);
if ( m_type.Eq(CBotTypClass) ) if ( m_type.Eq(CBotTypClass) )
@ -221,7 +222,7 @@ CBotVar* CBotVar::Create( CBotVar* pVar )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotVar::Create( const char* n, CBotTypResult type) CBotVar* CBotVar::Create(const std::string& n, CBotTypResult type)
{ {
CBotToken name(n); CBotToken name(n);
@ -286,7 +287,7 @@ CBotVar* CBotVar::Create( const char* n, CBotTypResult type)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass) CBotVar* CBotVar::Create(const std::string& name, int type, CBotClass* pClass)
{ {
CBotToken token( name, "" ); CBotToken token( name, "" );
CBotVar* pVar = Create( &token, type ); CBotVar* pVar = Create( &token, type );
@ -308,7 +309,7 @@ CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotVar::Create( const char* name, CBotClass* pClass) CBotVar* CBotVar::Create(const std::string& name, CBotClass* pClass)
{ {
CBotToken token( name, "" ); CBotToken token( name, "" );
CBotVar* pVar = Create( &token, CBotTypResult( CBotTypClass, pClass ) ); CBotVar* pVar = Create( &token, CBotTypResult( CBotTypClass, pClass ) );
@ -390,13 +391,13 @@ void CBotVar::SetInit(CBotVar::InitType bInit)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVar::GetName() std::string CBotVar::GetName()
{ {
return m_token->GetString(); return m_token->GetString();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVar::SetName(const char* name) void CBotVar::SetName(const std::string& name)
{ {
m_token->SetString(name); m_token->SetString(name);
} }
@ -408,7 +409,7 @@ CBotToken* CBotVar::GetToken()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotVar::GetItem(const char* name) CBotVar* CBotVar::GetItem(const std::string& name)
{ {
assert(0); assert(0);
return nullptr; return nullptr;
@ -436,7 +437,7 @@ CBotVar* CBotVar::GetItem(int row, bool bGrow)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotVar::IsElemOfClass(const char* name) bool CBotVar::IsElemOfClass(const std::string& name)
{ {
CBotClass* pc = nullptr; CBotClass* pc = nullptr;
@ -579,7 +580,7 @@ float CBotVar::GetValFloat()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVar::SetValInt(int c, const char* s) void CBotVar::SetValInt(int c, const std::string& s)
{ {
assert(0); assert(0);
} }
@ -737,16 +738,16 @@ void CBotVar::Copy(CBotVar* pSrc, bool bName)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVar::SetValString(const char* p) void CBotVar::SetValString(const std::string& p)
{ {
assert(0); assert(0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVar::GetValString() std::string CBotVar::GetValString()
{ {
assert(0); assert(0);
return CBotString(); return std::string();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -21,16 +21,18 @@
// Modules inlcude // Modules inlcude
#include "CBot/CBotDefines.h" #include "CBot/CBotDefines.h"
#include "CBot/CBotTypResult.h"
#include "CBot/CBotString.h"
// Local include // Local include
// Global include // Global include
#include <string>
// Forward declaration // Forward declaration
class CBotVarClass; class CBotVarClass;
class CBotInstr; class CBotInstr;
class CBotClass;
class CBotToken;
/*! /*!
* \brief The CBotVar class Class for managing variables. May be useful to the * \brief The CBotVar class Class for managing variables. May be useful to the
@ -68,7 +70,7 @@ public:
* \param type * \param type
* \return * \return
*/ */
static CBotVar* Create( const char* name, CBotTypResult type); static CBotVar* Create(const std::string& name, CBotTypResult type);
/*! /*!
* \brief Create Creates from one instance of a known class. * \brief Create Creates from one instance of a known class.
@ -76,7 +78,7 @@ public:
* \param pClass * \param pClass
* \return * \return
*/ */
static CBotVar* Create( const char* name, CBotClass* pClass); static CBotVar* Create(const std::string& name, CBotClass* pClass);
/*! /*!
* \brief Create Creates a variable depending on its type. * \brief Create Creates a variable depending on its type.
@ -101,7 +103,7 @@ public:
* \param pClass * \param pClass
* \return * \return
*/ */
static CBotVar* Create( const char* name, int type, CBotClass* pClass); static CBotVar* Create(const std::string& name, int type, CBotClass* pClass);
/*! /*!
* \brief Create * \brief Create
@ -139,13 +141,13 @@ public:
* \brief GetName The name of the variable, if known. * \brief GetName The name of the variable, if known.
* \return * \return
*/ */
CBotString GetName(); std::string GetName();
/*! /*!
* \brief SetName Changes the name of the variable * \brief SetName Changes the name of the variable
* \param name * \param name
*/ */
void SetName(const char* name); void SetName(const std::string& name);
/*! /*!
* \brief GetType Returns the base type (int) of the variable * \brief GetType Returns the base type (int) of the variable
@ -251,7 +253,7 @@ public:
* \param name * \param name
* \return * \return
*/ */
virtual CBotVar* GetItem(const char* name); virtual CBotVar* GetItem(const std::string& name);
/*! /*!
* \brief GetItemRef * \brief GetItemRef
@ -287,7 +289,7 @@ public:
* \param name * \param name
* \return * \return
*/ */
bool IsElemOfClass(const char* name); bool IsElemOfClass(const std::string& name);
/*! /*!
* \brief GetNext Next variable in the list (parameters). * \brief GetNext Next variable in the list (parameters).
@ -313,7 +315,7 @@ public:
* \param val * \param val
* \param name * \param name
*/ */
virtual void SetValInt(int val, const char* name = nullptr); virtual void SetValInt(int val, const std::string& name = "");
/*! /*!
* \brief SetValFloat Initialized with a real value (#). * \brief SetValFloat Initialized with a real value (#).
@ -325,7 +327,7 @@ public:
* \brief SetValString Initialized with a string value (#). * \brief SetValString Initialized with a string value (#).
* \param p * \param p
*/ */
virtual void SetValString(const char* p); virtual void SetValString(const std::string& p);
/*! /*!
* \brief GetValInt Request the full value (#). * \brief GetValInt Request the full value (#).
@ -343,7 +345,7 @@ public:
* \brief GetValString Request the string value (#). * \brief GetValString Request the string value (#).
* \return * \return
*/ */
virtual CBotString GetValString(); virtual std::string GetValString();
/*! /*!
* \brief SetClass * \brief SetClass

View File

@ -131,9 +131,9 @@ CBotVar* CBotVarArray::GetItemList()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVarArray::GetValString() std::string CBotVarArray::GetValString()
{ {
if ( m_pInstance == nullptr ) return ( CBotString( "Null pointer" ) ) ; if ( m_pInstance == nullptr ) return ( std::string( "Null pointer" ) ) ;
return m_pInstance->GetValString(); return m_pInstance->GetValString();
} }

View File

@ -86,7 +86,7 @@ public:
* \brief GetValString Gets the contents of the array into a string. * \brief GetValString Gets the contents of the array into a string.
* \return * \return
*/ */
CBotString GetValString() override; std::string GetValString() override;
/*! /*!
* \brief Save1State * \brief Save1State

View File

@ -64,7 +64,7 @@ void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarBoolean::SetValInt(int val, const char* s) void CBotVarBoolean::SetValInt(int val, const std::string& s)
{ {
m_val = static_cast<bool>(val); m_val = static_cast<bool>(val);
m_binit = CBotVar::InitType::DEF; m_binit = CBotVar::InitType::DEF;
@ -90,11 +90,11 @@ float CBotVarBoolean::GetValFloat()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVarBoolean::GetValString() std::string CBotVarBoolean::GetValString()
{ {
CBotString ret; std::string ret;
CBotString res; std::string res;
if ( m_binit == CBotVar::InitType::UNDEF ) if ( m_binit == CBotVar::InitType::UNDEF )
{ {

View File

@ -47,7 +47,7 @@ public:
* \param val * \param val
* \param s * \param s
*/ */
void SetValInt(int val, const char* s = nullptr) override; void SetValInt(int val, const std::string& s = nullptr) override;
/*! /*!
* \brief SetValFloat * \brief SetValFloat
@ -71,7 +71,7 @@ public:
* \brief GetValString * \brief GetValString
* \return * \return
*/ */
CBotString GetValString() override; std::string GetValString() override;
/*! /*!
* \brief Copy Copy a variable into another. * \brief Copy Copy a variable into another.

View File

@ -268,7 +268,7 @@ void CBotVarClass::Maj(void* pUser, bool bContinu)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotVarClass::GetItem(const char* name) CBotVar* CBotVarClass::GetItem(const std::string& name)
{ {
CBotVar* p = m_pVar; CBotVar* p = m_pVar;
@ -335,15 +335,15 @@ CBotVar* CBotVarClass::GetItemList()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVarClass::GetValString() std::string CBotVarClass::GetValString()
{ {
// if ( m_Indirect != nullptr) return m_Indirect->GetValString(); // if ( m_Indirect != nullptr) return m_Indirect->GetValString();
CBotString res; std::string res;
if ( m_pClass != nullptr ) // not used for an array if ( m_pClass != nullptr ) // not used for an array
{ {
res = m_pClass->GetName() + CBotString("( "); res = m_pClass->GetName() + std::string("( ");
CBotVarClass* my = this; CBotVarClass* my = this;
while ( my != nullptr ) while ( my != nullptr )
@ -351,7 +351,7 @@ CBotString CBotVarClass::GetValString()
CBotVar* pv = my->m_pVar; CBotVar* pv = my->m_pVar;
while ( pv != nullptr ) while ( pv != nullptr )
{ {
res += pv->GetName() + CBotString("="); res += pv->GetName() + std::string("=");
if ( pv->IsStatic() ) if ( pv->IsStatic() )
{ {
@ -423,7 +423,7 @@ void CBotVarClass::DecrementUse()
pThis->SetPointer(this); pThis->SetPointer(this);
CBotVar* pResult = nullptr; CBotVar* pResult = nullptr;
CBotString nom = CBotString("~") + m_pClass->GetName(); std::string nom = std::string("~") + m_pClass->GetName();
long ident = 0; long ident = 0;
while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end

View File

@ -70,7 +70,7 @@ public:
* \param name * \param name
* \return * \return
*/ */
CBotVar* GetItem(const char* name) override; CBotVar* GetItem(const std::string& name) override;
/*! /*!
* \brief GetItemRef * \brief GetItemRef
@ -98,7 +98,7 @@ public:
* \brief GetValString * \brief GetValString
* \return * \return
*/ */
CBotString GetValString() override; std::string GetValString() override;
/*! /*!
* \brief Save1State * \brief Save1State

View File

@ -67,7 +67,7 @@ void CBotVarFloat::Copy(CBotVar* pSrc, bool bName)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarFloat::SetValInt(int val, const char* s) void CBotVarFloat::SetValInt(int val, const std::string& s)
{ {
m_val = static_cast<float>(val); m_val = static_cast<float>(val);
m_binit = CBotVar::InitType::DEF; m_binit = CBotVar::InitType::DEF;
@ -93,9 +93,9 @@ float CBotVarFloat::GetValFloat()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVarFloat::GetValString() std::string CBotVarFloat::GetValString()
{ {
CBotString res; std::string res;
if ( m_binit == CBotVar::InitType::UNDEF ) if ( m_binit == CBotVar::InitType::UNDEF )
{ {

View File

@ -45,7 +45,7 @@ public:
* \param val * \param val
* \param s * \param s
*/ */
void SetValInt(int val, const char* s = nullptr) override; void SetValInt(int val, const std::string& s = nullptr) override;
/*! /*!
* \brief SetValFloat * \brief SetValFloat
@ -69,7 +69,7 @@ public:
* \brief GetValString * \brief GetValString
* \return * \return
*/ */
CBotString GetValString() override; std::string GetValString() override;
/*! /*!
* \brief Copy Copy a variable into another. * \brief Copy Copy a variable into another.

View File

@ -66,7 +66,7 @@ void CBotVarInt::Copy(CBotVar* pSrc, bool bName)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::SetValInt(int val, const char* defnum) void CBotVarInt::SetValInt(int val, const std::string& defnum)
{ {
m_val = val; m_val = val;
m_binit = CBotVar::InitType::DEF; m_binit = CBotVar::InitType::DEF;
@ -93,11 +93,11 @@ float CBotVarInt::GetValFloat()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVarInt::GetValString() std::string CBotVarInt::GetValString()
{ {
if ( !m_defnum.IsEmpty() ) return m_defnum; if ( !m_defnum.empty() ) return m_defnum;
CBotString res; std::string res;
if ( m_binit == CBotVar::InitType::UNDEF ) if ( m_binit == CBotVar::InitType::UNDEF )
{ {
@ -216,27 +216,27 @@ void CBotVarInt::SR(CBotVar* left, CBotVar* right)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Neg() void CBotVarInt::Neg()
{ {
m_val = -m_val; m_val = -m_val;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Not() void CBotVarInt::Not()
{ {
m_val = ~m_val; m_val = ~m_val;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Inc() void CBotVarInt::Inc()
{ {
m_val++; m_val++;
m_defnum.Empty(); m_defnum.empty();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Dec() void CBotVarInt::Dec()
{ {
m_val--; m_val--;
m_defnum.Empty(); m_defnum.empty();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -278,7 +278,7 @@ bool CBotVarInt::Ne(CBotVar* left, CBotVar* right)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotVarInt::Save0State(FILE* pf) bool CBotVarInt::Save0State(FILE* pf)
{ {
if ( !m_defnum.IsEmpty() ) if ( !m_defnum.empty() )
{ {
if(!WriteWord(pf, 200 )) return false; // special marker if(!WriteWord(pf, 200 )) return false; // special marker
if(!WriteString(pf, m_defnum)) return false; // name of the value if(!WriteString(pf, m_defnum)) return false; // name of the value

View File

@ -45,7 +45,7 @@ public:
* \param val * \param val
* \param s * \param s
*/ */
void SetValInt(int val, const char* s = nullptr) override; void SetValInt(int val, const std::string& s = nullptr) override;
/*! /*!
* \brief SetValFloat * \brief SetValFloat
@ -69,7 +69,7 @@ public:
* \brief GetValString * \brief GetValString
* \return * \return
*/ */
CBotString GetValString() override; std::string GetValString() override;
/*! /*!
* \brief Copy Copy a variable in to another. * \brief Copy Copy a variable in to another.
@ -250,6 +250,6 @@ private:
//! The value. //! The value.
int m_val; int m_val;
//! The name if given by DefineNum. //! The name if given by DefineNum.
CBotString m_defnum; std::string m_defnum;
friend class CBotVar; friend class CBotVar;
}; };

View File

@ -23,9 +23,9 @@
#include "CBot/CBotClass.h" #include "CBot/CBotClass.h"
#include "CBot/CBotVar/CBotVarClass.h" #include "CBot/CBotVar/CBotVarClass.h"
#include "CBot/CBotFileUtils.h"
#include "CBot/CBotEnums.h" #include "CBot/CBotEnums.h"
#include "CBot/CBotUtils.h"
#include "CBot/CBotFileUtils.h"
// Local include // Local include
@ -71,7 +71,7 @@ void CBotVarPointer::Maj(void* pUser, bool bContinu)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotVarPointer::GetItem(const char* name) CBotVar* CBotVarPointer::GetItem(const std::string& name)
{ {
if ( m_pVarClass == nullptr) // no existing instance? if ( m_pVarClass == nullptr) // no existing instance?
return m_pClass->GetItem(name); // makes the pointer in the class itself return m_pClass->GetItem(name); // makes the pointer in the class itself
@ -96,9 +96,9 @@ CBotVar* CBotVarPointer::GetItemList()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVarPointer::GetValString() std::string CBotVarPointer::GetValString()
{ {
CBotString s = "Pointer to "; std::string s = "Pointer to ";
if ( m_pVarClass == nullptr ) s = "Null pointer" ; if ( m_pVarClass == nullptr ) s = "Null pointer" ;
else s += m_pVarClass->GetValString(); else s += m_pVarClass->GetValString();
return s; return s;

View File

@ -71,7 +71,7 @@ public:
* \param name * \param name
* \return * \return
*/ */
CBotVar* GetItem(const char* name) override; CBotVar* GetItem(const std::string& name) override;
/*! /*!
* \brief GetItemRef * \brief GetItemRef
@ -90,7 +90,7 @@ public:
* \brief GetValString * \brief GetValString
* \return * \return
*/ */
CBotString GetValString() override; std::string GetValString() override;
/*! /*!
* \brief SetPointer Initializes the pointer to the instance of a class. * \brief SetPointer Initializes the pointer to the instance of a class.

View File

@ -43,7 +43,7 @@ CBotVarString::CBotVarString( const CBotToken* name )
m_bStatic = false; m_bStatic = false;
m_mPrivate = 0; m_mPrivate = 0;
m_val.Empty(); m_val.clear();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -65,14 +65,14 @@ void CBotVarString::Copy(CBotVar* pSrc, bool bName)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotVarString::SetValString(const char* p) void CBotVarString::SetValString(const std::string& p)
{ {
m_val = p; m_val = p;
m_binit = CBotVar::InitType::DEF; m_binit = CBotVar::InitType::DEF;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotString CBotVarString::GetValString() std::string CBotVarString::GetValString()
{ {
if ( m_binit == CBotVar::InitType::UNDEF ) if ( m_binit == CBotVar::InitType::UNDEF )
{ {

View File

@ -44,13 +44,13 @@ public:
* \brief SetValString * \brief SetValString
* \param p * \param p
*/ */
void SetValString(const char* p) override; void SetValString(const std::string& p) override;
/*! /*!
* \brief GetValString * \brief GetValString
* \return * \return
*/ */
CBotString GetValString() override; std::string GetValString() override;
/*! /*!
* \brief Copy Copy a variable into another. * \brief Copy Copy a variable into another.
@ -123,5 +123,5 @@ public:
private: private:
//! The value. //! The value.
CBotString m_val; std::string m_val;
}; };

View File

@ -5,12 +5,12 @@ set(SOURCES
CBotProgram.cpp CBotProgram.cpp
CBotStack.cpp CBotStack.cpp
CBotCStack.cpp CBotCStack.cpp
CBotString.cpp
CBotToken.cpp CBotToken.cpp
CBotCall.cpp CBotCall.cpp
CBotDefParam.cpp CBotDefParam.cpp
CBotCallMethode.cpp CBotCallMethode.cpp
CBotTypResult.cpp CBotTypResult.cpp
CBotKeywordStrings.cpp
StringFunctions.cpp StringFunctions.cpp
CBotInstr/CBotInstr.cpp CBotInstr/CBotInstr.cpp
CBotInstr/CBotInstrUtils.cpp CBotInstr/CBotInstrUtils.cpp
@ -67,7 +67,7 @@ set(SOURCES
CBotVar/CBotVarFloat.cpp CBotVar/CBotVarFloat.cpp
CBotVar/CBotVarInt.cpp CBotVar/CBotVarInt.cpp
CBotVar/CBotVar.cpp CBotVar/CBotVar.cpp
CBotKeywordStrings.cpp CBotKeywordStrings.h) )
# Includes # Includes
set(LOCAL_INCLUDES set(LOCAL_INCLUDES

View File

@ -24,11 +24,13 @@
#include "CBot/CBotEnums.h" #include "CBot/CBotEnums.h"
#include "CBot/CBotVar/CBotVar.h" #include "CBot/CBotVar/CBotVar.h"
#include "CBot/CBotUtils.h"
// Local include // Local include
// Global include // Global include
#include <boost/algorithm/string.hpp>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
@ -43,10 +45,10 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// puts the length of the stack // puts the length of the stack
pResult->SetValInt( s.GetLength() ); pResult->SetValInt( s.length() );
return true; return true;
} }
@ -77,7 +79,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// it takes a second parameter // it takes a second parameter
pVar = pVar->GetNext(); pVar = pVar->GetNext();
@ -93,7 +95,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part // takes the interesting part
s = s.Left( n ); s = s.substr(0, n);
// puts on the stack // puts on the stack
pResult->SetValString( s ); pResult->SetValString( s );
@ -135,7 +137,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// it takes a second parameter // it takes a second parameter
pVar = pVar->GetNext(); pVar = pVar->GetNext();
@ -151,7 +153,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part // takes the interesting part
s = s.Right( n ); s = s.substr(s.length()-n, std::string::npos);
// puts on the stack // puts on the stack
pResult->SetValString( s ); pResult->SetValString( s );
@ -168,7 +170,7 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// it takes a second parameter // it takes a second parameter
pVar = pVar->GetNext(); pVar = pVar->GetNext();
@ -195,12 +197,12 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
// takes the interesting part // takes the interesting part
s = s.Mid( n, l ); s = s.substr(n, l);
} }
else else
{ {
// takes the interesting part // takes the interesting part
s = s.Mid( n ); s = s.substr(n);
} }
// puts on the stack // puts on the stack
@ -253,7 +255,7 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// but no second parameter // but no second parameter
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
@ -292,7 +294,7 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// it takes a second parameter // it takes a second parameter
pVar = pVar->GetNext(); pVar = pVar->GetNext();
@ -302,14 +304,14 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// retrieves this number // retrieves this number
CBotString s2 = pVar->GetValString(); std::string s2 = pVar->GetValString();
// no third parameter // no third parameter
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// puts the result on the stack // puts the result on the stack
int res = s.Find(s2); std::size_t res = s.find(s2);
pResult->SetValInt( res ); pResult->SetValInt( res != std::string::npos ? res : -1 );
if ( res < 0 ) pResult->SetInit( CBotVar::InitType::IS_NAN ); if ( res < 0 ) pResult->SetInit( CBotVar::InitType::IS_NAN );
return true; return true;
} }
@ -349,13 +351,13 @@ bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// but no second parameter // but no second parameter
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
s.MakeUpper(); boost::to_upper(s);
// puts the value on the stack // puts the value on the stack
pResult->SetValString( s ); pResult->SetValString( s );
@ -372,13 +374,13 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string // get the contents of the string
CBotString s = pVar->GetValString(); std::string s = pVar->GetValString();
// but no second parameter // but no second parameter
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
s.MakeLower(); boost::to_lower(s);
// puts the value on the stack // puts the value on the stack
pResult->SetValString( s ); pResult->SetValString( s );

View File

@ -158,8 +158,8 @@ bool CScript::CheckToken()
{ {
CBotToken* bt; CBotToken* bt;
CBotToken* allBt; CBotToken* allBt;
CBotString bs; std::string bs;
const char* token; std::string token;
int error, cursor1, cursor2, i; int error, cursor1, cursor2, i;
char used[100]; char used[100];
@ -186,13 +186,13 @@ bool CScript::CheckToken()
cursor1 = bt->GetStart(); cursor1 = bt->GetStart();
cursor2 = bt->GetEnd(); cursor2 = bt->GetEnd();
i = m_main->IsObligatoryToken(token); i = m_main->IsObligatoryToken(token.c_str());
if ( i != -1 ) if ( i != -1 )
{ {
used[i] = 1; // token used used[i] = 1; // token used
} }
if ( !m_main->IsProhibitedToken(token) ) if ( !m_main->IsProhibitedToken(token.c_str()) )
{ {
m_error = ERR_PROHIBITEDTOKEN; m_error = ERR_PROHIBITEDTOKEN;
m_cursor1 = cursor1; m_cursor1 = cursor1;
@ -228,9 +228,9 @@ bool CScript::CheckToken()
bool CScript::Compile() bool CScript::Compile()
{ {
std::vector<CBotString> functionList; std::vector<std::string> functionList;
int i; int i;
const char* p; std::string p;
m_error = 0; m_error = 0;
m_cursor1 = 0; m_cursor1 = 0;
@ -486,8 +486,7 @@ bool CScript::IsContinue()
bool CScript::GetCursor(int &cursor1, int &cursor2) bool CScript::GetCursor(int &cursor1, int &cursor2)
{ {
const char* funcName; std::string funcName;
cursor1 = cursor2 = 0; cursor1 = cursor2 = 0;
if (m_botProg == nullptr) return false; if (m_botProg == nullptr) return false;
@ -508,11 +507,10 @@ bool CScript::GetCursor(int &cursor1, int &cursor2)
void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, int &rankList) void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, int &rankList)
{ {
CBotString bs;
CBotVar *svar, *pStatic; CBotVar *svar, *pStatic;
char varName[100]; char varName[100];
char buffer[100]; char buffer[100];
const char *p; std::string p;
int index, type; int index, type;
if ( var == nullptr && baseName[0] != 0 ) if ( var == nullptr && baseName[0] != 0 )
@ -528,8 +526,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
var->Maj(nullptr, false); var->Maj(nullptr, false);
pStatic = var->GetStaticVar(); // finds the static element pStatic = var->GetStaticVar(); // finds the static element
bs = pStatic->GetName(); // variable name p = pStatic->GetName(); // variable name
p = bs;
//? if ( strcmp(p, "this") == 0 ) //? if ( strcmp(p, "this") == 0 )
//? { //? {
//? var = var->GetNext(); //? var = var->GetNext();
@ -538,7 +535,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
if ( baseName[0] == 0 ) if ( baseName[0] == 0 )
{ {
sprintf(varName, "%s", p); sprintf(varName, "%s", p.c_str());
} }
else else
{ {
@ -548,7 +545,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
} }
else else
{ {
sprintf(varName, "%s.%s", baseName, p); sprintf(varName, "%s.%s", baseName, p.c_str());
} }
} }
@ -556,18 +553,14 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
if ( type < CBotTypBoolean ) if ( type < CBotTypBoolean )
{ {
CBotString value; p = pStatic->GetValString();
value = pStatic->GetValString(); sprintf(buffer, "%s = %s;", varName, p.c_str());
p = value;
sprintf(buffer, "%s = %s;", varName, p);
list->SetItemName(rankList++, buffer); list->SetItemName(rankList++, buffer);
} }
else if ( type == CBotTypString ) else if ( type == CBotTypString )
{ {
CBotString value; p = pStatic->GetValString();
value = pStatic->GetValString(); sprintf(buffer, "%s = \"%s\";", varName, p.c_str());
p = value;
sprintf(buffer, "%s = \"%s\";", varName, p);
list->SetItemName(rankList++, buffer); list->SetItemName(rankList++, buffer);
} }
else if ( type == CBotTypArrayPointer ) else if ( type == CBotTypArrayPointer )
@ -597,7 +590,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
void CScript::UpdateList(Ui::CList* list) void CScript::UpdateList(Ui::CList* list)
{ {
CBotVar *var; CBotVar *var;
const char *progName, *funcName; std::string progName, funcName;
int total, select, level, cursor1, cursor2, rank; int total, select, level, cursor1, cursor2, rank;
if (m_botProg == nullptr) return; if (m_botProg == nullptr) return;
@ -607,7 +600,7 @@ void CScript::UpdateList(Ui::CList* list)
list->Flush(); // empty list list->Flush(); // empty list
m_botProg->GetRunPos(progName, cursor1, cursor2); m_botProg->GetRunPos(progName, cursor1, cursor2);
if ( progName == nullptr ) return; if ( progName.empty() ) return;
level = 0; level = 0;
rank = 0; rank = 0;
@ -646,8 +639,7 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd)
CBotToken* bt = CBotToken::CompileTokens(text.c_str(), error); CBotToken* bt = CBotToken::CompileTokens(text.c_str(), error);
while ( bt != nullptr ) while ( bt != nullptr )
{ {
CBotString bs = bt->GetString(); std::string token = bt->GetString();
const char* token = bs;
int type = bt->GetType(); int type = bt->GetType();
int cursor1 = bt->GetStart(); int cursor1 = bt->GetStart();
@ -659,15 +651,15 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd)
cursor2 += rangeStart; cursor2 += rangeStart;
Gfx::FontHighlight color = Gfx::FONT_HIGHLIGHT_NONE; Gfx::FontHighlight color = Gfx::FONT_HIGHLIGHT_NONE;
if ((type == TokenTypVar || (type >= TokenKeyWord && type < TokenKeyWord+100)) && IsType(token)) // types (basic types are TokenKeyWord, classes are TokenTypVar) if ((type == TokenTypVar || (type >= TokenKeyWord && type < TokenKeyWord+100)) && IsType(token.c_str())) // types (basic types are TokenKeyWord, classes are TokenTypVar)
{ {
color = Gfx::FONT_HIGHLIGHT_TYPE; color = Gfx::FONT_HIGHLIGHT_TYPE;
} }
else if (type == TokenTypVar && IsFunction(token)) // functions else if (type == TokenTypVar && IsFunction(token.c_str())) // functions
{ {
color = Gfx::FONT_HIGHLIGHT_TOKEN; color = Gfx::FONT_HIGHLIGHT_TOKEN;
} }
else if (type == TokenTypVar && (strcmp(token, "this") == 0 || strcmp(token, "super") == 0)) // this, super else if (type == TokenTypVar && (token == "this" || token == "super")) // this, super
{ {
color = Gfx::FONT_HIGHLIGHT_THIS; color = Gfx::FONT_HIGHLIGHT_THIS;
} }

View File

@ -473,7 +473,7 @@ CBotTypResult CScriptFunctions::cPlayMusic(CBotVar* &var, void* user)
bool CScriptFunctions::rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user) bool CScriptFunctions::rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user)
{ {
std::string filename; std::string filename;
CBotString cbs; std::string cbs;
bool repeat; bool repeat;
cbs = var->GetValString(); cbs = var->GetValString();
@ -703,13 +703,9 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul
ObjectType type = static_cast<ObjectType>(var->GetValInt()); ObjectType type = static_cast<ObjectType>(var->GetValInt());
var = var->GetNext(); var = var->GetNext();
CBotString cbs; std::string program;
const char* program;
if ( var != nullptr ) if ( var != nullptr )
{ program = var->GetValString();
cbs = var->GetValString();
program = cbs;
}
else else
program = ""; program = "";
@ -1584,8 +1580,7 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
if ( var != nullptr ) if ( var != nullptr )
{ {
CBotString cbs = var->GetValString(); name = var->GetValString();
name = static_cast<const char*>(cbs);
var = var->GetNext(); var = var->GetNext();
if ( var != nullptr ) if ( var != nullptr )
{ {
@ -2225,17 +2220,15 @@ CBotTypResult CScriptFunctions::cReceive(CBotVar* &var, void* user)
bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user) bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user)
{ {
CScript* script = static_cast<CScript*>(user); CScript* script = static_cast<CScript*>(user);
CBotString cbs;
Error err; Error err;
const char* p; std::string p;
float power; float power;
exception = 0; exception = 0;
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress? if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
{ {
cbs = var->GetValString(); p = var->GetValString();
p = cbs;
var = var->GetNext(); var = var->GetNext();
power = 10.0f*g_unit; power = 10.0f*g_unit;
@ -2245,7 +2238,7 @@ bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, v
var = var->GetNext(); var = var->GetNext();
} }
err = script->m_taskExecutor->StartTaskInfo(p, 0.0f, power, false); err = script->m_taskExecutor->StartTaskInfo(p.c_str(), 0.0f, power, false);
if ( err != ERR_OK ) if ( err != ERR_OK )
{ {
script->m_taskExecutor->StopForegroundTask(); script->m_taskExecutor->StopForegroundTask();
@ -2294,17 +2287,15 @@ CBotTypResult CScriptFunctions::cSend(CBotVar* &var, void* user)
bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void* user) bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void* user)
{ {
CScript* script = static_cast<CScript*>(user); CScript* script = static_cast<CScript*>(user);
CBotString cbs;
Error err; Error err;
const char* p; std::string p;
float value, power; float value, power;
exception = 0; exception = 0;
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress? if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
{ {
cbs = var->GetValString(); p = var->GetValString();
p = cbs;
var = var->GetNext(); var = var->GetNext();
value = var->GetValFloat(); value = var->GetValFloat();
@ -2317,7 +2308,7 @@ bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void
var = var->GetNext(); var = var->GetNext();
} }
err = script->m_taskExecutor->StartTaskInfo(static_cast<const char*>(p), value, power, true); err = script->m_taskExecutor->StartTaskInfo(p.c_str(), value, power, true);
if ( err != ERR_OK ) if ( err != ERR_OK )
{ {
script->m_taskExecutor->StopForegroundTask(); script->m_taskExecutor->StopForegroundTask();
@ -2365,15 +2356,13 @@ bool CScriptFunctions::rDeleteInfo(CBotVar* var, CBotVar* result, int& exception
exception = 0; exception = 0;
CBotString infoNameCbs = var->GetValString(); std::string infoName = var->GetValString();
std::string infoName = std::string(static_cast<const char*>(infoNameCbs));
var = var->GetNext(); var = var->GetNext();
float power = 10.0f*g_unit; float power = 10.0f*g_unit;
if (var != nullptr) if (var != nullptr)
{ {
power = var->GetValFloat()*g_unit; power = var->GetValFloat()*g_unit;
var = var->GetNext();
} }
CExchangePost* exchangePost = FindExchangePost(pThis, power); CExchangePost* exchangePost = FindExchangePost(pThis, power);
@ -2413,15 +2402,13 @@ bool CScriptFunctions::rTestInfo(CBotVar* var, CBotVar* result, int& exception,
exception = 0; exception = 0;
CBotString infoNameCbs = var->GetValString(); std::string infoName = var->GetValString();
std::string infoName = std::string(static_cast<const char*>(infoNameCbs));
var = var->GetNext(); var = var->GetNext();
float power = 10.0f*g_unit; float power = 10.0f*g_unit;
if (var != nullptr) if (var != nullptr)
{ {
power = var->GetValFloat()*g_unit; power = var->GetValFloat()*g_unit;
var = var->GetNext();
} }
CExchangePost* exchangePost = FindExchangePost(pThis, power); CExchangePost* exchangePost = FindExchangePost(pThis, power);
@ -2813,12 +2800,10 @@ CBotTypResult CScriptFunctions::cMessage(CBotVar* &var, void* user)
bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user) bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user)
{ {
CScript* script = static_cast<CScript*>(user); CScript* script = static_cast<CScript*>(user);
CBotString cbs; std::string p;
const char* p;
Ui::TextType type; Ui::TextType type;
cbs = var->GetValString(); p = var->GetValString();
p = cbs;
type = Ui::TT_MESSAGE; type = Ui::TT_MESSAGE;
var = var->GetNext(); var = var->GetNext();
@ -2827,7 +2812,7 @@ bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, v
type = static_cast<Ui::TextType>(var->GetValInt()); type = static_cast<Ui::TextType>(var->GetValInt());
} }
script->m_main->GetDisplayText()->DisplayText(p, script->m_object, 10.0f, type); script->m_main->GetDisplayText()->DisplayText(p.c_str(), script->m_object, 10.0f, type);
return true; return true;
} }
@ -3157,22 +3142,22 @@ int CScriptFunctions::m_nextFile = 1;
// Prepares a file name. // Prepares a file name.
void PrepareFilename(CBotString &filename) void PrepareFilename(std::string &filename)
{ {
CResourceManager::CreateDirectory("files"); CResourceManager::CreateDirectory("files");
filename = CBotString("files/") + filename; filename = "files/" + filename;
GetLogger()->Debug("CBot accessing file '%s'\n", static_cast<const char*>(filename)); GetLogger()->Debug("CBot accessing file '%s'\n", filename.c_str());
} }
bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{ {
CBotString mode; std::string mode;
// must be a character string // must be a character string
if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString filename = pVar->GetValString(); std::string filename = pVar->GetValString();
PrepareFilename(filename); PrepareFilename(filename);
// there may be a second parameter // there may be a second parameter
@ -3196,20 +3181,20 @@ bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar*
// which must not be initialized // which must not be initialized
if ( pVar->IsDefined()) { Exception = CBotErrFileOpen; return false; } if ( pVar->IsDefined()) { Exception = CBotErrFileOpen; return false; }
if ( ! mode.IsEmpty() ) if ( !mode.empty() )
{ {
// opens the requested file // opens the requested file
bool ok = false; bool ok = false;
std::unique_ptr<std::ios> file; std::unique_ptr<std::ios> file;
if (mode == "r") if (mode == "r")
{ {
auto is = MakeUnique<CInputStream>(static_cast<const char*>(filename)); auto is = MakeUnique<CInputStream>(filename);
ok = is->is_open(); ok = is->is_open();
file = std::move(is); file = std::move(is);
} }
else if (mode == "w") else if (mode == "w")
{ {
auto os = MakeUnique<COutputStream>(static_cast<const char*>(filename)); auto os = MakeUnique<COutputStream>(filename);
ok = os->is_open(); ok = os->is_open();
file = std::move(os); file = std::move(os);
} }
@ -3396,7 +3381,7 @@ bool CScriptFunctions::rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult,
// which must be a character string // which must be a character string
if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString param = pVar->GetValString(); std::string param = pVar->GetValString();
// retrieve the item "handle" // retrieve the item "handle"
pVar = pThis->GetItem("handle"); pVar = pThis->GetItem("handle");
@ -3526,11 +3511,10 @@ CBotTypResult CScriptFunctions::cfeof (CBotVar* pThis, CBotVar* &pVar)
bool CScriptFunctions::rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user) bool CScriptFunctions::rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user)
{ {
CBotString cbs; std::string filename;
cbs = var->GetValString(); filename = var->GetValString();
PrepareFilename(cbs); PrepareFilename(filename);
std::string filename = static_cast<const char*>(cbs);
return CResourceManager::Remove(filename); return CResourceManager::Remove(filename);
} }
@ -3773,7 +3757,7 @@ void CScriptFunctions::Init()
bc->AddFunction("eof", CScriptFunctions::rfeof, CScriptFunctions::cfeof ); bc->AddFunction("eof", CScriptFunctions::rfeof, CScriptFunctions::cfeof );
//m_pFuncFile = new CBotProgram( ); //m_pFuncFile = new CBotProgram( );
//CBotStringArray ListFonctions; //std::stringArray ListFonctions;
//m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions); //m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
//m_pFuncFile->SetIdent(-2); // restoreState in special identifier for this function //m_pFuncFile->SetIdent(-2); // restoreState in special identifier for this function

View File

@ -18,8 +18,7 @@ CBotTypResult cMessage(CBotVar* &var, void* user)
bool rMessage(CBotVar* var, CBotVar* result, int& exception, void* user) bool rMessage(CBotVar* var, CBotVar* result, int& exception, void* user)
{ {
CBotString cbs = var->GetValString(); std::string message = var->GetValString();
const char* message = cbs; // Don't ask me why, but it doesn't work if you write it on a single line
std::cout << message << std::endl; std::cout << message << std::endl;
@ -44,7 +43,7 @@ int main(int argc, char* argv[])
CBotProgram::AddFunction("message", rMessage, cMessage); CBotProgram::AddFunction("message", rMessage, cMessage);
// Compile the program // Compile the program
std::vector<CBotString> externFunctions; std::vector<std::string> externFunctions;
std::unique_ptr<CBotProgram> program{new CBotProgram(nullptr)}; std::unique_ptr<CBotProgram> program{new CBotProgram(nullptr)};
if (!program->Compile(code.c_str(), externFunctions, nullptr)) if (!program->Compile(code.c_str(), externFunctions, nullptr))
{ {
@ -63,7 +62,7 @@ int main(int argc, char* argv[])
return 2; return 2;
} }
bool runErrors = false; bool runErrors = false;
for (const char* func : externFunctions) for (const std::string& func : externFunctions)
{ {
if (!program->Start(func)) if (!program->Start(func))
{ {

View File

@ -1,399 +0,0 @@
/*
* 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 "CBot/CBotString.h"
// Local include
// Global include
#include <gtest/gtest.h>
/**
* @brief CBotString_Test.Empty Check Empty and IsEmpty functions of class
* CBotString_Test.
*/
TEST(CBotString_Test, Empty)
{
CBotString str1;
EXPECT_EQ(true, str1.IsEmpty());
CBotString str2("qsexrdctfvygbuh");
EXPECT_EQ(false, str2.IsEmpty());
str2.Empty();
EXPECT_EQ(true, str2.IsEmpty());
}
/**
* @brief CBotString_Test.Length Check GetLength function of class
* CBotString_Test.
*/
TEST(CBotString_Test, Length)
{
CBotString str1;
EXPECT_EQ(0, str1.GetLength());
CBotString str2("a");
EXPECT_EQ(1, str2.GetLength());
CBotString str3("aaaaa");
EXPECT_EQ(5, str3.GetLength());
}
/**
* @brief CBotString_Test.Find Check find functions of class CBotString_Test
*/
TEST(CBotString_Test, Find)
{
CBotString str1("a");
EXPECT_EQ(0, str1.Find('a'));
CBotString str2("b");
EXPECT_EQ(-1, str2.Find('a'));
CBotString str3("bbabb");
EXPECT_EQ(2, str3.Find('a'));
CBotString str4("bbAbb");
EXPECT_EQ(-1, str4.Find('a'));
CBotString str5("bbAbb");
EXPECT_EQ(2, str5.Find('A'));
CBotString str6("test");
EXPECT_EQ(0, str6.Find("test"));
CBotString str7("azazdazd");
EXPECT_EQ(-1, str7.Find("test"));
CBotString str8("bbtestbb");
EXPECT_EQ(2, str8.Find("test"));
CBotString str9("bbTestbb");
EXPECT_EQ(-1, str9.Find("test"));
CBotString str10("bbTestbb");
EXPECT_EQ(2, str10.Find("Test"));
}
/**
* @brief CBotString_Test.ReverseFind Check find functions of class
* CBotString_Test
*/
TEST(CBotString_Test, ReverseFind)
{
CBotString str1("a");
EXPECT_EQ(0, str1.ReverseFind('a'));
CBotString str2("b");
EXPECT_EQ(-1, str2.ReverseFind('a'));
CBotString str3("bbabb");
EXPECT_EQ(2, str3.ReverseFind('a'));
CBotString str4("bbAbb");
EXPECT_EQ(-1, str4.ReverseFind('a'));
CBotString str5("bbAbb");
EXPECT_EQ(2, str5.ReverseFind('A'));
CBotString str6("test");
EXPECT_EQ(0, str6.ReverseFind("test"));
CBotString str7("azazdazd");
EXPECT_EQ(-1, str7.ReverseFind("test"));
CBotString str8("bbtestbb");
EXPECT_EQ(2, str8.ReverseFind("test"));
CBotString str9("bbTestbb");
EXPECT_EQ(-1, str9.ReverseFind("test"));
CBotString str10("bbTestbb");
EXPECT_EQ(2, str10.ReverseFind("Test"));
}
/**
* @brief CBotString_Test.Mid Check Mid functions of class CBotString_Test
*/
TEST(CBotString_Test, Mid)
{
CBotString str1("aaaColobot");
EXPECT_STREQ(str1.Mid(3).CStr(), "Colobot");
CBotString str2("aaaColobotaa");
EXPECT_STREQ(str2.Mid(3,7).CStr(), "Colobot");
}
/**
* @brief CBotString_Test.Left Check Left function of class CBotString_Test
*/
TEST(CBotString_Test, Left)
{
CBotString str1("Colobotaaa");
EXPECT_STREQ(str1.Left(7).CStr(), "Colobot");
}
/**
* @brief CBotString_Test.Right Check Right function of class CBotString_Test
*/
TEST(CBotString_Test, Right)
{
CBotString str1("aaaColobot");
EXPECT_STREQ(str1.Right(7).CStr(), "Colobot");
}
/**
* @brief CBotString_Test.MakeUpper Check MakeUpper function of class
* CBotString_Test
*/
TEST(CBotString_Test, MakeUpper)
{
CBotString str1("colobot");
str1.MakeUpper();
EXPECT_STREQ(str1.CStr(), "COLOBOT");
CBotString str2("Colobot");
str2.MakeUpper();
EXPECT_STREQ(str2.CStr(), "COLOBOT");
}
/**
* @brief CBotString_Test.MakeLower Check MakeLower function of class
* CBotString_Test
*/
TEST(CBotString_Test, MakeLower)
{
CBotString str1("COLOBOT");
str1.MakeLower();
EXPECT_STREQ(str1.CStr(), "colobot");
CBotString str2("Colobot");
str2.MakeLower();
EXPECT_STREQ(str2.CStr(), "colobot");
}
/**
* @brief CBotString_Test.operatorEqual Check operator equal of class
* CBotString_Test
*/
TEST(CBotString_Test, operatorEqual)
{
//-- CBotString
CBotString botStr1;
CBotString botStr2("Colobot");
//-- C Character
const char cStr1[2] = "C";
//-- C string
const char cStr2[8] = "Colobot";
//-- Compare with CBotString
botStr1 = botStr2;
EXPECT_STREQ(botStr1.CStr(), botStr2.CStr());
//-- Compare with C character
botStr1 = cStr1[0];
EXPECT_STREQ(botStr1.CStr(), cStr1);
//-- Compare with C string
botStr1 = cStr2;
EXPECT_STREQ(botStr1.CStr(), cStr2);
}
/**
* @brief CBotString_Test.operatorIsEqual Check operator is equal of class
* CBotString_Test
*/
TEST(CBotString_Test, operatorIsEqual)
{
//-- CBotString
CBotString botStr1("C");
CBotString botStr2("C");
CBotString botStr3("Colobot");
//-- C string
const char cStr1[8] = "Colobot";
const char cStr2[8] = "colobot";
EXPECT_EQ(true, (botStr1 == botStr2));
EXPECT_EQ(false, (botStr1 == botStr3));
//-- Compare with C string
EXPECT_EQ(true, (botStr3 == cStr1));
EXPECT_EQ(false, (botStr3 == cStr2));
}
/**
* @brief CBotString_Test.operatorAdd Check operator add of class
* CBotString_Test.
*/
TEST(CBotString_Test, operatorAdd)
{
//-- CBotString
CBotString botStr1;
CBotString botStr2("C");
CBotString botStr3("olobot");
CBotString botStr4("Colobot");
//-- C string
const char* cStr1 = "olobot";
botStr1 = botStr1 + botStr2;
botStr1 = botStr1 + botStr3;
EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
botStr1.Empty();
botStr1 = botStr2 + cStr1;
EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
botStr1.Empty();
botStr1 += botStr2;
botStr1 += botStr3;
EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
botStr1.Empty();
botStr1 += botStr2;
botStr1 += cStr1;
EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
}
/**
* @brief CBotString_Test.operatorDiff Check operator diff of class
* CBotString_Test.
*/
TEST(CBotString_Test, operatorDiff)
{
//-- CBotString
CBotString botStr1("C");
CBotString botStr2("C");
CBotString botStr3("Colobot");
//-- C string
const char cStr1[8] = "Colobot";
const char cStr2[8] = "colobot";
EXPECT_EQ(false, (botStr1 != botStr2));
EXPECT_EQ(true, (botStr1 != botStr3));
//-- Compare with C string
EXPECT_EQ(false, (botStr3 != cStr1));
EXPECT_EQ(true, (botStr3 != cStr2));
}
/**
* @brief CBotString_Test.operatorSuperior Check operator superior of class
* CBotString_Test.
*/
TEST(CBotString_Test, operatorSuperior)
{
//-- CBotString
CBotString botStr1("a");
CBotString botStr2("z");
CBotString botStr3("colobot");
//-- C string
const char cStr1[2] = "a";
const char cStr2[2] = "z";
EXPECT_EQ(true, (botStr3 > botStr1));
EXPECT_EQ(false, (botStr3 > botStr2));
//-- Compare with C string
EXPECT_EQ(true, (botStr3 > cStr1));
EXPECT_EQ(false, (botStr3 > cStr2));
}
/**
* @brief CBotString_Test.operatorSuperiorOrEqual Check operator superior or
* equa of class CBotString_Test.
*/
TEST(CBotString_Test, operatorSuperiorOrEqual)
{
//-- CBotString
CBotString botStr1("a");
CBotString botStr2("z");
CBotString botStr3("colobot");
//-- C string
const char cStr1[2] = "a";
const char cStr2[2] = "z";
const char cStr3[8] = "colobot";
EXPECT_EQ(true, (botStr3 >= botStr1));
EXPECT_EQ(false, (botStr3 >= botStr2));
EXPECT_EQ(true, (botStr3 >= botStr3));
//-- Compare with C string
EXPECT_EQ(true, (botStr3 >= cStr1));
EXPECT_EQ(false, (botStr3 >= cStr2));
EXPECT_EQ(true, (botStr3 >= cStr3));
}
/**
* @brief CBotString_Test.operatorInferior Check operator Inferior of class
* CBotString_Test.
*/
TEST(CBotString_Test, operatorInferior)
{
//-- CBotString
CBotString botStr1("a");
CBotString botStr2("z");
CBotString botStr3("colobot");
//-- C string
const char cStr1[2] = "a";
const char cStr2[2] = "z";
EXPECT_EQ(false, (botStr3 < botStr1));
EXPECT_EQ(true, (botStr3 < botStr2));
//-- Compare with C string
EXPECT_EQ(false, (botStr3 < cStr1));
EXPECT_EQ(true, (botStr3 < cStr2));
}
/**
* @brief CBotString_Test.operatorInferiorOrEqual Check operator Inferior or
* equa of class CBotString_Test.
*/
TEST(CBotString_Test, operatorInferiorOrEqual)
{
//-- CBotString
CBotString botStr1("a");
CBotString botStr2("z");
CBotString botStr3("colobot");
//-- C string
const char cStr1[2] = "a";
const char cStr2[2] = "z";
const char cStr3[8] = "colobot";
EXPECT_EQ(false, (botStr3 <= botStr1));
EXPECT_EQ(true, (botStr3 <= botStr2));
EXPECT_EQ(true, (botStr3 <= botStr3));
//-- Compare with C string
EXPECT_EQ(false, (botStr3 <= cStr1));
EXPECT_EQ(true, (botStr3 <= cStr2));
EXPECT_EQ(true, (botStr3 <= cStr3));
}

View File

@ -15,7 +15,6 @@ set(UT_SOURCES
math/geometry_test.cpp math/geometry_test.cpp
math/matrix_test.cpp math/matrix_test.cpp
math/vector_test.cpp math/vector_test.cpp
CBot/CBotString_test.cpp
${PLATFORM_TESTS} ${PLATFORM_TESTS}
) )