[colobot] 115/377: Moving CBotVarString class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:04 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 1b3b2ea5a1e4f3186f0e33f4f1eebce259e18f88
Author: Grunaka <dev at romainbreton.fr>
Date: Sun Nov 15 21:24:54 2015 +0100
Moving CBotVarString class in its own header and source files.
---
src/CBot/CBot.h | 29 --------
src/CBot/CBotProgram.cpp | 12 ----
src/CBot/CBotStack.cpp | 6 --
src/CBot/CBotUtils.cpp | 12 ++++
src/CBot/CBotUtils.h | 8 +++
src/CBot/CBotVar.cpp | 102 +--------------------------
src/CBot/CBotVar/CBotVarString.cpp | 139 +++++++++++++++++++++++++++++++++++++
src/CBot/CBotVar/CBotVarString.h | 127 +++++++++++++++++++++++++++++++++
src/CBot/CMakeLists.txt | 1 +
9 files changed, 288 insertions(+), 148 deletions(-)
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 13a1191..2c23fa7 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -316,35 +316,6 @@ public:
bool Save1State(FILE* pf) override;
};
-
-// class for management of strings (String)
-class CBotVarString : public CBotVar
-{
-private:
- CBotString m_val; // the value
-
-public:
- CBotVarString( const CBotToken* name );
-// ~CBotVarString();
-
- void SetValString(const char* p) override;
- CBotString GetValString() override;
-
- void Copy(CBotVar* pSrc, bool bName=true) override;
-
- void Add(CBotVar* left, CBotVar* right) override; // addition
-
- bool Lo(CBotVar* left, CBotVar* right) override;
- bool Hi(CBotVar* left, CBotVar* right) override;
- bool Ls(CBotVar* left, CBotVar* right) override;
- bool Hs(CBotVar* left, CBotVar* right) override;
- bool Eq(CBotVar* left, CBotVar* right) override;
- bool Ne(CBotVar* left, CBotVar* right) override;
-
- bool Save1State(FILE* pf) override;
-};
-
-
extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars);
extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 );
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 9817f37..9ce3595 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -433,18 +433,6 @@ bool ReadLong(FILE* pf, long& w)
}
////////////////////////////////////////////////////////////////////////////////
-bool WriteString(FILE* pf, CBotString s)
-{
- size_t lg1, lg2;
-
- lg1 = s.GetLength();
- if (!WriteWord(pf, lg1)) return false;
-
- lg2 = fwrite(s, 1, lg1, pf );
- return (lg1 == lg2);
-}
-
-////////////////////////////////////////////////////////////////////////////////
bool ReadString(FILE* pf, CBotString& s)
{
unsigned short w;
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 421bf5d..574c81c 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -997,12 +997,6 @@ bool CBotVarFloat::Save1State(FILE* pf)
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotVarString::Save1State(FILE* pf)
-{
- return WriteString(pf, m_val); // the value of the variable
-}
-
-////////////////////////////////////////////////////////////////////////////////
bool CBotVarClass::Save1State(FILE* pf)
{
if ( !WriteType(pf, m_type) ) return false;
diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp
index 3fe76d0..4596b6f 100644
--- a/src/CBot/CBotUtils.cpp
+++ b/src/CBot/CBotUtils.cpp
@@ -115,3 +115,15 @@ bool WriteWord(FILE* pf, unsigned short w)
return (lg == 1);
}
+
+////////////////////////////////////////////////////////////////////////////////
+bool WriteString(FILE* pf, CBotString s)
+{
+ size_t lg1, lg2;
+
+ lg1 = s.GetLength();
+ if (!WriteWord(pf, lg1)) return false;
+
+ lg2 = fwrite(s, 1, lg1, pf );
+ return (lg1 == lg2);
+}
diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h
index 47a83d7..000c90a 100644
--- a/src/CBot/CBotUtils.h
+++ b/src/CBot/CBotUtils.h
@@ -59,3 +59,11 @@ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type);
* \return
*/
bool WriteWord(FILE* pf, unsigned short w);
+
+/*!
+ * \brief WriteString
+ * \param pf
+ * \param s
+ * \return
+ */
+bool WriteString(FILE* pf, CBotString s);
diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp
index ce0c5f0..b87f718 100644
--- a/src/CBot/CBotVar.cpp
+++ b/src/CBot/CBotVar.cpp
@@ -31,6 +31,7 @@
#include "CBotVar/CBotVarPointer.h"
#include "CBotVar/CBotVarClass.h"
#include "CBotVar/CBotVarBoolean.h"
+#include "CBotVar/CBotVarString.h"
#include "CBotDefines.h"
#include "CBotClass.h"
@@ -87,22 +88,6 @@ CBotVarFloat::CBotVarFloat( const CBotToken* name )
m_val = 0;
}
-CBotVarString::CBotVarString( const CBotToken* name )
-{
- m_token = new CBotToken(name);
- m_next = nullptr;
- m_pMyThis = nullptr;
- m_pUserPtr = nullptr;
- m_InitExpr = nullptr;
- m_LimExpr = nullptr;
- m_type = CBotTypString;
- m_binit = InitType::UNDEF;
- m_bStatic = false;
- m_mPrivate = 0;
-
- m_val.Empty();
-}
-
CBotVar::~CBotVar( )
{
delete m_token;
@@ -1120,91 +1105,6 @@ bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right)
return left->GetValFloat() != right->GetValFloat();
}
-
-//////////////////////////////////////////////////////////////////////////////////////
-
-// copy a variable into another
-void CBotVarString::Copy(CBotVar* pSrc, bool bName)
-{
- CBotVarString* p = static_cast<CBotVarString*>(pSrc);
-
- if (bName) *m_token = *p->m_token;
- m_type = p->m_type;
- m_val = p->m_val;
- m_binit = p->m_binit;
-//- m_bStatic = p->m_bStatic;
- m_next = nullptr;
- m_pMyThis = nullptr;//p->m_pMyThis;
- m_pUserPtr = p->m_pUserPtr;
-
- // keeps indentificator the same (by default)
- if (m_ident == 0 ) m_ident = p->m_ident;
-}
-
-
-void CBotVarString::SetValString(const char* p)
-{
- m_val = p;
- m_binit = CBotVar::InitType::DEF;
-}
-
-CBotString CBotVarString::GetValString()
-{
- if ( m_binit == CBotVar::InitType::UNDEF )
- {
- CBotString res;
- res.LoadString(TX_UNDEF);
- return res;
- }
- if ( m_binit == CBotVar::InitType::IS_NAN )
- {
- CBotString res;
- res.LoadString(TX_NAN);
- return res;
- }
-
- return m_val;
-}
-
-
-void CBotVarString::Add(CBotVar* left, CBotVar* right)
-{
- m_val = left->GetValString() + right->GetValString();
- m_binit = CBotVar::InitType::DEF;
-}
-
-bool CBotVarString::Eq(CBotVar* left, CBotVar* right)
-{
- return (left->GetValString() == right->GetValString());
-}
-
-bool CBotVarString::Ne(CBotVar* left, CBotVar* right)
-{
- return (left->GetValString() != right->GetValString());
-}
-
-
-bool CBotVarString::Lo(CBotVar* left, CBotVar* right)
-{
- return (left->GetValString() == right->GetValString());
-}
-
-bool CBotVarString::Hi(CBotVar* left, CBotVar* right)
-{
- return (left->GetValString() == right->GetValString());
-}
-
-bool CBotVarString::Ls(CBotVar* left, CBotVar* right)
-{
- return (left->GetValString() == right->GetValString());
-}
-
-bool CBotVarString::Hs(CBotVar* left, CBotVar* right)
-{
- return (left->GetValString() == right->GetValString());
-}
-
-
////////////////////////////////////////////////////////////////
// copy a variable into another
diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp
new file mode 100644
index 0000000..7b74014
--- /dev/null
+++ b/src/CBot/CBotVar/CBotVarString.cpp
@@ -0,0 +1,139 @@
+/*
+ * 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 "CBotVarString.h"
+
+#include "CBotToken.h"
+
+#include "CBotUtils.h"
+
+// Local include
+
+// Global include
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVarString::CBotVarString( const CBotToken* name )
+{
+ m_token = new CBotToken(name);
+ m_next = nullptr;
+ m_pMyThis = nullptr;
+ m_pUserPtr = nullptr;
+ m_InitExpr = nullptr;
+ m_LimExpr = nullptr;
+ m_type = CBotTypString;
+ m_binit = InitType::UNDEF;
+ m_bStatic = false;
+ m_mPrivate = 0;
+
+ m_val.Empty();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotVarString::Copy(CBotVar* pSrc, bool bName)
+{
+ CBotVarString* p = static_cast<CBotVarString*>(pSrc);
+
+ if (bName) *m_token = *p->m_token;
+ m_type = p->m_type;
+ m_val = p->m_val;
+ m_binit = p->m_binit;
+//- m_bStatic = p->m_bStatic;
+ m_next = nullptr;
+ m_pMyThis = nullptr;//p->m_pMyThis;
+ m_pUserPtr = p->m_pUserPtr;
+
+ // keeps indentificator the same (by default)
+ if (m_ident == 0 ) m_ident = p->m_ident;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotVarString::SetValString(const char* p)
+{
+ m_val = p;
+ m_binit = CBotVar::InitType::DEF;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotString CBotVarString::GetValString()
+{
+ if ( m_binit == CBotVar::InitType::UNDEF )
+ {
+ CBotString res;
+ res.LoadString(TX_UNDEF);
+ return res;
+ }
+ if ( m_binit == CBotVar::InitType::IS_NAN )
+ {
+ CBotString res;
+ res.LoadString(TX_NAN);
+ return res;
+ }
+
+ return m_val;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotVarString::Add(CBotVar* left, CBotVar* right)
+{
+ m_val = left->GetValString() + right->GetValString();
+ m_binit = CBotVar::InitType::DEF;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarString::Eq(CBotVar* left, CBotVar* right)
+{
+ return (left->GetValString() == right->GetValString());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarString::Ne(CBotVar* left, CBotVar* right)
+{
+ return (left->GetValString() != right->GetValString());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarString::Lo(CBotVar* left, CBotVar* right)
+{
+ return (left->GetValString() == right->GetValString());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarString::Hi(CBotVar* left, CBotVar* right)
+{
+ return (left->GetValString() == right->GetValString());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarString::Ls(CBotVar* left, CBotVar* right)
+{
+ return (left->GetValString() == right->GetValString());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarString::Hs(CBotVar* left, CBotVar* right)
+{
+ return (left->GetValString() == right->GetValString());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotVarString::Save1State(FILE* pf)
+{
+ return WriteString(pf, m_val); // the value of the variable
+}
diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h
new file mode 100644
index 0000000..31c776e
--- /dev/null
+++ b/src/CBot/CBotVar/CBotVarString.h
@@ -0,0 +1,127 @@
+/*
+ * 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 "CBotDll.h"
+
+// Local include
+
+// Global include
+
+
+/*!
+ * \brief The CBotVarString class Class for management of strings (String).
+ */
+class CBotVarString : public CBotVar
+{
+public:
+
+ /*!
+ * \brief CBotVarString
+ * \param name
+ */
+ CBotVarString( const CBotToken* name );
+
+ /*!
+ * \brief SetValString
+ * \param p
+ */
+ void SetValString(const char* p) override;
+
+ /*!
+ * \brief GetValString
+ * \return
+ */
+ CBotString GetValString() override;
+
+ /*!
+ * \brief Copy Copy a variable into another.
+ * \param pSrc
+ * \param bName
+ */
+ void Copy(CBotVar* pSrc, bool bName=true) override;
+
+ /*!
+ * \brief Add
+ * \param left
+ * \param right
+ */
+ void Add(CBotVar* left, CBotVar* right) override;
+
+ /*!
+ * \brief Lo
+ * \param left
+ * \param right
+ * \return
+ */
+ bool Lo(CBotVar* left, CBotVar* right) override;
+
+ /*!
+ * \brief Hi
+ * \param left
+ * \param right
+ * \return
+ */
+ bool Hi(CBotVar* left, CBotVar* right) override;
+
+ /*!
+ * \brief Ls
+ * \param left
+ * \param right
+ * \return
+ */
+ bool Ls(CBotVar* left, CBotVar* right) override;
+
+ /*!
+ * \brief Hs
+ * \param left
+ * \param right
+ * \return
+ */
+ bool Hs(CBotVar* left, CBotVar* right) override;
+
+ /*!
+ * \brief Eq
+ * \param left
+ * \param right
+ * \return
+ */
+ bool Eq(CBotVar* left, CBotVar* right) override;
+
+ /*!
+ * \brief Ne
+ * \param left
+ * \param right
+ * \return
+ */
+ bool Ne(CBotVar* left, CBotVar* right) override;
+
+ /*!
+ * \brief Save1State
+ * \param pf
+ * \return
+ */
+ bool Save1State(FILE* pf) override;
+
+private:
+ //! The value.
+ CBotString m_val;
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 283e01c..1dd05b8 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -59,6 +59,7 @@ set(SOURCES
CBotVar/CBotVarPointer.cpp
CBotVar/CBotVarClass.cpp
CBotVar/CBotVarBoolean.cpp
+ CBotVar/CBotVarString.cpp
)
# Includes
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list