* Fix forward declaration of OpenEditorFile
* Remove useless, and (luckily) unused default constructor from CFileParser * Move initialisation of m_Flags to initialization list of constructor * Don't use (void) as argument list of destructor (this is bad style in C, but especially so in C++, since C++ implies an empty argument list if you give one) * Don't check whether new didn't return NULL, since we're using the throwing variant of new anyway * Use istream.read instead of istream.readsome since the former will refill the buffer if necessary (which *is* necessary to be able to read something the first time) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2022 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
f0d6c4d6b6
commit
eb898d0293
|
@ -29,38 +29,30 @@
|
|||
#include "debugprint.h"
|
||||
|
||||
|
||||
CFileParser::CFileParser() :
|
||||
m_File(NULL)
|
||||
{
|
||||
strcpy(m_Brk,"= \n\r\t");
|
||||
}
|
||||
|
||||
CFileParser::CFileParser(std::istream& file, short flags) :
|
||||
m_Flags(flags),
|
||||
m_File(NULL)
|
||||
{
|
||||
m_Flags = flags;
|
||||
|
||||
// Seek to the end to determine the file/stream's size
|
||||
file.seekg(0, std::ios::end);
|
||||
std::ifstream::pos_type fileSize = file.tellg();
|
||||
size_t fileSize = file.tellg();
|
||||
file.seekg(0);
|
||||
|
||||
delete m_File;
|
||||
// Should throw std::bad_alloc on failure to allocate memory
|
||||
m_File = new char[fileSize + 1];
|
||||
|
||||
m_File = new char[fileSize + static_cast<std::ifstream::pos_type>(1)];
|
||||
if(m_File)
|
||||
{
|
||||
file.readsome(static_cast<std::istream::char_type*>(m_File), fileSize);
|
||||
m_File[fileSize]=0;
|
||||
}
|
||||
file.read(m_File, fileSize);
|
||||
|
||||
// Nul terminate string
|
||||
m_File[fileSize] = 0;
|
||||
|
||||
m_Pos = m_File;
|
||||
|
||||
m_BufferSize = static_cast<long>(fileSize) + 1;
|
||||
m_BufferSize = fileSize + 1;
|
||||
strcpy(m_Brk,"= \n\r\t");
|
||||
}
|
||||
|
||||
CFileParser::~CFileParser(void)
|
||||
CFileParser::~CFileParser()
|
||||
{
|
||||
delete m_File;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ struct TokenID
|
|||
class CFileParser
|
||||
{
|
||||
public:
|
||||
CFileParser();
|
||||
CFileParser(std::istream& file, short flags);
|
||||
|
||||
~CFileParser();
|
||||
|
|
|
@ -149,7 +149,7 @@ extern CUndoRedo *g_UndoRedo;
|
|||
|
||||
extern char g_HomeDirectory[1024];
|
||||
extern char g_WorkDirectory[1024];
|
||||
extern FILE *OpenEditorFile(char *FileName);
|
||||
extern FILE *OpenEditorFile(const char *FileName);
|
||||
extern std::string EditorDataFileName(const std::string& fileName);
|
||||
|
||||
char *IMDTypeNames[]={
|
||||
|
|
Loading…
Reference in New Issue