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
Shinya Kitaoka d1f6c4
class DVAPI Tifstream final : public std::ifstream {
Shinya Kitaoka 120a6e
  FILE *m_file;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Tifstream(const TFilePath &fp);
Shinya Kitaoka 120a6e
  ~Tifstream();
Shinya Kitaoka 120a6e
  bool isOpen() const;
Shinya Kitaoka 120a6e
  void close();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI Tofstream : public std::ofstream {
Shinya Kitaoka 120a6e
  FILE *m_file;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Tofstream(const TFilePath &fp, bool append_existing = false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ~Tofstream();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isOpen() const;
Shinya Kitaoka 120a6e
  void close();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif