|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tfilepath_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <fcntl.h></fcntl.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys types.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys stat.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <fstream></fstream>
|
|
Toshihiro Shimizu |
890ddd |
#include <iostream></iostream>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace std;
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <io.h></io.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <windows.h></windows.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Return a pointer to a \b FILE, if exist. The file is opened using _wfopen_s,
|
|
Toshihiro Shimizu |
890ddd |
documentation \b http://msdn2.microsoft.com/en-us/library/z5hh6ee9(VS.80).aspx.
|
|
Toshihiro Shimizu |
890ddd |
\b fp is file path, \b mode is the way open, read ("r"), write ("w"), ... , to
|
|
Toshihiro Shimizu |
890ddd |
know mode view _wfopen_s documentation.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
FILE *fopen(const TFilePath &fp, string mode)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
FILE *pFile;
|
|
Shinya Kitaoka |
9eb50d |
errno_t err = _wfopen_s(&pFile, fp.getWideString().c_str(), ::to_wstring(mode).c_str());
|
|
Toshihiro Shimizu |
890ddd |
if (err == -1)
|
|
Toshihiro Shimizu |
890ddd |
return NULL;
|
|
Toshihiro Shimizu |
890ddd |
return pFile;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tifstream::Tifstream(const TFilePath &fp)
|
|
Toshihiro Shimizu |
890ddd |
: ifstream(m_file = fopen(fp, "rb"))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tifstream::~Tifstream()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_file) {
|
|
Toshihiro Shimizu |
890ddd |
int ret = fclose(m_file);
|
|
Toshihiro Shimizu |
890ddd |
assert(ret == 0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tifstream::close()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_file = 0;
|
|
Toshihiro Shimizu |
890ddd |
std::ifstream::close();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tofstream::Tofstream(const TFilePath &fp, bool append_existing)
|
|
Toshihiro Shimizu |
890ddd |
: ofstream(m_file = fopen(fp, append_existing ? "ab" : "wb"))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tofstream::~Tofstream()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_file) {
|
|
Toshihiro Shimizu |
890ddd |
flush();
|
|
Toshihiro Shimizu |
890ddd |
int ret = fclose(m_file);
|
|
Toshihiro Shimizu |
890ddd |
assert(ret == 0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tofstream::close()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_file = 0;
|
|
Toshihiro Shimizu |
890ddd |
std::ofstream::close();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool Tifstream::isOpen() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_file != 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool Tofstream::isOpen() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_file != 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//======================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Versione non windows
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//======================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FILE *fopen(const TFilePath &fp, string mode)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return fopen(QString::fromStdWString(fp.getWideString()).toUtf8().data(), mode.c_str());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tifstream::Tifstream(const TFilePath &fp)
|
|
Toshihiro Shimizu |
890ddd |
: ifstream(QString::fromStdWString(fp.getWideString()).toUtf8().data(), ios::binary)
|
|
Toshihiro Shimizu |
890ddd |
/*: ifstream(openFileForReading(fp), ios::binary)
|
|
Toshihiro Shimizu |
890ddd |
NO! Questo costruttore non e' standard, anche se e' presente
|
|
Toshihiro Shimizu |
890ddd |
in molte versioni. Nel MAC non c'e e fa un cast a char*
|
|
Toshihiro Shimizu |
890ddd |
sperando che sia il nome del file => compila ma non funziona
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tifstream::~Tifstream()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Toshihiro Shimizu |
890ddd |
fclose();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tofstream::Tofstream(const TFilePath &fp, bool append_existing)
|
|
Toshihiro Shimizu |
890ddd |
: ofstream(QString::fromStdWString(fp.getWideString()).toUtf8().data(), ios::binary | (append_existing ? ios_base::app : ios_base::trunc))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tofstream::~Tofstream()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tofstream::close()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool Tifstream::isOpen() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// TODO
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool Tofstream::isOpen() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// TODO
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|