ScummVM API documentation
afx.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BAGEL_MFC_AFX_H
23 #define BAGEL_MFC_AFX_H
24 
25 #include "common/stream.h"
26 #include "bagel/mfc/minwindef.h"
27 
28 namespace Bagel {
29 namespace MFC {
30 
31 struct CRuntimeClass;
32 class CObject;
33 class CException;
34 class CFileException;
35 
36 #define DECLARE_DYNAMIC(class_name) \
37  public: \
38  static const CRuntimeClass class##class_name; \
39  virtual const CRuntimeClass *GetRuntimeClass() const override; \
40 
41 
42 #define RUNTIME_CLASS(class_name) ((const CRuntimeClass *)(&class_name::class##class_name))
43 
44 #define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
45  const CRuntimeClass class_name::class##class_name = { \
46  #class_name, sizeof(class class_name), wSchema, pfnNew, \
47  RUNTIME_CLASS(base_class_name) }; \
48  const CRuntimeClass* class_name::GetRuntimeClass() const \
49  { return RUNTIME_CLASS(class_name); }
50 
51 #define IMPLEMENT_DYNAMIC(class_name, base_class_name) \
52  IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, nullptr)
53 
54 #define IMPLEMENT_DYNCREATE(class_name, base_class_name) \
55  CObject *class_name::CreateObject() \
56  { return new class_name; } \
57  IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, \
58  class_name::CreateObject)
59 
60 #define ASSERT_KINDOF(class_name, object) \
61  assert((object)->IsKindOf(RUNTIME_CLASS(class_name)))
62 #define ASSERT_VALID(X) assert((X) != nullptr)
63 
64 struct CRuntimeClass {
65  const char *m_lpszClassName;
66  int m_nObjectSize;
67  unsigned int m_wSchema;
68  CObject *(*m_pfnCreateObject)();
69  const CRuntimeClass *m_pBaseClass;
70 
71  CObject *CreateObject() const;
72  bool IsDerivedFrom(const CRuntimeClass *pBaseClass) const;
73 };
74 
75 class CDumpContext {
76 };
77 
78 class CObject {
79 public:
80  static const CRuntimeClass classCObject;
81 public:
82  CObject();
83  CObject(const CObject &) = default;
84  CObject &operator=(const CObject &) = default;
85  virtual ~CObject() = 0;
86  virtual const CRuntimeClass *GetRuntimeClass() const;
87 
88  virtual void AssertValid() const {}
89  virtual void Dump(CDumpContext &dc) const {}
90 
91  bool IsKindOf(const CRuntimeClass *pClass) const;
92 };
93 
94 class CFile : public CObject {
95  DECLARE_DYNAMIC(CFile)
96 public:
97  // Flag values
98  enum OpenFlags {
99  modeRead = (int)0x00000,
100  modeWrite = (int)0x00001,
101  modeReadWrite = (int)0x00002,
102  shareCompat = (int)0x00000,
103  shareExclusive = (int)0x00010,
104  shareDenyWrite = (int)0x00020,
105  shareDenyRead = (int)0x00030,
106  shareDenyNone = (int)0x00040,
107  modeNoInherit = (int)0x00080,
108  typeUnicode = (int)0x00400, // used in derived classes (e.g. CStdioFile) only
109  modeCreate = (int)0x01000,
110  modeNoTruncate = (int)0x02000,
111  typeText = (int)0x04000, // used in derived classes (e.g. CStdioFile) only
112  typeBinary = (int)0x08000, // used in derived classes (e.g. CStdioFile) only
113  osNoBuffer = (int)0x10000,
114  osWriteThrough = (int)0x20000,
115  osRandomAccess = (int)0x40000,
116  osSequentialScan = (int)0x80000,
117  };
118 
119  enum Attribute {
120  normal = 0x00, // note: not same as FILE_ATTRIBUTE_NORMAL
121  readOnly = FILE_ATTRIBUTE_READONLY,
122  hidden = FILE_ATTRIBUTE_HIDDEN,
123  system = FILE_ATTRIBUTE_SYSTEM,
124  volume = 0x08,
125  directory = FILE_ATTRIBUTE_DIRECTORY,
126  archive = FILE_ATTRIBUTE_ARCHIVE,
127  device = FILE_ATTRIBUTE_DEVICE,
128  temporary = FILE_ATTRIBUTE_TEMPORARY,
129  sparse = FILE_ATTRIBUTE_SPARSE_FILE,
130  reparsePt = FILE_ATTRIBUTE_REPARSE_POINT,
131  compressed = FILE_ATTRIBUTE_COMPRESSED,
132  offline = FILE_ATTRIBUTE_OFFLINE,
133  notIndexed = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
134  encrypted = FILE_ATTRIBUTE_ENCRYPTED
135  };
136 
137  enum SeekPosition {
138  begin = 0x0, current = 0x1, end = 0x2
139  };
140 
141 private:
142  Common::Stream *_stream = nullptr;
143 
144  Common::SeekableReadStream *readStream() const;
145  Common::WriteStream *writeStream() const;
146 
147 public:
148  CFile() {}
149  CFile(const char *lpszFileName, unsigned int nOpenFlags);
150  ~CFile() {
151  Close();
152  }
153 
154  bool Open(const char *lpszFileName,
155  unsigned int nOpenFlags = CFile::modeRead,
156  CFileException *pError = nullptr);
157  void Close();
158  void Abort();
159  uint64 SeekToEnd();
160  void SeekToBegin();
161  virtual uint64 Seek(int64 lOff, unsigned int nFrom);
162  virtual uint64 GetLength() const;
163  virtual uint64 GetPosition() const;
164 
165  virtual unsigned int Read(void *lpBuf, unsigned int nCount);
166  virtual void Write(const void *lpBuf, unsigned int nCount);
167  unsigned int ReadHuge(void *lpBuf, unsigned int nCount) {
168  return Read(lpBuf, nCount);
169  }
170 
171  operator Common::SeekableReadStream *() {
172  return readStream();
173  }
174  operator Common::SeekableReadStream &() {
175  return *readStream();
176  }
177 
182  Common::SeekableReadStream *detach();
183 };
184 
185 /*============================================================================*/
186 /* Exceptions - Not supported in ScummVM */
187 class CException {};
188 class CFileException : public CException {};
189 
190 } // namespace MFC
191 } // namespace Bagel
192 
193 #endif
Definition: afx.h:75
Definition: afx.h:188
Definition: afx.h:64
Definition: afx.h:78
Definition: stream.h:77
Definition: afx.h:187
Definition: stream.h:745
Definition: afx.h:94
Definition: afxwin.h:27
Definition: stream.h:48