123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- // This is a part of the Microsoft Foundation Classes C++ library.
- // Copyright (C) 1992-1998 Microsoft Corporation
- // All rights reserved.
- //
- // This source code is only intended as a supplement to the
- // Microsoft Foundation Classes Reference and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding the
- // Microsoft Foundation Classes product.
- #ifndef __AFX_H__
- #define __AFX_H__
- #ifndef __cplusplus
- #error MFC requires C++ compilation (use a .cpp suffix)
- #endif
- /////////////////////////////////////////////////////////////////////////////
- #include <afxver_.h> // Target version control
- /////////////////////////////////////////////////////////////////////////////
- // Other includes from standard "C" runtimes
- #include <System.hpp>
- /////////////////////////////////////////////////////////////////////////////
- // Diagnostic support
- #define ASSERT(f) ((void)0)
- #define VERIFY(f) ((void)(f))
- #define ASSERT_VALID(pOb) ((void)0)
- #define TRACE0(sz)
- #define TRACE1(sz, p1)
- #define TRACE2(sz, p1, p2)
- #define TRACE3(sz, p1, p2, p3)
- /////////////////////////////////////////////////////////////////////////////
- // Turn off warnings for /W4
- // To resume any of these warning: #pragma warning(default: 4xxx)
- // which should be placed after the AFX include files
- #ifndef ALL_WARNINGS
- // warnings generated with common MFC/Windows code
- #pragma warning(disable: 4127) // constant expression for TRACE/ASSERT
- #pragma warning(disable: 4134) // message map member fxn casts
- #pragma warning(disable: 4201) // nameless unions are part of C++
- #pragma warning(disable: 4511) // private copy constructors are good to have
- #pragma warning(disable: 4512) // private operator= are good to have
- #pragma warning(disable: 4514) // unreferenced inlines are common
- #pragma warning(disable: 4710) // private constructors are disallowed
- #pragma warning(disable: 4705) // statement has no effect in optimized code
- #pragma warning(disable: 4191) // pointer-to-function casting
- // warnings caused by normal optimizations
- #pragma warning(disable: 4701) // local variable *may* be used without init
- #pragma warning(disable: 4702) // unreachable code caused by optimizations
- #pragma warning(disable: 4791) // loss of debugging info in release version
- #pragma warning(disable: 4189) // initialized but unused variable
- #pragma warning(disable: 4390) // empty controlled statement
- #endif //!ALL_WARNINGS
- #define UNUSED(x) (static_cast<const void *>(&x) == static_cast<const void *>(&x))
- /////////////////////////////////////////////////////////////////////////////
- // Basic object model
- /////////////////////////////////////////////////////////////////////////////
- // Strings
- class CString
- {
- public:
- // Constructors
- // constructs empty CString
- CString();
- // copy constructor
- CString(const CString& stringSrc);
- // copy constructor
- explicit CString(const UnicodeString& str);
- // from an ANSI string (converts to TCHAR)
- CString(LPCSTR lpsz);
- // from a UNICODE string (converts to TCHAR)
- CString(LPCWSTR lpsz);
- // subset of characters from an ANSI string (converts to TCHAR)
- CString(LPCSTR lpch, int nLength);
- // subset of characters from a UNICODE string (converts to TCHAR)
- CString(LPCWSTR lpch, int nLength);
- // from unsigned characters
- CString(const unsigned char* psz);
- // Attributes & Operations
- // get data length
- int GetLength() const;
- // TRUE if zero length
- BOOL IsEmpty() const;
- // clear contents to empty
- void Empty();
- // return single character at zero-based index
- TCHAR GetAt(int nIndex) const;
- // return single character at zero-based index
- TCHAR operator[](int nIndex) const;
- // set a single character at zero-based index
- void SetAt(int nIndex, TCHAR ch);
- // return pointer to const string
- operator LPCTSTR() const;
- // overloaded assignment
- // ref-counted copy from another CString
- const CString& operator=(const CString& stringSrc);
- // set string content to single character
- const CString& operator=(TCHAR ch);
- const CString& operator=(char ch);
- // copy string content from ANSI string (converts to TCHAR)
- const CString& operator=(LPCSTR lpsz);
- // copy string content from UNICODE string (converts to TCHAR)
- const CString& operator=(LPCWSTR lpsz);
- // copy string content from unsigned chars
- const CString& operator=(const unsigned char* psz);
- // string concatenation
- // concatenate from another CString
- const CString& operator+=(const CString& string);
- // concatenate a single character
- const CString& operator+=(TCHAR ch);
- // concatenate an ANSI character after converting it to TCHAR
- const CString& operator+=(char ch);
- // concatenate a UNICODE character after converting it to TCHAR
- const CString& operator+=(LPCTSTR lpsz);
- friend CString AFXAPI operator+(const CString& string1,
- const CString& string2);
- friend CString AFXAPI operator+(const CString& string, TCHAR ch);
- friend CString AFXAPI operator+(TCHAR ch, const CString& string);
- friend CString AFXAPI operator+(const CString& string, char ch);
- friend CString AFXAPI operator+(char ch, const CString& string);
- friend CString AFXAPI operator+(const CString& string, LPCTSTR lpsz);
- friend CString AFXAPI operator+(LPCTSTR lpsz, const CString& string);
- // string comparison
- // straight character comparison
- int Compare(LPCTSTR lpsz) const;
- // compare ignoring case
- int CompareNoCase(LPCTSTR lpsz) const;
- // simple sub-string extraction
- // return nCount characters starting at zero-based nFirst
- CString Mid(int nFirst, int nCount) const;
- // return all characters starting at zero-based nFirst
- CString Mid(int nFirst) const;
- // return first nCount characters in string
- CString Left(int nCount) const;
- // return nCount characters from end of string
- CString Right(int nCount) const;
- // NLS aware conversion to lowercase
- void MakeLower();
- // trimming anything (either side)
- // remove continuous occurrences of chTarget starting from right
- void TrimRight(TCHAR chTarget);
- // remove continuous occcurrences of characters in passed string,
- // starting from right
- void TrimRight(LPCTSTR lpszTargets);
- // remove continuous occurrences of chTarget starting from left
- void TrimLeft(TCHAR chTarget);
- // remove continuous occcurrences of characters in
- // passed string, starting from left
- void TrimLeft(LPCTSTR lpszTargets);
- // advanced manipulation
- // replace occurrences of chOld with chNew
- int Replace(TCHAR chOld, TCHAR chNew);
- // replace occurrences of substring lpszOld with lpszNew;
- // empty lpszNew removes instances of lpszOld
- BOOL Replace(LPCTSTR lpszOld, LPCTSTR lpszNew);
- // delete nCount characters starting at zero-based index
- int Delete(int nIndex, int nCount = 1);
- // searching
- // find character starting at left, -1 if not found
- int Find(TCHAR ch) const;
- // find character starting at right
- int ReverseFind(TCHAR ch) const;
- // find character starting at zero-based index and going right
- int Find(TCHAR ch, int nStart) const;
- // find first instance of any character in passed string
- int FindOneOf(LPCTSTR lpszCharSet) const;
- // find first instance of substring
- int Find(LPCTSTR lpszSub) const;
- // find first instance of substring starting at zero-based index
- int Find(LPCTSTR lpszSub, int nStart) const;
- // simple formatting
- // printf-like formatting using passed string
- void Format(LPCTSTR lpszFormat, ...);
- // printf-like formatting using referenced string resource
- void Format(UINT nFormatID, ...);
- // printf-like formatting using variable arguments parameter
- void FormatV(LPCTSTR lpszFormat, va_list argList);
- // load from string resource
- BOOL LoadString(UINT nID);
- // Implementation
- protected:
- UnicodeString m_Data;
- };
- // Compare helpers
- bool AFXAPI operator==(const CString& s1, const CString& s2);
- bool AFXAPI operator==(const CString& s1, LPCTSTR s2);
- bool AFXAPI operator==(LPCTSTR s1, const CString& s2);
- bool AFXAPI operator!=(const CString& s1, const CString& s2);
- bool AFXAPI operator!=(const CString& s1, LPCTSTR s2);
- bool AFXAPI operator!=(LPCTSTR s1, const CString& s2);
- bool AFXAPI operator<(const CString& s1, const CString& s2);
- bool AFXAPI operator<(const CString& s1, LPCTSTR s2);
- bool AFXAPI operator<(LPCTSTR s1, const CString& s2);
- /////////////////////////////////////////////////////////////////////////////
- // Standard Exception classes
- class CFileException
- {
- public:
- enum {
- none,
- generic,
- fileNotFound,
- badPath,
- tooManyOpenFiles,
- accessDenied,
- invalidFile,
- removeCurrentDir,
- directoryFull,
- badSeek,
- hardIO,
- sharingViolation,
- lockViolation,
- diskFull,
- endOfFile
- };
- // Constructor
- CFileException(int cause = CFileException::none, LONG lOsError = -1,
- LPCTSTR lpszArchiveName = NULL);
- // Attributes
- int m_cause;
- LONG m_lOsError;
- CString m_strFileName;
- // Operations
- // convert a OS dependent error code to a Cause
- static int OsErrorToException(LONG lOsError);
- // helper functions to throw exception after converting to a Cause
- static void ThrowOsError(LONG lOsError, LPCTSTR lpszFileName = NULL);
- // Implementation
- public:
- BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
- PUINT pnHelpContext = NULL);
- };
- /////////////////////////////////////////////////////////////////////////////
- // Standard exception throws
- void AFXAPI AfxThrowFileException(int cause, LONG lOsError = -1,
- LPCTSTR lpszFileName = NULL);
- /////////////////////////////////////////////////////////////////////////////
- // File - raw unbuffered disk file I/O
- class CFile
- {
- public:
- // Flag values
- enum OpenFlags {
- modeRead = 0x0000,
- modeWrite = 0x0001,
- modeReadWrite = 0x0002,
- shareCompat = 0x0000,
- shareExclusive = 0x0010,
- shareDenyWrite = 0x0020,
- shareDenyRead = 0x0030,
- shareDenyNone = 0x0040,
- modeNoInherit = 0x0080,
- modeCreate = 0x1000,
- modeNoTruncate = 0x2000,
- typeText = 0x4000, // typeText and typeBinary are used in
- typeBinary = (int)0x8000 // derived classes only
- };
- enum { hFileNull = -1 };
- // Constructors
- CFile();
- // Attributes
- UINT m_hFile;
- // Operations
- BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
- CFileException* pError = NULL);
- static BOOL IsValid(LPCTSTR lpszFileName);
- // Overridables
- UINT Read(void* lpBuf, UINT nCount);
- void Write(const void* lpBuf, UINT nCount);
- void Close();
- // Implementation
- public:
- ~CFile();
- protected:
- BOOL m_bCloseOnDelete;
- CString m_strFileName;
- };
- /////////////////////////////////////////////////////////////////////////////
- // CTimeSpan and CTime
- class CTimeSpan
- {
- public:
- // Constructors
- CTimeSpan();
- CTimeSpan(time_t time);
- CTimeSpan(const CTimeSpan& timeSpanSrc);
- const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);
- // Attributes
- // extract parts
- LONG GetTotalSeconds() const;
- // Operations
- // time math
- BOOL operator==(CTimeSpan timeSpan) const;
- BOOL operator!=(CTimeSpan timeSpan) const;
- private:
- time_t m_timeSpan;
- };
- class CTime
- {
- public:
- // Constructors
- static CTime CreateForCurrentTime();
- CTime();
- CTime(time_t time);
- CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
- int nDST = -1);
- CTime(const CTime& timeSrc);
- CTime(const SYSTEMTIME& sysTime, int nDST = -1);
- CTime(const FILETIME& fileTime, int nDST = -1);
- const CTime& operator=(const CTime& timeSrc);
- const CTime& operator=(time_t t);
- // Attributes
- struct tm* GetLocalTm(struct tm* ptm = NULL) const;
- time_t GetTime() const;
- int GetYear() const;
- int GetMonth() const; // month of year (1 = Jan)
- int GetDay() const; // day of month
- int GetHour() const;
- int GetMinute() const;
- // Operations
- // time math
- CTimeSpan operator-(CTime time) const;
- BOOL operator==(CTime time) const;
- BOOL operator!=(CTime time) const;
- private:
- time_t m_time;
- };
- /////////////////////////////////////////////////////////////////////////////
- // Inline function declarations
- #ifdef _AFX_ENABLE_INLINES
- #define _AFX_INLINE AFX_INLINE
- #include <afx.inl>
- #endif
- #ifdef WINSCP
- extern HINSTANCE afxCurrentResourceHandle;
- #endif
- #endif // __AFX_H__
- /////////////////////////////////////////////////////////////////////////////
|