Moving global files function from CBot.cpp to CBotFileUtils.cpp

dev-time-step
Grunaka 2015-11-22 16:04:38 +01:00
parent 7b200a0922
commit 43ac0e35f2
8 changed files with 139 additions and 48 deletions

View File

@ -83,43 +83,3 @@
// Global include
#include <cassert>
/////////////////////////////////////////////////////////////////////////////////////
// file management
// necessary because it is not possible to do the fopen in the main program
// fwrite and fread in a dll or using the FILE * returned.
FILE* fOpen(const char* name, const char* mode)
{
return fopen(name, mode);
}
int fClose(FILE* filehandle)
{
return fclose(filehandle);
}
size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle)
{
return fwrite(buffer, elemsize, length, filehandle);
}
size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle)
{
return fread(buffer, elemsize, length, filehandle);
}
size_t fWrite(const void *buffer, size_t length, FILE* filehandle)
{
return fwrite(buffer, 1, length, filehandle);
}
size_t fRead(void *buffer, size_t length, FILE* filehandle)
{
return fread(buffer, 1, length, filehandle);
}
////////////////////////////////////////

View File

@ -147,13 +147,6 @@ class CBotCStack; // stack
// for example exceptions returned by external routines
// and " throw " with any number.
///////////////////////////////////////////////////////////////////////////////
// routines for file management (* FILE)
FILE* fOpen(const char* name, const char* mode);
int fClose(FILE* filehandle);
size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle);
size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle);
#if 0
/*

View File

@ -0,0 +1,62 @@
/*
* 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 "CBotFileUtils.h"
// Local include
// Global include
// file management
// necessary because it is not possible to do the fopen in the main program
// fwrite and fread in a dll or using the FILE * returned.
////////////////////////////////////////////////////////////////////////////////
FILE* fOpen(const char* name, const char* mode)
{
return fopen(name, mode);
}
////////////////////////////////////////////////////////////////////////////////
int fClose(FILE* filehandle)
{
return fclose(filehandle);
}
////////////////////////////////////////////////////////////////////////////////
std::size_t fWrite(const void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle)
{
return fwrite(buffer, elemsize, length, filehandle);
}
////////////////////////////////////////////////////////////////////////////////
std::size_t fRead(void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle)
{
return fread(buffer, elemsize, length, filehandle);
}

71
src/CBot/CBotFileUtils.h Normal file
View File

@ -0,0 +1,71 @@
/*
* 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
// Local include
// Global include
#include <cstdio>
///////////////////////////////////////////////////////////////////////////////
// routines for file management (* FILE)
/*!
* \brief fOpen
* \param name
* \param mode
* \return
*/
FILE* fOpen(const char* name, const char* mode);
/*!
* \brief fClose
* \param filehandle
* \return
*/
int fClose(FILE* filehandle);
/*!
* \brief fWrite
* \param buffer
* \param elemsize
* \param length
* \param filehandle
* \return
*/
std::size_t fWrite(const void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle);
/*!
* \brief fRead
* \param buffer
* \param elemsize
* \param length
* \param filehandle
* \return
*/
std::size_t fRead(void *buffer,
std::size_t elemsize,
std::size_t length,
FILE* filehandle);

View File

@ -1,5 +1,7 @@
set(SOURCES
CBot.cpp
CBotUtils.cpp
CBotFileUtils.cpp
CBotClass.cpp
CBotProgram.cpp
CBotStack.cpp
@ -7,7 +9,6 @@ set(SOURCES
CBotString.cpp
CBotToken.cpp
CBotCall.cpp
CBotUtils.cpp
CBotDefParam.cpp
CBotCallMethode.cpp
CBotStringArray.cpp

View File

@ -20,6 +20,7 @@
#include "level/robotmain.h"
#include "CBot/CBotDll.h"
#include "CBot/CBotFileUtils.h"
// TODO must be replaced by CBot.h
#include "CBot/CBotClass.h"

View File

@ -40,6 +40,8 @@
#include "ui/controls/edit.h"
#include "CBot/CBotFileUtils.h"
#include <algorithm>
#include <iomanip>

View File

@ -44,6 +44,7 @@
#include "CBot/CBotToken.h"
#include "CBot/CBotVar/CBotVar.h"
#include "CBot/CBotFileUtils.h"
const int CBOT_IPF = 100; // CBOT: default number of instructions / frame