[colobot] 131/377: Moving global files function from CBotProgram.cpp to CBotFileUtils.cpp.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:07 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 751999064bbb478e274b6b20a9fe96697b6e647b
Author: Grunaka <dev at romainbreton.fr>
Date: Sun Nov 22 17:36:01 2015 +0100
Moving global files function from CBotProgram.cpp to CBotFileUtils.cpp.
---
src/CBot/CBot.h | 15 -----
src/CBot/CBotClass.cpp | 1 +
src/CBot/CBotFileUtils.cpp | 113 ++++++++++++++++++++++++++++++++++++
src/CBot/CBotFileUtils.h | 85 +++++++++++++++++++++++++++
src/CBot/CBotProgram.cpp | 108 +---------------------------------
src/CBot/CBotStack.cpp | 2 +
src/CBot/CBotVar/CBotVarArray.cpp | 2 +
src/CBot/CBotVar/CBotVarClass.cpp | 2 +
src/CBot/CBotVar/CBotVarPointer.cpp | 3 +
9 files changed, 209 insertions(+), 122 deletions(-)
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 1e28110..458cfdd 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -50,21 +50,6 @@ class CBotWhile; // while (...) {...};
class CBotIf; // if (...) {...} else {...}
class CBotDefParam; // paramerer list of a function
-
-extern bool SaveVar(FILE* pf, CBotVar* pVar);
-
-extern bool WriteWord(FILE* pf, unsigned short w);
-extern bool ReadWord(FILE* pf, unsigned short& w);
-extern bool ReadLong(FILE* pf, long& w);
-extern bool WriteFloat(FILE* pf, float w);
-extern bool WriteLong(FILE* pf, long w);
-extern bool ReadFloat(FILE* pf, float& w);
-extern bool ReadString(FILE* pf, CBotString& s);
-extern bool WriteType(FILE* pf, CBotTypResult type);
-extern bool ReadType(FILE* pf, CBotTypResult& type);
-
-extern float GetNumFloat( const char* p );
-
#if 0
extern void DEBUG( const char* text, int val, CBotStack* pile );
#endif
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 94a0534..172f2cd 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -32,6 +32,7 @@
#include "CBotStack.h"
#include "CBotCStack.h"
#include "CBotUtils.h"
+#include "CBotFileUtils.h"
#include "CBotCallMethode.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp
index 1c58571..bb561bd 100644
--- a/src/CBot/CBotFileUtils.cpp
+++ b/src/CBot/CBotFileUtils.cpp
@@ -20,6 +20,11 @@
// Modules inlcude
#include "CBotFileUtils.h"
+#include "CBotString.h"
+#include "CBotClass.h"
+
+#include "CBotEnums.h"
+
// Local include
// Global include
@@ -60,3 +65,111 @@ std::size_t fRead(void *buffer,
{
return fread(buffer, elemsize, length, filehandle);
}
+
+
+////////////////////////////////////////////////////////////////////////////////
+bool ReadWord(FILE* pf, unsigned short& w)
+{
+ size_t lg;
+
+ lg = fread(&w, sizeof( unsigned short ), 1, pf );
+
+ return (lg == 1);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ReadFloat(FILE* pf, float& w)
+{
+ size_t lg;
+
+ lg = fread(&w, sizeof( float ), 1, pf );
+
+ return (lg == 1);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool WriteLong(FILE* pf, long w)
+{
+ size_t lg;
+
+ lg = fwrite(&w, sizeof( long ), 1, pf );
+
+ return (lg == 1);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ReadLong(FILE* pf, long& w)
+{
+ size_t lg;
+
+ lg = fread(&w, sizeof( long ), 1, pf );
+
+ return (lg == 1);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ReadString(FILE* pf, CBotString& s)
+{
+ unsigned short w;
+ char buf[1000];
+ size_t lg1, lg2;
+
+ if (!ReadWord(pf, w)) return false;
+ lg1 = w;
+ lg2 = fread(buf, 1, lg1, pf );
+ buf[lg2] = 0;
+
+ s = buf;
+ return (lg1 == lg2);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool WriteType(FILE* pf, CBotTypResult type)
+{
+ int typ = type.GetType();
+ if ( typ == CBotTypIntrinsic ) typ = CBotTypClass;
+ if ( !WriteWord(pf, typ) ) return false;
+ if ( typ == CBotTypClass )
+ {
+ CBotClass* p = type.GetClass();
+ if ( !WriteString(pf, p->GetName()) ) return false;
+ }
+ if ( type.Eq( CBotTypArrayBody ) ||
+ type.Eq( CBotTypArrayPointer ) )
+ {
+ if ( !WriteWord(pf, type.GetLimite()) ) return false;
+ if ( !WriteType(pf, type.GetTypElem()) ) return false;
+ }
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ReadType(FILE* pf, CBotTypResult& type)
+{
+ unsigned short w, ww;
+ if ( !ReadWord(pf, w) ) return false;
+ type.SetType(w);
+
+ if ( type.Eq( CBotTypIntrinsic ) )
+ {
+ type = CBotTypResult( w, "point" );
+ }
+
+ if ( type.Eq( CBotTypClass ) )
+ {
+ CBotString s;
+ if ( !ReadString(pf, s) ) return false;
+ type = CBotTypResult( w, s );
+ }
+
+ if ( type.Eq( CBotTypArrayPointer ) ||
+ type.Eq( CBotTypArrayBody ) )
+ {
+ CBotTypResult r;
+ if ( !ReadWord(pf, ww) ) return false;
+ if ( !ReadType(pf, r) ) return false;
+ type = CBotTypResult( w, r );
+ type.SetLimite(static_cast<short>(ww));
+ }
+ return true;
+}
diff --git a/src/CBot/CBotFileUtils.h b/src/CBot/CBotFileUtils.h
index 8f76ec4..1ac1664 100644
--- a/src/CBot/CBotFileUtils.h
+++ b/src/CBot/CBotFileUtils.h
@@ -20,12 +20,17 @@
#pragma once
// Modules inlcude
+#include "CBotTypResult.h"
// Local include
// Global include
#include <cstdio>
+// Forward declaration
+class CBotVar;
+class CBotString;
+
///////////////////////////////////////////////////////////////////////////////
// routines for file management (* FILE)
@@ -69,3 +74,83 @@ std::size_t fRead(void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle);
+
+/*!
+ * \brief SaveVar
+ * \param pf
+ * \param pVar
+ * \return
+ */
+bool SaveVar(FILE* pf, CBotVar* pVar);
+
+/*!
+ * \brief WriteWord
+ * \param pf
+ * \param w
+ * \return
+ */
+bool WriteWord(FILE* pf, unsigned short w);
+
+/*!
+ * \brief ReadWord
+ * \param pf
+ * \param w
+ * \return
+ */
+bool ReadWord(FILE* pf, unsigned short& w);
+
+/*!
+ * \brief ReadLong
+ * \param pf
+ * \param w
+ * \return
+ */
+bool ReadLong(FILE* pf, long& w);
+
+/*!
+ * \brief WriteFloat
+ * \param pf
+ * \param w
+ * \return
+ */
+bool WriteFloat(FILE* pf, float w);
+
+/*!
+ * \brief WriteLong
+ * \param pf
+ * \param w
+ * \return
+ */
+bool WriteLong(FILE* pf, long w);
+
+/*!
+ * \brief ReadFloat
+ * \param pf
+ * \param w
+ * \return
+ */
+bool ReadFloat(FILE* pf, float& w);
+
+/*!
+ * \brief ReadString
+ * \param pf
+ * \param s
+ * \return
+ */
+bool ReadString(FILE* pf, CBotString& s);
+
+/*!
+ * \brief WriteType
+ * \param pf
+ * \param type
+ * \return
+ */
+bool WriteType(FILE* pf, CBotTypResult type);
+
+/*!
+ * \brief ReadType
+ * \param pf
+ * \param type
+ * \return
+ */
+bool ReadType(FILE* pf, CBotTypResult& type);
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 4ee5bff..187f560 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -27,6 +27,7 @@
#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotUtils.h"
+#include "CBotFileUtils.h"
#include "CBotInstr/CBotFunction.h"
@@ -386,113 +387,6 @@ bool CBotProgram::AddFunction(const char* name,
}
////////////////////////////////////////////////////////////////////////////////
-bool ReadWord(FILE* pf, unsigned short& w)
-{
- size_t lg;
-
- lg = fread(&w, sizeof( unsigned short ), 1, pf );
-
- return (lg == 1);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool ReadFloat(FILE* pf, float& w)
-{
- size_t lg;
-
- lg = fread(&w, sizeof( float ), 1, pf );
-
- return (lg == 1);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool WriteLong(FILE* pf, long w)
-{
- size_t lg;
-
- lg = fwrite(&w, sizeof( long ), 1, pf );
-
- return (lg == 1);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool ReadLong(FILE* pf, long& w)
-{
- size_t lg;
-
- lg = fread(&w, sizeof( long ), 1, pf );
-
- return (lg == 1);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool ReadString(FILE* pf, CBotString& s)
-{
- unsigned short w;
- char buf[1000];
- size_t lg1, lg2;
-
- if (!ReadWord(pf, w)) return false;
- lg1 = w;
- lg2 = fread(buf, 1, lg1, pf );
- buf[lg2] = 0;
-
- s = buf;
- return (lg1 == lg2);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool WriteType(FILE* pf, CBotTypResult type)
-{
- int typ = type.GetType();
- if ( typ == CBotTypIntrinsic ) typ = CBotTypClass;
- if ( !WriteWord(pf, typ) ) return false;
- if ( typ == CBotTypClass )
- {
- CBotClass* p = type.GetClass();
- if ( !WriteString(pf, p->GetName()) ) return false;
- }
- if ( type.Eq( CBotTypArrayBody ) ||
- type.Eq( CBotTypArrayPointer ) )
- {
- if ( !WriteWord(pf, type.GetLimite()) ) return false;
- if ( !WriteType(pf, type.GetTypElem()) ) return false;
- }
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool ReadType(FILE* pf, CBotTypResult& type)
-{
- unsigned short w, ww;
- if ( !ReadWord(pf, w) ) return false;
- type.SetType(w);
-
- if ( type.Eq( CBotTypIntrinsic ) )
- {
- type = CBotTypResult( w, "point" );
- }
-
- if ( type.Eq( CBotTypClass ) )
- {
- CBotString s;
- if ( !ReadString(pf, s) ) return false;
- type = CBotTypResult( w, s );
- }
-
- if ( type.Eq( CBotTypArrayPointer ) ||
- type.Eq( CBotTypArrayBody ) )
- {
- CBotTypResult r;
- if ( !ReadWord(pf, ww) ) return false;
- if ( !ReadType(pf, r) ) return false;
- type = CBotTypResult( w, r );
- type.SetLimite(static_cast<short>(ww));
- }
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
if ( pVar == nullptr ) return TX_LOWPARAM;
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 91f91a9..ac312c9 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -26,6 +26,8 @@
#include "CBotVar/CBotVarPointer.h"
#include "CBotVar/CBotVarClass.h"
+#include "CBotFileUtils.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp
index b030e7a..59a3b97 100644
--- a/src/CBot/CBotVar/CBotVarArray.cpp
+++ b/src/CBot/CBotVar/CBotVarArray.cpp
@@ -21,6 +21,8 @@
#include "CBotVarArray.h"
#include "CBotVarClass.h"
+#include "CBotFileUtils.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp
index 4d6ee78..467255c 100644
--- a/src/CBot/CBotVar/CBotVarClass.cpp
+++ b/src/CBot/CBotVar/CBotVarClass.cpp
@@ -24,6 +24,8 @@
#include "CBotStack.h"
#include "CBotDefines.h"
+#include "CBotFileUtils.h"
+
#include "CBotInstr/CBotInstr.h"
// Local include
diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp
index df33322..9bbaee7 100644
--- a/src/CBot/CBotVar/CBotVarPointer.cpp
+++ b/src/CBot/CBotVar/CBotVarPointer.cpp
@@ -23,6 +23,9 @@
#include "CBot.h"
#include "CBotClass.h"
#include "CBotVarClass.h"
+
+#include "CBotFileUtils.h"
+
// Local include
// Global include
--
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