afx.inl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 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 related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. // Inlines for AFX.H
  11. #ifdef _AFX_INLINE
  12. // CObject
  13. _AFX_INLINE CObject::CObject()
  14. { }
  15. _AFX_INLINE CObject::~CObject()
  16. { }
  17. // exceptions
  18. _AFX_INLINE CException::~CException()
  19. { }
  20. _AFX_INLINE CFileException::CFileException(int cause, LONG lOsError,
  21. LPCTSTR pstrFileName /* = NULL */)
  22. { m_cause = cause; m_lOsError = lOsError; m_strFileName = pstrFileName; }
  23. _AFX_INLINE CFileException::~CFileException()
  24. { }
  25. // CString
  26. _AFX_INLINE CStringData* CString::GetData() const
  27. { ASSERT(m_pchData != NULL); return ((CStringData*)m_pchData)-1; }
  28. _AFX_INLINE void CString::Init()
  29. { m_pchData = afxEmptyString.m_pchData; }
  30. _AFX_INLINE CString::CString()
  31. { m_pchData = afxEmptyString.m_pchData; }
  32. _AFX_INLINE CString::CString(const unsigned char* lpsz)
  33. { Init(); *this = (LPCSTR)lpsz; }
  34. _AFX_INLINE const CString& CString::operator=(const unsigned char* lpsz)
  35. { *this = (LPCSTR)lpsz; return *this; }
  36. _AFX_INLINE const CString& CString::operator+=(char ch)
  37. { *this += (TCHAR)ch; return *this; }
  38. _AFX_INLINE const CString& CString::operator=(char ch)
  39. { *this = (TCHAR)ch; return *this; }
  40. _AFX_INLINE CString AFXAPI operator+(const CString& string, char ch)
  41. { return string + (TCHAR)ch; }
  42. _AFX_INLINE CString AFXAPI operator+(char ch, const CString& string)
  43. { return (TCHAR)ch + string; }
  44. _AFX_INLINE int CString::GetLength() const
  45. { return GetData()->nDataLength; }
  46. _AFX_INLINE int CString::GetAllocLength() const
  47. { return GetData()->nAllocLength; }
  48. _AFX_INLINE BOOL CString::IsEmpty() const
  49. { return GetData()->nDataLength == 0; }
  50. _AFX_INLINE CString::operator LPCTSTR() const
  51. { return m_pchData; }
  52. _AFX_INLINE int PASCAL CString::SafeStrlen(LPCTSTR lpsz)
  53. { return (lpsz == NULL) ? 0 : lstrlen(lpsz); }
  54. // CString support (windows specific)
  55. _AFX_INLINE int CString::Compare(LPCTSTR lpsz) const
  56. { ASSERT(AfxIsValidString(lpsz)); return _tcscmp(m_pchData, lpsz); } // MBCS/Unicode aware
  57. _AFX_INLINE int CString::CompareNoCase(LPCTSTR lpsz) const
  58. { ASSERT(AfxIsValidString(lpsz)); return _tcsicmp(m_pchData, lpsz); } // MBCS/Unicode aware
  59. _AFX_INLINE TCHAR CString::GetAt(int nIndex) const
  60. {
  61. ASSERT(nIndex >= 0);
  62. ASSERT(nIndex < GetData()->nDataLength);
  63. return m_pchData[nIndex];
  64. }
  65. _AFX_INLINE TCHAR CString::operator[](int nIndex) const
  66. {
  67. // same as GetAt
  68. ASSERT(nIndex >= 0);
  69. ASSERT(nIndex < GetData()->nDataLength);
  70. return m_pchData[nIndex];
  71. }
  72. _AFX_INLINE bool AFXAPI operator==(const CString& s1, const CString& s2)
  73. { return s1.Compare(s2) == 0; }
  74. _AFX_INLINE bool AFXAPI operator==(const CString& s1, LPCTSTR s2)
  75. { return s1.Compare(s2) == 0; }
  76. _AFX_INLINE bool AFXAPI operator==(LPCTSTR s1, const CString& s2)
  77. { return s2.Compare(s1) == 0; }
  78. _AFX_INLINE bool AFXAPI operator!=(const CString& s1, const CString& s2)
  79. { return s1.Compare(s2) != 0; }
  80. _AFX_INLINE bool AFXAPI operator!=(const CString& s1, LPCTSTR s2)
  81. { return s1.Compare(s2) != 0; }
  82. _AFX_INLINE bool AFXAPI operator!=(LPCTSTR s1, const CString& s2)
  83. { return s2.Compare(s1) != 0; }
  84. _AFX_INLINE bool AFXAPI operator<(const CString& s1, const CString& s2)
  85. { return s1.Compare(s2) < 0; }
  86. _AFX_INLINE bool AFXAPI operator<(const CString& s1, LPCTSTR s2)
  87. { return s1.Compare(s2) < 0; }
  88. _AFX_INLINE bool AFXAPI operator<(LPCTSTR s1, const CString& s2)
  89. { return s2.Compare(s1) > 0; }
  90. // CTime and CTimeSpan
  91. _AFX_INLINE CTimeSpan::CTimeSpan(time_t time)
  92. { m_timeSpan = time; }
  93. _AFX_INLINE CTimeSpan::CTimeSpan(const CTimeSpan& timeSpanSrc)
  94. { m_timeSpan = timeSpanSrc.m_timeSpan; }
  95. _AFX_INLINE const CTimeSpan& CTimeSpan::operator=(const CTimeSpan& timeSpanSrc)
  96. { m_timeSpan = timeSpanSrc.m_timeSpan; return *this; }
  97. _AFX_INLINE LONG CTimeSpan::GetTotalSeconds() const
  98. { return m_timeSpan; }
  99. _AFX_INLINE BOOL CTimeSpan::operator==(CTimeSpan timeSpan) const
  100. { return m_timeSpan == timeSpan.m_timeSpan; }
  101. _AFX_INLINE BOOL CTimeSpan::operator!=(CTimeSpan timeSpan) const
  102. { return m_timeSpan != timeSpan.m_timeSpan; }
  103. _AFX_INLINE CTime::CTime()
  104. { }
  105. _AFX_INLINE CTime::CTime(time_t time)
  106. { m_time = time; }
  107. _AFX_INLINE CTime::CTime(const CTime& timeSrc)
  108. { m_time = timeSrc.m_time; }
  109. _AFX_INLINE const CTime& CTime::operator=(const CTime& timeSrc)
  110. { m_time = timeSrc.m_time; return *this; }
  111. _AFX_INLINE const CTime& CTime::operator=(time_t t)
  112. { m_time = t; return *this; }
  113. _AFX_INLINE time_t CTime::GetTime() const
  114. { return m_time; }
  115. _AFX_INLINE int CTime::GetYear() const
  116. { return (GetLocalTm(NULL)->tm_year) + 1900; }
  117. _AFX_INLINE int CTime::GetMonth() const
  118. { return GetLocalTm(NULL)->tm_mon + 1; }
  119. _AFX_INLINE int CTime::GetDay() const
  120. { return GetLocalTm(NULL)->tm_mday; }
  121. _AFX_INLINE int CTime::GetHour() const
  122. { return GetLocalTm(NULL)->tm_hour; }
  123. _AFX_INLINE int CTime::GetMinute() const
  124. { return GetLocalTm(NULL)->tm_min; }
  125. _AFX_INLINE CTimeSpan CTime::operator-(CTime time) const
  126. { return CTimeSpan(m_time - time.m_time); }
  127. _AFX_INLINE BOOL CTime::operator==(CTime time) const
  128. { return m_time == time.m_time; }
  129. _AFX_INLINE BOOL CTime::operator!=(CTime time) const
  130. { return m_time != time.m_time; }
  131. /////////////////////////////////////////////////////////////////////////////
  132. #endif //_AFX_INLINE