tahoma2d/toonz/sources/include/tfilepath_io.h

85 lines
1.4 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef T_TFILEPATH_IO_INCLUDED
#define T_TFILEPATH_IO_INCLUDED
#ifndef _DEBUG
#undef _STLP_DEBUG
#else
#define _STLP_DEBUG 1
#endif
#include "tfilepath.h"
#include <stdio.h>
// #include <stl/_iosfwd.h>
#undef DVAPI
#undef DVVAR
#ifdef TSYSTEM_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
/*=========================================================
Regole da seguire per evitare HANDLE leaks o doppie chiusure
{
Tofstream os(path);
os << "ok";
}
{
Tofstream os(path);
int fd = os.fd();
_write(fd,"ok",2);
}
{
Tofstream os(path);
FILE *chan = fdopen(_dup(os.fd()),"wb");
fprintf(chan, "ok");
int ret = fclose(chan);
assert(ret==0);
}
{
FILE *chan = fopen(path, mode);
fprintf(chan, "ok");
int ret = fclose(chan);
assert(ret==0);
}
=========================================================*/
DVAPI FILE *fopen(const TFilePath &fp, std::string mode);
2016-03-19 06:57:51 +13:00
class DVAPI Tifstream final : public std::ifstream {
2016-06-15 18:43:10 +12:00
FILE *m_file;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Tifstream(const TFilePath &fp);
~Tifstream();
bool isOpen() const;
void close();
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI Tofstream : public std::ofstream {
FILE *m_file;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Tofstream(const TFilePath &fp, bool append_existing = false);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
~Tofstream();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isOpen() const;
void close();
2016-03-19 06:57:51 +13:00
};
#endif