cgma
CubitFile.cpp
Go to the documentation of this file.
00001 //- Class:          CubitFile
00002 //- Description:    Class with functions to work with files
00003 
00004 #include "CubitFile.hpp"
00005 #include <errno.h>
00006 
00007 CubitFile::CubitFile()
00008   : mFile(NULL), mError(0)
00009 {
00010 }
00011 
00012 CubitFile::CubitFile(const CubitString& file, const char* mode)
00013   : mFile(NULL)
00014 {
00015   open(file, mode);
00016 }
00017 
00018 CubitFile::~CubitFile()
00019 {
00020   close();
00021 }
00022 
00023 bool CubitFile::open(const CubitString& file, const char* mode)
00024 {
00025   close();
00026 
00027   this->mError = 0;
00028 
00029 #ifdef _WIN32
00030   this->mFile = _wfopen(CubitString::toUtf16(file).c_str(), CubitString::toUtf16(mode).c_str());
00031 #else
00032   this->mFile = fopen(file.c_str(), mode);
00033 #endif
00034   if(!this->mFile)
00035   {
00036     this->mError = errno;
00037   }
00038 
00039   return mError == 0;
00040 }
00041 
00042 void CubitFile::close()
00043 {
00044   if(mFile)
00045   {
00046     fclose(mFile);
00047   }
00048   mFile = NULL;
00049   mError = 0;
00050 }
00051 
00052 FILE* CubitFile::file() const
00053 {
00054   return this->mFile;
00055 }
00056 
00057 CubitFile::operator bool () const
00058 {
00059   return this->mFile != NULL;
00060 }
00061 
00062 int CubitFile::error()
00063 {
00064   return this->mError;
00065 }
00066 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines