|
|
1.1 root 1: // Microsoft Foundation Classes C++ library.
2: // Copyright (C) 1992 Microsoft Corporation,
3: // All rights reserved.
4:
5: // This source code is only intended as a supplement to the
6: // Microsoft Foundation Classes Reference and Microsoft
7: // QuickHelp documentation provided with the library.
8: // See these sources for detailed information regarding the
9: // Microsoft Foundation Classes product.
10:
11: #ifndef __AFX_H__
12: #define __AFX_H__
13:
14: #define _MFC_VER 0x0100 /* Microsoft Foundation Classes */
15: #define _AFX 1 /* Microsoft Application Framework Classes */
16:
17: #ifndef __cplusplus
18: #error Microsoft Foundation Classes require C++ compilation (use a .cpp suffix)
19: #endif
20:
21: /////////////////////////////////////////////////////////////////////////////
22: // Classes declared in this file
23: // in addition to standard primitive data types and various helper macros
24:
25: struct CRuntimeClass; // object type information
26:
27: class CObject; // the root of all objects classes
28:
29: class CException; // the root of all exceptions
30: class CMemoryException; // out-of-memory exception
31: class CNotSupportedException; // feature not supported exception
32: class CArchiveException; // archive exception
33: class CFileException; // file exception
34:
35: class CFile; // raw binary file
36: class CStdioFile; // buffered stdio text/binary file
37: class CMemFile; // memory based file
38:
39: // Non CObject classes
40: class CString; // growable string type
41: class CTimeSpan; // time/date difference
42: class CTime; // absolute time/date
43: struct CFileStatus; // file status information
44: struct CMemoryState; // diagnostic memory support
45:
46: class CArchive; // object persistence tool
47: class CDumpContext; // object diagnostic dumping
48:
49: /////////////////////////////////////////////////////////////////////////////
50: // Other includes from standard "C" runtimes
51:
52:
53: #include <string.h>
54: #include <stdio.h>
55: #include <stdlib.h>
1.1.1.2 root 56: #ifdef _NTWIN
57: #pragma warning(default: 4069)
58: #endif
1.1 root 59: #include <time.h>
60:
61: /////////////////////////////////////////////////////////////////////////////
62: // Target version control
63:
64: // For target version (one of)
65: // _WINDOWS : for Microsoft Windows target (defined by #include <afxwin.h>)
66: // _DOS : for Microsoft DOS (non Windows) target
67: // _NTWIN : with _WINDOWS is a Windows NT GUI application, by itself is a
68: // character application (only <afx.h> applies)
69: //
70: // Additional build options:
71: // _DEBUG : debug versions (full diagnostics)
72: //
73: // Internal version flags:
74: // _DOSWIN : for Microsoft Windows and DOS target code (internal)
75: // _NEARDATA : ambient near data pointers needing far overloads
76:
77: #if !defined(_WINDOWS) && !defined(_DOS) && !defined(_NTWIN)
78: #error Please define one of _WINDOWS or _DOS or _NTWIN
79: #endif
80:
81: #if defined(_WINDOWS) && defined(_DOS)
82: #error Please define only one of _WINDOWS or _DOS
83: #endif
84:
85: #ifndef _NTWIN
86: #ifdef _WINDOWS
87: #define _DOSWIN
88: #endif
89:
90: #ifdef _DOS
91: #define _DOSWIN
92: #endif
93: #endif // _NTWIN
94:
95: #if defined(_M_I86SM) || defined(_M_I86MM)
96: #define _NEARDATA
97: #endif
98:
99: /////////////////////////////////////////////////////////////////////////////
100: // Standard preprocessor symbols:
101:
102:
103: #ifdef _DOSWIN
104: #ifndef PASCAL
105: #define PASCAL _pascal
106: #endif
107:
108: #ifndef CDECL
109: #define CDECL _cdecl
110: #endif
111:
112: #ifndef FAR
113: #define FAR _far
114: #endif
115:
116: #ifndef NEAR
117: #define NEAR _near
118: #endif
119:
120: #else
121:
122: #include <excpt.h>
123: #include <windef.h>
124: #include <winbase.h>
125:
126: #define BASED_CODE
127: #undef _NEARDATA
128:
129: #ifndef PASCAL
130: #define PASCAL pascal
131: #endif
132:
133: #ifndef CDECL
134: #define CDECL cdecl
135: #endif
136:
137: #ifndef FAR
138: #define FAR far
139: #endif
140:
141: #ifndef NEAR
142: #define NEAR near
143: #endif
144:
145: #define _huge
146: #define huge
147: #define near
148: #define far
149:
150: #define _fstrcpy strcpy
151: #define _fstrlen strlen
152: #define _fstrcmp strcmp
153: #define _fstrcat strcat
154: #define _fstrncpy strncpy
155: #define _fstrncmp strncmp
156: #define _fmemcpy memcpy
157: #define _fmalloc malloc
158: #define _frealloc realloc
159: #define _ffree free
160:
1.1.1.3 ! root 161: // _export is not accepted by the NT compiler
! 162: #define __export
! 163: #define _export
! 164: #define export
! 165:
1.1 root 166: #undef GetCurrentTime
167: inline unsigned long GetCurrentTime(void)
168: { return ::GetTickCount(); }
169:
170: #endif
171:
172: /////////////////////////////////////////////////////////////////////////////
173: // Basic types (from Windows)
174:
175: typedef unsigned char BYTE; // 8-bit unsigned entity
176: typedef unsigned short WORD; // 16-bit unsigned number
177: typedef unsigned int UINT; // machine sized unsigned number (preferred)
178: typedef long LONG; // 32-bit signed number
179: typedef unsigned long DWORD; // 32-bit unsigned number
180: typedef int BOOL; // BOOLean (0 or !=0)
181:
182: typedef void* POSITION; // abstract iteration position
183:
184: // Standard constants
185: #define FALSE 0
186: #define TRUE 1
187: #define NULL 0
188:
189: /////////////////////////////////////////////////////////////////////////////
190: // Diagnostic support
191:
192:
193: #ifdef _DEBUG
194:
195: extern "C"
196: {
197: void CDECL AfxTrace(const char* pszFormat, ...);
198: void PASCAL AfxAssertFailedLine(const char FAR* lpszFileName, int nLine);
199: void PASCAL AfxAssertValidObject(const CObject* pOb);
200: }
201: #define TRACE ::AfxTrace
202: #define THIS_FILE __FILE__
203: #define ASSERT(f) ((f) ? (void)0 : \
204: ::AfxAssertFailedLine(THIS_FILE, __LINE__))
205: #define VERIFY(f) ASSERT(f)
206: #define ASSERT_VALID(pOb) (::AfxAssertValidObject(pOb))
207:
208: #else
209:
210: #define ASSERT(f) ((void)0)
211: #define VERIFY(f) ((void)(f))
212: #define ASSERT_VALID(pOb) ((void)0)
213: inline void CDECL AfxTrace(const char* /* pszFormat */, ...) { }
214: #define TRACE 1 ? (void)0 : ::AfxTrace
215:
216: #endif // _DEBUG
217:
218: // Explicit extern for version API/Windows 3.0 loader problem
219: #ifdef _WINDOWS
220: extern "C" int FAR PASCAL __export _afx_version();
221: #else
222: extern "C" int FAR PASCAL _afx_version();
223: #endif
224:
225: // Turn off warnings for /W4
226: // To resume any of these warning: #pragma warning(default: 4xxx)
227: // which should be placed after the AFX include files
228: #ifndef ALL_WARNINGS
229: #pragma warning(disable: 4001) // nameless unions are part of C++
230: #pragma warning(disable: 4134) // message map member fxn casts
231: #pragma warning(disable: 4505) // optimize away locals
232: #pragma warning(disable: 4510) // default constructors are bad to have
233: #pragma warning(disable: 4511) // private copy constructors are good to have
234: #pragma warning(disable: 4512) // private operator= are good to have
235: #ifdef STRICT
236: #pragma warning(disable: 4305) // STRICT handles are near*, integer truncation
237: #endif
238: #endif
239:
240: /////////////////////////////////////////////////////////////////////////////
241: // Basic object model
242:
243: struct CRuntimeClass
244: {
245: // Attributes
246: const char* m_pszClassName;
247: int m_nObjectSize;
248: UINT m_wSchema; // schema number of the loaded class
249: void (PASCAL *m_pfnConstruct)(void* p); // NULL => abstract class
250: CRuntimeClass* m_pBaseClass;
251:
252: // Operations
253: CObject* CreateObject();
254: BOOL ConstructObject(void* pThis);
255: void Store(CArchive& ar);
256: static CRuntimeClass* Load(CArchive& ar, UINT* pwSchema);
257:
258: // Implementation
259: static CRuntimeClass* pFirstClass; // start of class list
260: CRuntimeClass* m_pNextClass; // linked list of registered classes
261: };
262:
263:
264: /////////////////////////////////////////////////////////////////////////////
265: // class CObject is the root of all compliant objects
266:
267: #if defined(_M_I86MM)
268: // force vtables to be in far code segments for medium model
269: class FAR CObjectRoot
270: {
271: protected:
272: virtual CRuntimeClass* GetRuntimeClass() NEAR const = 0;
273: };
274:
275: #pragma warning(disable: 4149) // don't warn for medium model change
276: class NEAR CObject : public CObjectRoot
277: #else
278: class CObject
279: #endif
280: {
281: public:
282:
283: // Object model (types, destruction, allocation)
284: virtual CRuntimeClass* GetRuntimeClass() const;
285: virtual ~CObject(); // virtual destructors are necessary
286:
287: // Diagnostic allocations
288: void* operator new(size_t, void* p);
289: void* operator new(size_t nSize);
290: void operator delete(void* p);
291:
292: #ifdef _DEBUG
293: // for file name/line number tracking using DEBUG_NEW
294: void* operator new(size_t nSize, const char FAR* lpszFileName, int nLine);
295: #endif
296:
297: // Disable the copy constructor and assignment by default so you will get
298: // compiler errors instead of unexpected behaviour if you pass objects
299: // by value or assign objects.
300: protected:
301: CObject();
302: private:
303: CObject(const CObject& objectSrc);
304: void operator=(const CObject& objectSrc);
305:
306: // Attributes
307: public:
308: BOOL IsSerializable() const;
309:
310: // Overridables
311: virtual void Serialize(CArchive& ar);
312:
313: // Diagnostic Support
314: virtual void AssertValid() const;
315: virtual void Dump(CDumpContext& dc) const;
316:
317: // Implementation
318: public:
319: // dynamic type checking/construction support
320: BOOL IsKindOf(const CRuntimeClass* pClass) const;
321: static void PASCAL Construct(void* pMemory);
322:
323: static CRuntimeClass NEAR classCObject;
324: };
325:
326: #if defined(_M_I86MM)
327: #pragma warning(default: 4149) // base class now ambient
328: #endif
329:
330:
331: // Helper macros
332: #define RUNTIME_CLASS(class_name) \
333: (&class_name::class##class_name)
334:
335: /////////////////////////////////////////////////////////////////////////////
336: // Helper macros for declaring compliant classes
337:
338: #define DECLARE_DYNAMIC(class_name) \
339: public: \
340: static CRuntimeClass NEAR class##class_name; \
341: virtual CRuntimeClass* GetRuntimeClass() const;
342:
343: #define DECLARE_SERIAL(class_name) \
344: DECLARE_DYNAMIC(class_name) \
345: static void PASCAL Construct(void* p); \
346: friend CArchive& operator>>(CArchive& ar, class_name* &pOb);
347:
348: // generate static object constructor for class registration
349: struct NEAR CClassInit
350: { CClassInit(CRuntimeClass* pNewClass); };
351:
352: #define IMPLEMENT_DYNAMIC(class_name, base_class_name) \
353: CRuntimeClass NEAR class_name::class##class_name = { \
354: #class_name, sizeof(class_name), 0xFFFF, NULL, \
355: &base_class_name::class##base_class_name, NULL }; \
356: static CClassInit _init_##class_name(&class_name::class##class_name);\
357: CRuntimeClass* class_name::GetRuntimeClass() const \
358: { return &class_name::class##class_name; } \
359: // end of IMPLEMENT_DYNAMIC
360:
361: #define IMPLEMENT_SERIAL(class_name, base_class_name, wSchema) \
362: void PASCAL class_name::Construct(void* p) \
363: { new(p) class_name; } \
364: CRuntimeClass NEAR class_name::class##class_name = { \
365: #class_name, sizeof(class_name), wSchema, \
366: &class_name::Construct, \
367: &base_class_name::class##base_class_name, NULL }; \
368: static CClassInit _init_##class_name(&class_name::class##class_name);\
369: CRuntimeClass* class_name::GetRuntimeClass() const \
370: { return &class_name::class##class_name; } \
371: CArchive& operator>>(CArchive& ar, class_name* &pOb) \
372: { ar >> (CObject*&) pOb; \
373: if ((pOb != NULL) && !pOb->IsKindOf(RUNTIME_CLASS(class_name))) \
374: AfxThrowArchiveException(CArchiveException::badClass);\
375: return ar; } \
376: // end of IMPLEMENT_SERIAL
377:
378: /////////////////////////////////////////////////////////////////////////////
379: // setjmp for Windows and C++
380:
1.1.1.3 ! root 381:
1.1 root 382: #ifdef _NTWIN
1.1.1.3 ! root 383: #ifdef _M_MRX000
! 384: typedef double jmp_buf[16];
1.1 root 385: #else
1.1.1.3 ! root 386: typedef int jmp_buf[8];
! 387: #define setjmp _setjmp
1.1 root 388: #endif
1.1.1.3 ! root 389: #else
! 390: typedef int jmp_buf[9];
1.1 root 391: #endif
392:
393: #if defined(_WINDOWS) && defined(_DOSWIN)
394: extern "C" int far pascal Catch(int FAR*);
395: #define setjmp ::Catch
396: #else
397: extern "C" int __cdecl setjmp(jmp_buf);
398: #endif
399:
400:
401: /////////////////////////////////////////////////////////////////////////////
402: // Exceptions
403:
404: typedef void (CDECL *AFX_TERM_PROC)();
405: struct CExceptionLink;
406:
407: AFX_TERM_PROC AfxSetTerminate(AFX_TERM_PROC);
408:
409: void CDECL AfxAbort();
410: void CDECL AfxTerminate();
411:
412: class CException : public CObject
413: {
414: // abstract class for dynamic type checking
415: DECLARE_DYNAMIC(CException)
416: };
417:
418: // Exception global state - never access directly
419: struct CExceptionContext
420: {
421: CException* m_pCurrent;
422: BOOL m_bDeleteWhenDone;
423: CExceptionLink* m_pLinkTop;
424:
425: void Throw(CException* pNewException);
426: void Throw(CException* pNewException, BOOL bShared);
427: void ThrowLast();
428:
429: void Cleanup(); // call to free up exception
430: };
431: extern CExceptionContext NEAR afxExceptionContext;
432:
433: // Placed on frame for EXCEPTION linkage
434: struct CExceptionLink
435: {
436: CExceptionLink* m_pLinkPrev;// previous top, next in handler chain
437: jmp_buf m_jumpBuf; // arg for setjmp/longjmp
438:
439: CExceptionLink(CExceptionLink* NEAR& rLinkTop);
440: ~CExceptionLink();
441: };
442:
443: /////////////////////////////////////////////////////////////////////////////
444: // Exception helper macros
445:
446: #define TRY \
447: { \
448: CExceptionLink _afxExLink(afxExceptionContext.m_pLinkTop); \
449: if (setjmp(_afxExLink.m_jumpBuf) == 0) \
450:
451: #define CATCH(class, e) \
452: else { if (afxExceptionContext.m_pCurrent->IsKindOf(RUNTIME_CLASS(class)))\
453: { class* e = (class*) afxExceptionContext.m_pCurrent;
454:
455: #define AND_CATCH(class, e) \
456: } else if (afxExceptionContext.m_pCurrent->IsKindOf(RUNTIME_CLASS(class)))\
457: { class* e = (class*) afxExceptionContext.m_pCurrent;
458:
459: #define END_CATCH \
460: } else { THROW(afxExceptionContext.m_pCurrent); } \
461: afxExceptionContext.Cleanup(); } }
462:
463: #define THROW(e) \
464: afxExceptionContext.Throw(e);
465: #define THROW_LAST() \
466: afxExceptionContext.ThrowLast();
467:
468: /////////////////////////////////////////////////////////////////////////////
469: // Standard Exception classes
470:
471: class CMemoryException : public CException
472: {
473: DECLARE_DYNAMIC(CMemoryException)
474: public:
475: CMemoryException();
476: };
477:
478: class CNotSupportedException : public CException
479: {
480: DECLARE_DYNAMIC(CNotSupportedException)
481: public:
482: CNotSupportedException();
483: };
484:
485: class CArchiveException : public CException
486: {
487: DECLARE_DYNAMIC(CArchiveException)
488: public:
489: enum {
490: none,
491: generic,
492: readOnly,
493: endOfFile,
494: writeOnly,
495: badIndex,
496: badClass,
497: badSchema
498: };
499:
500: // Constructor
501: CArchiveException(int cause = CArchiveException::none);
502:
503: // Attributes
504: int m_cause;
505:
506: #ifdef _DEBUG
507: virtual void Dump(CDumpContext& dc) const;
508: #endif
509: };
510:
511: class CFileException : public CException
512: {
513: DECLARE_DYNAMIC(CFileException)
514:
515: public:
516: enum {
517: none,
518: generic,
519: fileNotFound,
520: badPath,
521: tooManyOpenFiles,
522: accessDenied,
523: invalidFile,
524: removeCurrentDir,
525: directoryFull,
526: badSeek,
527: hardIO,
528: sharingViolation,
529: lockViolation,
530: diskFull,
1.1.1.2 root 531: endOfFile
1.1 root 532: };
533:
534: // Constructors
535:
536: CFileException(int cause = CFileException::none, LONG lOsError = -1);
537:
538: // Attributes
539: int m_cause;
540: LONG m_lOsError;
541:
542: // Operations
543:
544: // convert a OS dependent error code to a Cause
545: static int OsErrorToException(LONG lOsError);
546: static int ErrnoToException(int nErrno);
547:
548: // helper functions to throw exception after converting to a Cause
549: static void ThrowOsError(LONG lOsError);
550: static void ThrowErrno(int nErrno);
551:
552: #ifdef _DEBUG
553: virtual void Dump(CDumpContext&) const;
554: #endif
555: };
556:
557: /////////////////////////////////////////////////////////////////////////////
558: // Standard exception throws
559:
560: void PASCAL AfxThrowMemoryException();
561: void PASCAL AfxThrowNotSupportedException();
562: void PASCAL AfxThrowArchiveException(int cause);
563: void PASCAL AfxThrowFileException(int cause, LONG lOsError = -1);
564:
565:
566: /////////////////////////////////////////////////////////////////////////////
567: // File - raw unbuffered disk file I/O
568:
569: class CFile : public CObject
570: {
571: DECLARE_DYNAMIC(CFile)
572:
573: public:
574: // Flag values
575: enum OpenFlags {
576: modeRead = 0x0000,
577: modeWrite = 0x0001,
578: modeReadWrite = 0x0002,
579: shareCompat = 0x0000,
580: shareExclusive = 0x0010,
581: shareDenyWrite = 0x0020,
582: shareDenyRead = 0x0030,
583: shareDenyNone = 0x0040,
584: modeNoInherit = 0x0080,
585: modeCreate = 0x1000,
586: typeText = 0x4000, // typeText and typeBinary are used in
587: typeBinary = (int)0x8000 // derived classes only
588: };
589:
590: enum Attribute {
591: normal = 0x00,
592: readOnly = 0x01,
593: hidden = 0x02,
594: system = 0x04,
595: volume = 0x08,
596: directory = 0x10,
597: archive = 0x20
598: };
599:
600: enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };
601:
602: enum {hFileNull = -1};
603:
604: // Constructors
605: CFile();
606: CFile(int hFile);
607: CFile(const char* pszFileName, UINT nOpenFlags);
608:
609: // Attributes
610: UINT m_hFile;
611:
612: virtual DWORD GetPosition() const;
613: virtual BOOL GetStatus(CFileStatus& rStatus) const;
614:
615: // Operations
616: virtual BOOL Open(const char* pszFileName, UINT nOpenFlags, CFileException* pError = NULL);
617:
618: static void Rename(const char* pszOldName, const char* pszNewName);
619: static void Remove(const char* pszFileName);
620: static BOOL GetStatus(const char* pszFileName, CFileStatus& rStatus);
621: static void SetStatus(const char* pszFileName, const CFileStatus& status);
622:
623: DWORD SeekToEnd();
624: void SeekToBegin();
625:
626: // Overridables
627: virtual CFile* Duplicate() const;
628:
629: virtual LONG Seek(LONG lOff, UINT nFrom);
630: virtual void SetLength(DWORD dwNewLen);
631: virtual DWORD GetLength() const;
632:
633: virtual UINT Read(void FAR* lpBuf, UINT nCount);
634: virtual void Write(const void FAR* lpBuf, UINT nCount);
635:
636: virtual void LockRange(DWORD dwPos, DWORD dwCount);
637: virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
638:
639: virtual void Flush();
640: virtual void Close();
641:
642: #ifdef _DEBUG
643: virtual void AssertValid() const;
644: virtual void Dump(CDumpContext& dc) const;
645: #endif
646:
647: // Implementation
648: virtual ~CFile();
649: protected:
650: BOOL m_bCloseOnDelete;
651: };
652:
653: /////////////////////////////////////////////////////////////////////////////
654: // STDIO file implementation
655:
656: class CStdioFile : public CFile
657: {
658: DECLARE_DYNAMIC(CStdioFile)
659:
660: public:
661: // Constructors
662: CStdioFile();
663: CStdioFile(FILE* pOpenStream);
664: CStdioFile(const char* pszFileName, UINT nOpenFlags);
665:
666: // Attributes
667: FILE* m_pStream; // stdio FILE
668: // m_hFile from base class is _fileno(m_pStream)
669:
670: virtual DWORD GetPosition() const;
671:
672: // Overridables
673: virtual BOOL Open(const char* pszFileName, UINT nOpenFlags, CFileException* pError = NULL);
674: virtual UINT Read(void FAR* lpBuf, UINT nCount);
675: virtual void Write(const void FAR* lpBuf, UINT nCount);
676: virtual LONG Seek(LONG lOff, UINT nFrom);
677: virtual void Flush();
678: virtual void Close();
679:
680: virtual void WriteString(const char FAR* lpsz); // write a string, like "C" fputs
681: virtual char FAR* ReadString(char FAR* lpsz, UINT nMax); // like "C" fgets
682:
683: // Unsupported APIs
684: virtual CFile* Duplicate() const;
685: virtual void LockRange(DWORD dwPos, DWORD dwCount);
686: virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
687:
688:
689: #ifdef _DEBUG
690: void Dump(CDumpContext& dc) const;
691: #endif
692: // Implementation
693: virtual ~CStdioFile();
694: };
695:
696: ////////////////////////////////////////////////////////////////////////////
697: // Memory based file implementation
698:
699: class CMemFile : public CFile
700: {
701: DECLARE_DYNAMIC(CMemFile)
702:
703: public:
704: // Constructors
705: CMemFile(UINT nGrowBytes = 1024);
706:
707: // Attributes
708: virtual DWORD GetPosition() const;
709: virtual BOOL GetStatus(CFileStatus& rStatus) const;
710:
711: // Overridables
712: virtual LONG Seek(LONG lOff, UINT nFrom);
713: virtual void SetLength(DWORD dwNewLen);
714: virtual UINT Read(void FAR* lpBuf, UINT nCount);
715: virtual void Write(const void FAR* lpBuf, UINT nCount);
716: virtual void Flush();
717: virtual void Close();
718:
719: #ifdef _DEBUG
720: virtual void Dump(CDumpContext& dc) const;
721: virtual void AssertValid() const;
722: #endif
723:
724: // Unsupported APIs
725: virtual CFile* Duplicate() const;
726: virtual void LockRange(DWORD dwPos, DWORD dwCount);
727: virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
728:
729:
730: // Implementation
731: virtual ~CMemFile();
732:
733: protected:
734: virtual BYTE FAR* Alloc(UINT nBytes);
735: virtual BYTE FAR* Realloc(BYTE FAR* lpMem, UINT nBytes);
736: virtual BYTE FAR* Memcpy(BYTE FAR* lpMemTarget, const BYTE FAR* lpMemSource, UINT nCount);
737: virtual void Free(BYTE FAR* lpMem);
738: virtual void GrowFile(DWORD dwNewLen);
739:
740: UINT m_nGrowBytes;
741: UINT m_nPosition;
742: UINT m_nBufferSize;
743: UINT m_nFileSize;
744: BYTE FAR* m_lpBuffer;
745: };
746:
747: /////////////////////////////////////////////////////////////////////////////
748: // Strings
749:
750: class CString
751: {
752: public:
753:
754: // Constructors
755: CString();
756: CString(const CString& stringSrc);
757: CString(char ch, int nRepeat = 1);
758: CString(const char* psz);
759: CString(const char* pch, int nLength);
760: #ifdef _NEARDATA
761: // Additional versions for far string data
762: CString(const char FAR* lpsz);
763: CString(const char FAR* lpch, int nLength);
764: #endif
765: ~CString();
766:
767: // Attributes & Operations
768:
769: // as an array of characters
770: int GetLength() const;
771: BOOL IsEmpty() const;
772: void Empty(); // free up the data
773:
774: char GetAt(int nIndex) const; // 0 based
775: char operator[](int nIndex) const; // same as GetAt
776: void SetAt(int nIndex, char ch);
777: operator const char*() const; // as a C string
778:
779: // overloaded assignment
780: const CString& operator=(const CString& stringSrc);
781: const CString& operator=(char ch);
782: const CString& operator=(const char* psz);
783:
784: // string concatenation
785: const CString& operator+=(const CString& string);
786: const CString& operator+=(char ch);
787: const CString& operator+=(const char* psz);
788:
789: friend CString operator+(const CString& string1, const CString& string2);
790: friend CString operator+(const CString& string, char ch);
791: friend CString operator+(char ch, const CString& string);
792: friend CString operator+(const CString& string, const char* psz);
793: friend CString operator+(const char* psz, const CString& string);
794:
795: // string comparison
796: int Compare(const char* psz) const; // straight character
797: int CompareNoCase(const char* psz) const; // ignore case
798: int Collate(const char* psz) const; // NLS aware
799:
800: // simple sub-string extraction
801: CString Mid(int nFirst, int nCount) const;
802: CString Mid(int nFirst) const;
803: CString Left(int nCount) const;
804: CString Right(int nCount) const;
805:
806: CString SpanIncluding(const char* pszCharSet) const;
807: CString SpanExcluding(const char* pszCharSet) const;
808:
809: // upper/lower/reverse conversion
810: void MakeUpper();
811: void MakeLower();
812: void MakeReverse();
813:
814: // searching (return starting index, or -1 if not found)
815: // look for a single character match
816: int Find(char ch) const; // like "C" strchr
817: int ReverseFind(char ch) const;
818: int FindOneOf(const char* pszCharSet) const;
819:
820: // look for a specific sub-string
821: int Find(const char* pszSub) const; // like "C" strstr
822:
823: // input and output
824: #ifdef _DEBUG
825: friend CDumpContext& operator<<(CDumpContext&, const CString& string);
826: #endif
827: friend CArchive& operator<<(CArchive& ar, const CString& string);
828: friend CArchive& operator>>(CArchive& ar, CString& string);
829:
830: // Windows support
831: #ifdef _WINDOWS
832: BOOL LoadString(UINT nID); // load from string resource
833: // 255 chars max
834: // ANSI<->OEM support (convert string in place)
835: void AnsiToOem();
836: void OemToAnsi();
837: #endif //_WINDOWS
838:
839: // Access to string implementation buffer as "C" character array
840: char* GetBuffer(int nMinBufLength);
841: void ReleaseBuffer(int nNewLength = -1);
842: char* GetBufferSetLength(int nNewLength);
843:
844: // Implementation
845: protected:
846: // lengths/sizes in characters
847: // (note: an extra character is always allocated)
848: char* m_pchData; // actual string (zero terminated)
849: int m_nDataLength; // does not include terminating 0
850: int m_nAllocLength; // does not include terminating 0
851:
852: // implementation helpers
853: void Init();
854: void AllocCopy(CString& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
855: void AllocBuffer(int nLen);
856: void AssignCopy(int nSrcLen, const char* pszSrcData);
857: void ConcatCopy(int nSrc1Len, const char* pszSrc1Data, int nSrc2Len, const char* pszSrc2Data);
858: void ConcatInPlace(int nSrcLen, const char* pszSrcData);
859: };
860:
861:
862: // Compare helpers
863: BOOL operator==(const CString& s1, const CString& s2);
864: BOOL operator==(const CString& s1, const char* s2);
865: BOOL operator==(const char* s1, const CString& s2);
866: BOOL operator!=(const CString& s1, const CString& s2);
867: BOOL operator!=(const CString& s1, const char* s2);
868: BOOL operator!=(const char* s1, const CString& s2);
869: BOOL operator<(const CString& s1, const CString& s2);
870: BOOL operator<(const CString& s1, const char* s2);
871: BOOL operator<(const char* s1, const CString& s2);
872: BOOL operator>(const CString& s1, const CString& s2);
873: BOOL operator>(const CString& s1, const char* s2);
874: BOOL operator>(const char* s1, const CString& s2);
875: BOOL operator<=(const CString& s1, const CString& s2);
876: BOOL operator<=(const CString& s1, const char* s2);
877: BOOL operator<=(const char* s1, const CString& s2);
878: BOOL operator>=(const CString& s1, const CString& s2);
879: BOOL operator>=(const CString& s1, const char* s2);
880: BOOL operator>=(const char* s1, const CString& s2);
881:
882: /////////////////////////////////////////////////////////////////////////////
883: // CTimeSpan and CTime
884:
885: class CTimeSpan
886: {
887: public:
888:
889: // Constructors
890: CTimeSpan();
891: CTimeSpan(time_t time);
892: CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);
893:
894: CTimeSpan(const CTimeSpan& timeSpanSrc);
895: const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);
896:
897: // Attributes
898: // extract parts
899: LONG GetDays() const; // total # of days
900: LONG GetTotalHours() const;
901: int GetHours() const;
902: LONG GetTotalMinutes() const;
903: int GetMinutes() const;
904: LONG GetTotalSeconds() const;
905: int GetSeconds() const;
906:
907: // Operations
908: // time math
909: CTimeSpan operator-(CTimeSpan timeSpan) const;
910: CTimeSpan operator+(CTimeSpan timeSpan) const;
911: const CTimeSpan& operator+=(CTimeSpan timeSpan);
912: const CTimeSpan& operator-=(CTimeSpan timeSpan);
913: BOOL operator==(CTimeSpan timeSpan) const;
914: BOOL operator!=(CTimeSpan timeSpan) const;
915: BOOL operator<(CTimeSpan timeSpan) const;
916: BOOL operator>(CTimeSpan timeSpan) const;
917: BOOL operator<=(CTimeSpan timeSpan) const;
918: BOOL operator>=(CTimeSpan timeSpan) const;
919:
920: #ifndef _WINDLL
921: CString Format(const char* pFormat);
922: #endif //!_WINDLL
923:
924: // serialization
925: #ifdef _DEBUG
926: friend CDumpContext& operator<<(CDumpContext& dc, CTimeSpan timeSpan);
927: #endif
928: friend CArchive& operator<<(CArchive& ar, CTimeSpan timeSpan);
929: friend CArchive& operator>>(CArchive& ar, CTimeSpan& rtimeSpan);
930:
931: private:
932: time_t m_timeSpan;
933: friend class CTime;
934: };
935:
1.1.1.2 root 936: #ifdef _NTWIN
937: struct _SYSTEMTIME;
938: struct _FILETIME;
939: #endif
1.1 root 940:
941: class CTime
942: {
943: public:
944:
945: // Constructors
946: static CTime GetCurrentTime();
947:
948: CTime();
949: CTime(time_t time);
950: CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec);
951: CTime(WORD wDosDate, WORD wDosTime);
952: CTime(const CTime& timeSrc);
953:
954: #ifdef _NTWIN
955: CTime(const _SYSTEMTIME& sysTime);
956: CTime(const _FILETIME& fileTime);
957: #endif
958:
959: const CTime& operator=(const CTime& timeSrc);
960: const CTime& operator=(time_t t);
961:
962: // Attributes
963: struct tm* GetGmtTm(struct tm* ptm = NULL) const;
964: struct tm* GetLocalTm(struct tm* ptm = NULL) const;
965:
966: time_t GetTime() const;
967: int GetYear() const;
968: int GetMonth() const; // month of year (1 = Jan)
969: int GetDay() const; // day of month
970: int GetHour() const;
971: int GetMinute() const;
972: int GetSecond() const;
973: int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat
974:
975: // Operations
976: // time math
977: CTimeSpan operator-(CTime time) const;
978: CTime operator-(CTimeSpan timeSpan) const;
979: CTime operator+(CTimeSpan timeSpan) const;
980: const CTime& operator+=(CTimeSpan timeSpan);
981: const CTime& operator-=(CTimeSpan timeSpan);
982: BOOL operator==(CTime time) const;
983: BOOL operator!=(CTime time) const;
984: BOOL operator<(CTime time) const;
985: BOOL operator>(CTime time) const;
986: BOOL operator<=(CTime time) const;
987: BOOL operator>=(CTime time) const;
988:
989: // formatting using "C" strftime
990: #ifndef _WINDLL
991: CString Format(const char* pFormat);
992: CString FormatGmt(const char* pFormat);
993: #endif //!_WINDLL
994:
995: // serialization
996: #ifdef _DEBUG
997: friend CDumpContext& operator<<(CDumpContext& dc, CTime time);
998: #endif
999: friend CArchive& operator<<(CArchive& ar, CTime time);
1000: friend CArchive& operator>>(CArchive& ar, CTime& rtime);
1001:
1002: private:
1003: time_t m_time;
1004: };
1005:
1006: /////////////////////////////////////////////////////////////////////////////
1007: // File status
1008:
1009: struct CFileStatus
1010: {
1011: CTime m_ctime; // creation date/time of file
1012: CTime m_mtime; // last modification date/time of file
1013: CTime m_atime; // last access date/time of file
1014: LONG m_size; // logical size of file in bytes
1015: BYTE m_attribute; // logical OR of CFile::Attribute enum values
1016: BYTE _m_padding; // pad the structure to a WORD
1017: char m_szFullName[_MAX_PATH]; // absolute path name
1018:
1019: #ifdef _DEBUG
1020: void Dump(CDumpContext& dc) const;
1021: #endif
1022: };
1023:
1024:
1025: /////////////////////////////////////////////////////////////////////////////
1026: // Diagnostic memory management routines
1027:
1028: #ifdef _DEBUG
1029:
1030: extern "C" BOOL AfxDiagnosticInit(void);
1031:
1032: // Memory tracking allocation
1033: void* operator new(size_t nSize, const char FAR* lpszFileName, int nLine);
1034: #define DEBUG_NEW new(THIS_FILE, __LINE__)
1035:
1036: // Low level sanity checks for memory blocks
1037: extern "C" BOOL FAR PASCAL AfxIsValidAddress(const void FAR* lp,
1038: UINT nBytes, BOOL bReadWrite = TRUE);
1039: #ifdef _NEARDATA
1040: inline BOOL PASCAL AfxIsValidAddress(const void NEAR* np,
1041: UINT nBytes, BOOL bReadWrite = TRUE)
1042: { return np != NULL && ::AfxIsValidAddress((const void FAR*)np,
1043: nBytes, bReadWrite); }
1044: #endif
1045:
1046: // Return TRUE if valid memory block of nBytes
1047: BOOL PASCAL AfxIsMemoryBlock(const void* p, UINT nBytes, LONG* plRequestNumber = NULL);
1048:
1049: // Return TRUE if memory is sane or print out what is wrong
1050: BOOL PASCAL AfxCheckMemory();
1051:
1052: // Options for tuning the allocation diagnostics
1053: extern "C"
1054: {
1055: extern int afxMemDF; // global variable for easy setting in debugger
1056: }
1057:
1058: enum AfxMemDF // memory debug/diagnostic flags
1059: {
1060: allocMemDF = 0x01, // turn on debugging allocator
1061: delayFreeMemDF = 0x02, // delay freeing memory memory
1.1.1.2 root 1062: checkAlwaysMemDF = 0x04 // AfxCheckMemory on every alloc/free
1.1 root 1063: };
1064:
1065: // turn on/off tracking for a short while
1066: BOOL PASCAL AfxEnableMemoryTracking(BOOL bTrack);
1067:
1068: // Memory allocator failure simulation and control (_DEBUG only)
1069:
1070: // A failure hook returns whether to permit allocation
1071: typedef BOOL (PASCAL * AFX_ALLOC_HOOK)(size_t nSize, BOOL bObject, LONG lRequestNumber);
1072:
1073: // Set new hook, return old (never NULL)
1074: AFX_ALLOC_HOOK AfxSetAllocHook(AFX_ALLOC_HOOK pfnAllocHook);
1075:
1076: // Debugger hook on specified allocation request
1077: void PASCAL AfxSetAllocStop(LONG lRequestNumber);
1078:
1079: // Memory state for snapshots/leak detection
1080: struct CMemoryState
1081: {
1082: // Attributes
1083: enum blockUsage
1084: {
1085: freeBlock, // not used
1086: objectBlock, // contains a CObject derived class object
1087: bitBlock, // contains ::operator new data
1.1.1.2 root 1088: nBlockUseMax // total number of usages
1.1 root 1089: };
1090:
1091: struct CBlockHeader* m_pBlockHeader;
1092: LONG m_lCounts[nBlockUseMax];
1093: LONG m_lSizes[nBlockUseMax];
1094: LONG m_lHighWaterCount;
1095: LONG m_lTotalCount;
1096:
1097: CMemoryState();
1098:
1099: // Operations
1100: void Checkpoint(); // fill with current state
1101: BOOL Difference(const CMemoryState& oldState,
1102: const CMemoryState& newState); // fill with difference
1103:
1104: // Output to afxDump
1105: void DumpStatistics() const;
1106: void DumpAllObjectsSince() const;
1107: };
1108:
1109: // Enumerate allocated objects or runtime classes
1110: void PASCAL AfxDoForAllObjects(void (*pfn)(CObject* pObject, void* pContext), void* pContext);
1111: void PASCAL AfxDoForAllClasses(void (*pfn)(const CRuntimeClass* pClass, void* pContext), void* pContext);
1112:
1113: #else
1114:
1115: // NonDebug version that assume everything is OK
1116: #define DEBUG_NEW new
1117: #define AfxCheckMemory() TRUE
1118: #define AfxIsMemoryBlock(pBuf, nBytes) TRUE
1119:
1120: #endif // _DEBUG
1121:
1122: /////////////////////////////////////////////////////////////////////////////
1123: // Archives for serializing CObject data
1124:
1125: // needed for implementation
1126: class CPtrArray;
1127: class CMapPtrToWord;
1128:
1129: class CArchive
1130: {
1131: public:
1132: // Flag values
1133: enum Mode { store = 0, load = 1 };
1134:
1135: CArchive(CFile* pFile, UINT nMode, int nBufSize = 512, void FAR* lpBuf = NULL);
1136: ~CArchive();
1137:
1138: // Attributes
1139: BOOL IsLoading() const;
1140: BOOL IsStoring() const;
1141: CFile* GetFile() const;
1142:
1143: // Operations
1144: UINT Read(void FAR* lpBuf, UINT nMax);
1145: void Write(const void FAR* lpBuf, UINT nMax);
1146: void Flush();
1147: void Close();
1148:
1149: protected:
1150: void FillBuffer(UINT nBytesNeeded);
1151: CObject* ReadObject(const CRuntimeClass* pClass);
1152: void WriteObject(const CObject* pOb);
1153:
1154: public:
1155: // Object I/O is pointer based to avoid added construction overhead.
1156: // Use the Serialize member function directly for embedded objects.
1157: friend CArchive& operator<<(CArchive& ar, const CObject* pOb);
1158:
1159: friend CArchive& operator>>(CArchive& ar, CObject*& pOb);
1160: friend CArchive& operator>>(CArchive& ar, const CObject*& pOb);
1161:
1162: // insertion operations
1163: // NOTE: operators available only for fixed size types for portability
1164: CArchive& operator<<(BYTE by);
1165: CArchive& operator<<(WORD w);
1166: CArchive& operator<<(LONG l);
1167: CArchive& operator<<(DWORD dw);
1168:
1169: // extraction operations
1170: // NOTE: operators available only for fixed size types for portability
1171: CArchive& operator>>(BYTE& by);
1172: CArchive& operator>>(WORD& w);
1173: CArchive& operator>>(DWORD& dw);
1174: CArchive& operator>>(LONG& l);
1175:
1176: // Implementation
1177: protected:
1178: // archive objects cannot be copied or assigned
1179: CArchive(const CArchive& arSrc);
1180: void operator=(const CArchive& arSrc);
1181:
1182: BOOL m_nMode;
1183: BOOL m_bUserBuf;
1184: int m_nBufSize;
1185: CFile* m_pFile;
1186: BYTE FAR* m_lpBufCur;
1187: BYTE FAR* m_lpBufMax;
1188: BYTE FAR* m_lpBufStart;
1189:
1190: UINT m_nMapCount; // count and map used when storing
1191: union
1192: {
1193: CPtrArray* m_pLoadArray;
1194: CMapPtrToWord* m_pStoreMap;
1195: };
1196: };
1197:
1198:
1199: /////////////////////////////////////////////////////////////////////////////
1200: // Diagnostic dumping
1201:
1202: class CDumpContext
1203: {
1204: public:
1205: CDumpContext(CFile* pFile);
1206:
1207: // Attributes
1208: int GetDepth() const; // 0 => this object, 1 => children objects
1209: void SetDepth(int nNewDepth);
1210:
1211: // Operations
1212: CDumpContext& operator<<(const char FAR* lpsz);
1213: CDumpContext& operator<<(const void FAR* lp);
1214: #ifdef _NEARDATA
1215: CDumpContext& operator<<(const void NEAR* np);
1216: #endif
1217: CDumpContext& operator<<(const CObject* pOb);
1218: CDumpContext& operator<<(const CObject& ob);
1219: CDumpContext& operator<<(BYTE by);
1220: CDumpContext& operator<<(WORD w);
1221: CDumpContext& operator<<(UINT u);
1222: CDumpContext& operator<<(LONG l);
1223: CDumpContext& operator<<(DWORD dw);
1224: CDumpContext& operator<<(int n);
1225: void HexDump(const char* pszLine, BYTE* pby, int nBytes, int nWidth);
1226: void Flush();
1227:
1228: // Implementation
1229: protected:
1230: // dump context objects cannot be copied or assigned
1231: CDumpContext(const CDumpContext& dcSrc);
1232: void operator=(const CDumpContext& dcSrc);
1233: void OutputString(const char FAR* lpsz);
1234:
1235: int m_nDepth;
1236:
1237: public:
1238: CFile* m_pFile;
1239: };
1240:
1241: #ifdef _DEBUG
1242: extern CDumpContext& afxDump;
1243: extern "C" BOOL afxTraceEnabled;
1244: #endif
1245:
1246: /////////////////////////////////////////////////////////////////////////////
1247: // Other implementation helpers
1248:
1249: #define BEFORE_START_POSITION ((void*)(void NEAR*)-1)
1250: #define _AFX_FP_OFF(thing) (*((UINT*)&(thing)))
1251: #define _AFX_FP_SEG(lp) (*((UINT*)&(lp)+1))
1252:
1253:
1254: /////////////////////////////////////////////////////////////////////////////
1255: // Swap tuning for AFX library
1256:
1257: // Use BASED_CODE so that it may be easily redefined for tuning purposes
1258:
1259: // Data defined using this modifier is placed in the current
1260: // code segment, which is modified with #pragma code_seg
1261: #ifndef BASED_CODE
1262: #define BASED_CODE __based(__segname("_CODE"))
1263: #endif
1264:
1.1.1.2 root 1265: #ifndef _NTWIN
1.1 root 1266: #if defined(_M_I86MM) || defined(_M_I86LM) // far code
1267: #define AFX_CORE_SEG "AFX_CORE_TEXT" /* core functionality */
1268: #define AFX_AUX_SEG "AFX_AUX_TEXT" /* auxilliary functionality */
1269: #define AFX_COLL_SEG "AFX_COLL_TEXT" /* collections */
1270: #define AFX_OLE_SEG "AFX_OLE_TEXT" /* OLE support */
1271: #endif
1.1.1.2 root 1272: #endif
1273:
1.1 root 1274: /////////////////////////////////////////////////////////////////////////////
1275: // Inline function declarations
1276:
1277: #include "afx.inl"
1278:
1279: #endif // __AFX_H__
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.