Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_TFILEPATH_IO_INCLUDED
Toshihiro Shimizu 890ddd
#define T_TFILEPATH_IO_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef _DEBUG
Toshihiro Shimizu 890ddd
#undef _STLP_DEBUG
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define _STLP_DEBUG 1
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <stdio.h></stdio.h>
Toshihiro Shimizu 890ddd
// #include <stl _iosfwd.h=""></stl>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TSYSTEM_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  Regole da seguire per evitare HANDLE leaks o doppie chiusure
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    Tofstream os(path);
Toshihiro Shimizu 890ddd
    os << "ok";
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    Tofstream os(path);
Toshihiro Shimizu 890ddd
    int fd = os.fd();
Toshihiro Shimizu 890ddd
    _write(fd,"ok",2);
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    Tofstream os(path);
Toshihiro Shimizu 890ddd
    FILE *chan = fdopen(_dup(os.fd()),"wb");
Toshihiro Shimizu 890ddd
    fprintf(chan, "ok");
Toshihiro Shimizu 890ddd
    int ret = fclose(chan);
Toshihiro Shimizu 890ddd
    assert(ret==0);
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    FILE *chan = fopen(path, mode);
Toshihiro Shimizu 890ddd
    fprintf(chan, "ok");
Toshihiro Shimizu 890ddd
    int ret = fclose(chan);
Toshihiro Shimizu 890ddd
    assert(ret==0);
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
=========================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
DVAPI FILE *fopen(const TFilePath &fp, std::string mode);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI Tifstream : public std::ifstream
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FILE *m_file;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Tifstream(const TFilePath &fp);
Toshihiro Shimizu 890ddd
	~Tifstream();
Toshihiro Shimizu 890ddd
	bool isOpen() const;
Toshihiro Shimizu 890ddd
	void close();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI Tofstream : public std::ofstream
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FILE *m_file;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Tofstream(const TFilePath &fp, bool append_existing = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~Tofstream();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isOpen() const;
Toshihiro Shimizu 890ddd
	void close();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif