Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
XFile.h
Go to the documentation of this file.
1//! @file XFile.h
2//! @brief CXFile is the base class for different kind of file (CXStdioFile, CXMemFile...)
3//!
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(CXFILE_INCLUDE_H)
7#define CXFILE_INCLUDE_H
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13BEGIN_MOOTOOLS_NAMESPACE
14
15 // Memory callback handlers
16 typedef enum
17 {
18 OPEN_FILE = 1,
19 CLOSE_FILE = 1,
20 } fileEventType;
21
22 typedef void (*fileCallbackEvent)(xFileHandle fileHandle, fileEventType type);
23
24 typedef struct XFileCallback
25 {
26 fileCallbackEvent callback;
27
28 XFileCallback()
29 {
30 callback = NULL;
31 }
32 } XFileCallback;
33
34 // Use this file callback object to receive notification on open / close files
35 extern XFileCallback fileCallbackNotify;
36
37 ////////////////////////////////////////////////////////////////////////////////////////////////
38 //! @class CXFile
39 //! @brief CXFile is the base class for CXStdioFile, CXStdioFileEx, CXMemFile
40 class CXFileException;
41 class DLL_TOOLSFUNCTION CXFile : public CXObject
42 {
43 friend CXArchive;
44
45 DECLARE_DYNAMIC_XOBJECT(CXFile)
46
47 public:
48 //! @enum OpenFlags
49 //! @brief Specify the open mode for file.
50 //! @details By default an open file is no inherited by child processes
51 typedef enum XEnumType( unsigned int)
52 {
53 modeRead = 0x00000,
54 modeWrite = 0x00001,
55 modeReadWrite = 0x00002,
56 readFlags = modeRead|modeWrite|modeReadWrite,
57
58 shareExclusive = 0x00010, //!< Default mode, if nothing specified. Deny file being opened for reading/writing to other process
59 shareDenyWrite = 0x00020, //!< Deny file being opened for writing to other process
60 shareDenyRead = 0x00030, //!< Deny file being opened for reading to other process
61 shareDenyNone = 0x00040, //!< file could be opened by other process
62 shareFlags = shareExclusive| shareDenyWrite|shareDenyRead|shareDenyNone,
63
64 typeUnicode = 0x00400, //!< used in derived classes (e.g. CXStdioFile) only
65 typeUtf8 = 0x00800, //!< Windows only, as it is always the case under MacOS / Linux. used in derived classes (e.g. CXStdioFile) only
66
67 modeCreate = 0x01000, //!< Existing file is replaced, unless modeNoTruncate is used
68 modeNoTruncate = 0x02000,
69 typeText = 0x04000, //!< CXFile are always binary, intended to be used in derived classes (e.g. CXStdioFile) only
70 typeBinary = 0x08000, //!< CXFile are always binary, intended to be used in derived classes (e.g. CXStdioFile) only
71
72 noException = 0x100000, //!< By default CXFile send exception. This flag turn off exception.
73
74 specificFlags = 0x10000000, //!< Override class mode base flags
75 } OpenFlags;
76
77
78 //! @enum OpenFlags
79 //! @brief Specify the open mode for file.
80 //! @details By default an open file is no inherited by child processes
81 typedef enum SeekPosition XEnumType( unsigned int)
82 {
83 begin = 0x00,
84 current = 0x01,
85 end = 0x02
86 } SeekPosition;
87
88 // Constructors
89 CXFile(bool allowException = true);
91 CXFile(LPCTSTR lpszFileName, unsigned int openFlags);
92#ifdef MOOTOOLS_MFC_PRODUCT_BUILD
93 CXFile(CFile *pfile, bool allowException = true); //!< allowException = false then no exception is send by the class which return false instead
94#endif
95
96 // Attributes
97 virtual fileuint GetPosition() const;
98 virtual CXString GetFileName() const;
99 virtual CXString GetFilePath() const;
100 virtual void SetFilePath(LPCTSTR lpszNewName);
101
102 // Operations
103 virtual bool Open(LPCTSTR lpszFileName, unsigned int openMode, CXFileException *pError = NULL); //!< Open does not send any exception but can fill CXFileException with the appropriate cause of the failing.
104
105 fileuint SeekToEnd();
106 void SeekToBegin();
107
108 // Overridables
109 virtual fileuint Seek(longint lOff, CXFile::SeekPosition nFrom);
110 virtual bool SetLength(fileuint newlength);
111 virtual fileuint GetLength() const;
112
113 virtual unsigned int Read(void* buffer, unsigned int maxByteToRead);
114 virtual void Write(const void* buffer, unsigned int byteToWrite);
115
116 virtual void Abort();
117 virtual void Flush();
118 virtual void Close();
119
120 // Implementation
121 public:
122 virtual ~CXFile();
123
124#ifdef _DEBUG
125 virtual void Dump() const;
126#endif
127
128 protected:
129 typedef enum XEnumType( unsigned int)
130 {
131 bufferRead,
132 bufferWrite,
133 bufferCommit,
134 bufferCheck
135 } BufferCommandType;
136
137 typedef enum XEnumType( unsigned int)
138 {
139 bufferNone = 0x00,
140 bufferDirect = 0x01
141 } BufferFlags;
142
143 void Init(xFileHandle hFile);
144 virtual SIZET BufferCommand(unsigned int bufferCommand, SIZET nCount = 0, unsigned char **ppBufStart = NULL, unsigned char **ppBufMax = NULL);
145
146 xFileHandle fileHandle;
147 bool autoClose, sendException;
148 CXString filename;
149 };
150
151END_MOOTOOLS_NAMESPACE
152
153#include "xfileoperation.h"
154
155#endif // !defined(CXFILE_INCLUDE_H)
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition XArchive.h:17
CXFile is the base class for CXStdioFile, CXStdioFileEx, CXMemFile.
Definition XFile.h:42
CXFile(CFile *pfile, bool allowException=true)
allowException = false then no exception is send by the class which return false instead
virtual bool Open(LPCTSTR lpszFileName, unsigned int openMode, CXFileException *pError=NULL)
Open does not send any exception but can fill CXFileException with the appropriate cause of the faili...