00001 // LICENSE: (Please see the file COPYING for details) 00002 // 00003 // NUS - Nemesis Utilities System: A C++ application development framework 00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske 00005 // 00006 // This file is part of NUS 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Lesser General Public 00010 // License as published by the Free Software Foundation version 2.1 00011 // of the License. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Lesser General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Lesser General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 // 00022 #ifndef NFILE_H 00023 #define NFILE_H 00024 00025 #include <cstdio> 00026 #include <sys/stat.h> 00027 00033 #ifdef _MSC_VER 00034 #include <io.h> 00035 #endif 00036 00037 #include "ndefs.h" 00038 #include "niodevice.h" 00039 #include "nstring.h" 00040 00041 00045 class DllDeclSpec NFile: public NIODevice { 00046 public: 00050 NFile(void); 00051 00058 NFile(const NString &path, 00059 NIODevice::Mode mode = NIODevice::ReadWrite); 00063 ~NFile(void); 00064 00069 bool atEnd(void) const; 00070 00075 bool exists(void) const; 00076 00082 static bool exists(const NString &filepath); 00083 00090 int handle(void) const; 00091 00099 void open(NIODevice::Mode mode); 00100 00104 void closeDevice(void); 00105 00112 nint32 read(NDataStream *buffer); 00113 00121 nint32 read(NDataStream *buffer, nuint32 bytes); 00122 00129 nint32 readLine(NDataStream *buffer); 00130 00138 nint32 write(const NDataStream &data, nuint32 bytes = 0); 00139 00144 nint64 size(void) const; 00145 00150 void setFileName(const NString &path); 00151 00156 NString getFileName(void) const; 00157 00158 00159 private: 00160 FILE *m_handle; 00161 NString m_path; 00162 00163 char *getMode(NIODevice::Mode mode) const; 00164 00165 NFile(const NFile &file); 00166 NFile &operator=(const NFile &file); 00167 }; 00168 00169 00170 #endif // NFILE_H 00171