X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fbinary.cpp;h=229a98eb5bfe31e3903eba79e623de38ae9ca718;hb=af0f7ea2da9ace619ff51edef564fe4669582074;hp=5a0f4ba3aba458ca0f93ace0c5629623201ff9d4;hpb=5b1d24fcf5aec37d73d79c1e7bd4dc0c7414d7f4;p=meshio%2Fmeshio.git diff --git a/src/binary.cpp b/src/binary.cpp index 5a0f4ba..229a98e 100644 --- a/src/binary.cpp +++ b/src/binary.cpp @@ -72,6 +72,8 @@ bool MemoryReader::isEnd()const } /////////////////////////////////////////////////////////////////////////////// +// readALL +/////////////////////////////////////////////////////////////////////////////// static void readALL_(FILE *fp, std::vector &buf) { int iRet = fseek(fp, 0L, SEEK_END); @@ -96,26 +98,47 @@ static void readALL_(FILE *fp, std::vector &buf) void readAll(const char *path, std::vector &buf) { - /* - std::ifstream io(path, std::ios::binary); - if(!io){ - return; + FILE* fp = fopen(path, "rb"); + if(fp){ + readALL_(fp, buf); + fclose(fp); } - io.seekg(0, std::fstream::end); - unsigned int eofPos = io.tellg(); - io.clear(); - io.seekg(0, std::fstream::beg); - unsigned int begPos = io.tellg(); - unsigned int size = eofPos - begPos; - io.read(&buf[0], buf.size()); - */ +} - FILE* fp = fopen(path, "rb"); +#ifdef _WIN32 +void readAll(const wchar_t *path, std::vector &buf) +{ + FILE* fp = _wfopen(path, L"rb"); if(fp){ readALL_(fp, buf); fclose(fp); } } +#endif + +/////////////////////////////////////////////////////////////////////////////// +// FileWriter +/////////////////////////////////////////////////////////////////////////////// +FileWriter::FileWriter(const char *path) +{ + io_=fopen(path, "wb"); +} + +FileWriter::FileWriter(const wchar_t *path) +{ + io_=_wfopen(path, L"wb"); +} + +FileWriter::~FileWriter() +{ + fclose(io_); +} + +void FileWriter::write(const char *buf, unsigned int size) +{ + fwrite(buf, size, 1, io_); +} + } // namespace binary } // namespace meshio