00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _NPT_FILE_H_
00011 #define _NPT_FILE_H_
00012
00013
00014
00015
00016 #include "NptTypes.h"
00017 #include "NptStreams.h"
00018
00019
00020
00021
00022 const int NPT_ERROR_NO_SUCH_FILE = NPT_ERROR_BASE_FILE - 0;
00023 const int NPT_ERROR_FILE_NOT_OPEN = NPT_ERROR_BASE_FILE - 1;
00024 const int NPT_ERROR_FILE_BUSY = NPT_ERROR_BASE_FILE - 2;
00025 const int NPT_ERROR_FILE_ALREADY_OPEN = NPT_ERROR_BASE_FILE - 3;
00026 const int NPT_ERROR_FILE_NOT_READABLE = NPT_ERROR_BASE_FILE - 4;
00027 const int NPT_ERROR_FILE_NOT_WRITABLE = NPT_ERROR_BASE_FILE - 5;
00028
00029 const unsigned int NPT_FILE_OPEN_MODE_READ = 0x01;
00030 const unsigned int NPT_FILE_OPEN_MODE_WRITE = 0x02;
00031 const unsigned int NPT_FILE_OPEN_MODE_CREATE = 0x04;
00032 const unsigned int NPT_FILE_OPEN_MODE_TRUNCATE = 0x08;
00033 const unsigned int NPT_FILE_OPEN_MODE_UNBUFFERED = 0x10;
00034 const unsigned int NPT_FILE_OPEN_MODE_APPEND = 0x20;
00035
00036 #define NPT_FILE_STANDARD_INPUT "@STDIN"
00037 #define NPT_FILE_STANDARD_OUTPUT "@STDOUT"
00038 #define NPT_FILE_STANDARD_ERROR "@STDERR"
00039
00040
00041
00042
00043 class NPT_DataBuffer;
00044
00045
00046
00047
00048 class NPT_FileInterface
00049 {
00050 public:
00051
00052 typedef unsigned int OpenMode;
00053
00054
00055 virtual ~NPT_FileInterface() {}
00056
00057
00058 virtual NPT_Result Open(OpenMode mode) = 0;
00059 virtual NPT_Result Close() = 0;
00060
00061
00062
00063 virtual NPT_Result GetSize(NPT_Size& size) = 0;
00064 virtual NPT_Result GetInputStream(NPT_InputStreamReference& stream) = 0;
00065 virtual NPT_Result GetOutputStream(NPT_OutputStreamReference& stream) = 0;
00066 };
00067
00068
00069
00070
00071 class NPT_File : public NPT_FileInterface
00072 {
00073 public:
00074
00075 static NPT_Result Load(const char* filename, NPT_DataBuffer& buffer);
00076
00077
00078 NPT_File(const char* name);
00079 ~NPT_File() { delete m_Delegate; }
00080
00081
00082 NPT_Result Load(NPT_DataBuffer& buffer);
00083
00084
00085 NPT_Result Open(OpenMode mode) {
00086 return m_Delegate->Open(mode);
00087 }
00088 NPT_Result Close() {
00089 return m_Delegate->Close();
00090 }
00091 NPT_Result GetSize(NPT_Size& size) {
00092 return m_Delegate->GetSize(size);
00093 }
00094 NPT_Result GetInputStream(NPT_InputStreamReference& stream) {
00095 return m_Delegate->GetInputStream(stream);
00096 }
00097 NPT_Result GetOutputStream(NPT_OutputStreamReference& stream) {
00098 return m_Delegate->GetOutputStream(stream);
00099 }
00100
00101 protected:
00102
00103 NPT_FileInterface* m_Delegate;
00104 };
00105
00106 #endif // _NPT_FILE_H_