home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / INCLUDE / AFX.IN_ / AFX.IN
Encoding:
Text File  |  1993-02-08  |  13.5 KB  |  335 lines

  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 and/or WinHelp documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. // Inlines for AFX.H
  12.  
  13. #ifdef _AFX_INLINE
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16.  
  17. // CObject
  18. _AFX_INLINE CObject::CObject()
  19.     { }
  20. _AFX_INLINE CObject::~CObject()
  21.     { }
  22. _AFX_INLINE void CObject::Serialize(CArchive&)
  23.     { /* CObject does not serialize anything by default */ }
  24. _AFX_INLINE void* CObject::operator new(size_t, void* p)
  25.     { return p; }
  26. #ifndef _DEBUG
  27. // _DEBUG versions in memory.cpp
  28. _AFX_INLINE void CObject::operator delete(void* p)
  29.     { ::operator delete(p); }
  30. _AFX_INLINE void* CObject::operator new(size_t nSize)
  31.     { return ::operator new(nSize); }
  32. #endif
  33.  
  34.  
  35. // exceptions
  36. _AFX_INLINE CMemoryException::CMemoryException()
  37.     { }
  38. _AFX_INLINE CNotSupportedException::CNotSupportedException()
  39.     { }
  40. _AFX_INLINE CArchiveException::CArchiveException(int cause /* = CArchiveException::none */)
  41.     { m_cause = cause; }
  42. _AFX_INLINE CFileException::CFileException(int cause /* = CFileException::none */, LONG lOsError /* = -1 */)
  43.     { m_cause = cause; m_lOsError = lOsError; }
  44.  
  45.  
  46. // CFile
  47.  
  48. _AFX_INLINE DWORD CFile::SeekToEnd()
  49.     { return Seek(0, CFile::end); }
  50. _AFX_INLINE void CFile::SeekToBegin()
  51.     { Seek(0, CFile::begin); }
  52.  
  53. // CString
  54. _AFX_INLINE int CString::GetLength() const
  55.     { return m_nDataLength; }
  56. _AFX_INLINE BOOL CString::IsEmpty() const
  57.     { return m_nDataLength == 0; }
  58. _AFX_INLINE CString::operator const char*() const
  59.     { return (const char*)m_pchData; }
  60. #ifndef _WINDOWS
  61. _AFX_INLINE int CString::Compare(const char* psz) const
  62.     { return strcmp(m_pchData, psz); }
  63. _AFX_INLINE int CString::CompareNoCase(const char* psz) const
  64.     { return _stricmp(m_pchData, psz); }
  65. _AFX_INLINE int CString::Collate(const char* psz) const
  66.     { return strcoll(m_pchData, psz); }
  67. _AFX_INLINE void CString::MakeUpper()
  68.     { _strupr(m_pchData); }
  69. _AFX_INLINE void CString::MakeLower()
  70.     { _strlwr(m_pchData); }
  71. // Windows version in AFXWIN.H
  72. #endif //!_WINDOWS
  73.  
  74. _AFX_INLINE void CString::MakeReverse()
  75.     { _strrev(m_pchData); }
  76. _AFX_INLINE char CString::GetAt(int nIndex) const
  77.     {
  78.         ASSERT(nIndex >= 0);
  79.         ASSERT(nIndex < m_nDataLength);
  80.  
  81.         return m_pchData[nIndex];
  82.     }
  83. _AFX_INLINE char CString::operator[](int nIndex) const
  84.     {
  85.         // same as GetAt
  86.  
  87.         ASSERT(nIndex >= 0);
  88.         ASSERT(nIndex < m_nDataLength);
  89.  
  90.         return m_pchData[nIndex];
  91.     }
  92. _AFX_INLINE void CString::SetAt(int nIndex, char ch)
  93.     {
  94.         ASSERT(nIndex >= 0);
  95.         ASSERT(nIndex < m_nDataLength);
  96.         ASSERT(ch != 0);
  97.  
  98.         m_pchData[nIndex] = ch;
  99.     }
  100. _AFX_INLINE BOOL AFXAPI operator==(const CString& s1, const CString& s2)
  101.     { return s1.Compare(s2) == 0; }
  102. _AFX_INLINE BOOL AFXAPI operator==(const CString& s1, const char* s2)
  103.     { return s1.Compare(s2) == 0; }
  104. _AFX_INLINE BOOL AFXAPI operator==(const char* s1, const CString& s2)
  105.     { return s2.Compare(s1) == 0; }
  106. _AFX_INLINE BOOL AFXAPI operator!=(const CString& s1, const CString& s2)
  107.     { return s1.Compare(s2) != 0; }
  108. _AFX_INLINE BOOL AFXAPI operator!=(const CString& s1, const char* s2)
  109.     { return s1.Compare(s2) != 0; }
  110. _AFX_INLINE BOOL AFXAPI operator!=(const char* s1, const CString& s2)
  111.     { return s2.Compare(s1) != 0; }
  112. _AFX_INLINE BOOL AFXAPI operator<(const CString& s1, const CString& s2)
  113.     { return s1.Compare(s2) < 0; }
  114. _AFX_INLINE BOOL AFXAPI operator<(const CString& s1, const char* s2)
  115.     { return s1.Compare(s2) < 0; }
  116. _AFX_INLINE BOOL AFXAPI operator<(const char* s1, const CString& s2)
  117.     { return s2.Compare(s1) > 0; }
  118. _AFX_INLINE BOOL AFXAPI operator>(const CString& s1, const CString& s2)
  119.     { return s1.Compare(s2) > 0; }
  120. _AFX_INLINE BOOL AFXAPI operator>(const CString& s1, const char* s2)
  121.     { return s1.Compare(s2) > 0; }
  122. _AFX_INLINE BOOL AFXAPI operator>(const char* s1, const CString& s2)
  123.     { return s2.Compare(s1) < 0; }
  124. _AFX_INLINE BOOL AFXAPI operator<=(const CString& s1, const CString& s2)
  125.     { return s1.Compare(s2) <= 0; }
  126. _AFX_INLINE BOOL AFXAPI operator<=(const CString& s1, const char* s2)
  127.     { return s1.Compare(s2) <= 0; }
  128. _AFX_INLINE BOOL AFXAPI operator<=(const char* s1, const CString& s2)
  129.     { return s2.Compare(s1) >= 0; }
  130. _AFX_INLINE BOOL AFXAPI operator>=(const CString& s1, const CString& s2)
  131.     { return s1.Compare(s2) >= 0; }
  132. _AFX_INLINE BOOL AFXAPI operator>=(const CString& s1, const char* s2)
  133.     { return s1.Compare(s2) >= 0; }
  134. _AFX_INLINE BOOL AFXAPI operator>=(const char* s1, const CString& s2)
  135.     { return s2.Compare(s1) <= 0; }
  136.  
  137. // CTime and CTimeSpan
  138. _AFX_INLINE CTimeSpan::CTimeSpan()
  139.     { }
  140. _AFX_INLINE CTimeSpan::CTimeSpan(time_t time)
  141.     { m_timeSpan = time; }
  142. _AFX_INLINE CTimeSpan::CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs)
  143.     { m_timeSpan = nSecs + 60* (nMins + 60* (nHours + 24* lDays)); }
  144. _AFX_INLINE CTimeSpan::CTimeSpan(const CTimeSpan& timeSpanSrc)
  145.     { m_timeSpan = timeSpanSrc.m_timeSpan; }
  146. _AFX_INLINE const CTimeSpan& CTimeSpan::operator=(const CTimeSpan& timeSpanSrc)
  147.     { m_timeSpan = timeSpanSrc.m_timeSpan; return *this; }
  148. _AFX_INLINE LONG CTimeSpan::GetDays() const
  149.     { return m_timeSpan / (24*3600L); }
  150. _AFX_INLINE LONG CTimeSpan::GetTotalHours() const
  151.     { return m_timeSpan/3600; }
  152. _AFX_INLINE int CTimeSpan::GetHours() const
  153.     { return (int)(GetTotalHours() - GetDays()*24); }
  154. _AFX_INLINE LONG CTimeSpan::GetTotalMinutes() const
  155.     { return m_timeSpan/60; }
  156. _AFX_INLINE int CTimeSpan::GetMinutes() const
  157.     { return (int)(GetTotalMinutes() - GetTotalHours()*60); }
  158. _AFX_INLINE LONG CTimeSpan::GetTotalSeconds() const
  159.     { return m_timeSpan; }
  160. _AFX_INLINE int CTimeSpan::GetSeconds() const
  161.     { return (int)(GetTotalSeconds() - GetTotalMinutes()*60); }
  162. _AFX_INLINE CTimeSpan CTimeSpan::operator-(CTimeSpan timeSpan) const
  163.     { return CTimeSpan(m_timeSpan - timeSpan.m_timeSpan); }
  164. _AFX_INLINE CTimeSpan CTimeSpan::operator+(CTimeSpan timeSpan) const
  165.     { return CTimeSpan(m_timeSpan + timeSpan.m_timeSpan); }
  166. _AFX_INLINE const CTimeSpan& CTimeSpan::operator+=(CTimeSpan timeSpan)
  167.     { m_timeSpan += timeSpan.m_timeSpan; return *this; }
  168. _AFX_INLINE const CTimeSpan& CTimeSpan::operator-=(CTimeSpan timeSpan)
  169.     { m_timeSpan -= timeSpan.m_timeSpan; return *this; }
  170. _AFX_INLINE BOOL CTimeSpan::operator==(CTimeSpan timeSpan) const
  171.     { return m_timeSpan == timeSpan.m_timeSpan; }
  172. _AFX_INLINE BOOL CTimeSpan::operator!=(CTimeSpan timeSpan) const
  173.     { return m_timeSpan != timeSpan.m_timeSpan; }
  174. _AFX_INLINE BOOL CTimeSpan::operator<(CTimeSpan timeSpan) const
  175.     { return m_timeSpan < timeSpan.m_timeSpan; }
  176. _AFX_INLINE BOOL CTimeSpan::operator>(CTimeSpan timeSpan) const
  177.     { return m_timeSpan > timeSpan.m_timeSpan; }
  178. _AFX_INLINE BOOL CTimeSpan::operator<=(CTimeSpan timeSpan) const
  179.     { return m_timeSpan <= timeSpan.m_timeSpan; }
  180. _AFX_INLINE BOOL CTimeSpan::operator>=(CTimeSpan timeSpan) const
  181.     { return m_timeSpan >= timeSpan.m_timeSpan; }
  182.  
  183.  
  184. _AFX_INLINE CTime::CTime()
  185.     { }
  186. _AFX_INLINE CTime::CTime(time_t time)
  187.     { m_time = time; }
  188. _AFX_INLINE CTime::CTime(const CTime& timeSrc)
  189.     { m_time = timeSrc.m_time; }
  190. _AFX_INLINE const CTime& CTime::operator=(const CTime& timeSrc)
  191.     { m_time = timeSrc.m_time; return *this; }
  192. _AFX_INLINE const CTime& CTime::operator=(time_t t)
  193.     { m_time = t; return *this; }
  194. _AFX_INLINE time_t CTime::GetTime() const
  195.     { return m_time; }
  196. _AFX_INLINE int CTime::GetYear() const
  197.     { return (GetLocalTm(NULL)->tm_year) + 1900; }
  198. _AFX_INLINE int CTime::GetMonth() const
  199.     { return GetLocalTm(NULL)->tm_mon + 1; }
  200. _AFX_INLINE int CTime::GetDay() const
  201.     { return GetLocalTm(NULL)->tm_mday; }
  202. _AFX_INLINE int CTime::GetHour() const
  203.     { return GetLocalTm(NULL)->tm_hour; }
  204. _AFX_INLINE int CTime::GetMinute() const
  205.     { return GetLocalTm(NULL)->tm_min; }
  206. _AFX_INLINE int CTime::GetSecond() const
  207.     { return GetLocalTm(NULL)->tm_sec; }
  208. _AFX_INLINE int CTime::GetDayOfWeek() const
  209.     { return GetLocalTm(NULL)->tm_wday + 1; }
  210. _AFX_INLINE CTimeSpan CTime::operator-(CTime time) const
  211.     { return CTimeSpan(m_time - time.m_time); }
  212. _AFX_INLINE CTime CTime::operator-(CTimeSpan timeSpan) const
  213.     { return CTime(m_time - timeSpan.m_timeSpan); }
  214. _AFX_INLINE CTime CTime::operator+(CTimeSpan timeSpan) const
  215.     { return CTime(m_time + timeSpan.m_timeSpan); }
  216. _AFX_INLINE const CTime& CTime::operator+=(CTimeSpan timeSpan)
  217.     { m_time += timeSpan.m_timeSpan; return *this; }
  218. _AFX_INLINE const CTime& CTime::operator-=(CTimeSpan timeSpan)
  219.     { m_time -= timeSpan.m_timeSpan; return *this; }
  220. _AFX_INLINE BOOL CTime::operator==(CTime time) const
  221.     { return m_time == time.m_time; }
  222. _AFX_INLINE BOOL CTime::operator!=(CTime time) const
  223.     { return m_time != time.m_time; }
  224. _AFX_INLINE BOOL CTime::operator<(CTime time) const
  225.     { return m_time < time.m_time; }
  226. _AFX_INLINE BOOL CTime::operator>(CTime time) const
  227.     { return m_time > time.m_time; }
  228. _AFX_INLINE BOOL CTime::operator<=(CTime time) const
  229.     { return m_time <= time.m_time; }
  230. _AFX_INLINE BOOL CTime::operator>=(CTime time) const
  231.     { return m_time >= time.m_time; }
  232.  
  233.  
  234. // Special structures for BLTing floats without linking the float library.
  235. // NOTE: Do not use these structures in your code -- instead use float and
  236. //  double as you would normally.
  237.  
  238. struct _AFXFLOAT
  239. {
  240.     char FloatBits[sizeof(float)];
  241. };
  242.  
  243. struct _AFXDOUBLE
  244. {
  245.     char DoubleBits[sizeof(double)];
  246. };
  247.  
  248. // CArchive
  249. _AFX_INLINE BOOL CArchive::IsLoading() const
  250.     { return (m_nMode & CArchive::load) != 0; }
  251. _AFX_INLINE BOOL CArchive::IsStoring() const
  252.     { return (m_nMode & CArchive::load) == 0; }
  253. _AFX_INLINE CFile* CArchive::GetFile() const
  254.     { return m_pFile; }
  255. _AFX_INLINE CArchive& CArchive::operator<<(BYTE by)
  256.     { if (m_lpBufCur + sizeof(BYTE) > m_lpBufMax) Flush();
  257.         *(BYTE FAR*)m_lpBufCur = by; m_lpBufCur += sizeof(BYTE); return *this; }
  258. _AFX_INLINE CArchive& CArchive::operator<<(WORD w)
  259.     { if (m_lpBufCur + sizeof(WORD) > m_lpBufMax) Flush();
  260.         *(WORD FAR*)m_lpBufCur = w; m_lpBufCur += sizeof(WORD); return *this; }
  261. _AFX_INLINE CArchive& CArchive::operator<<(LONG l)
  262.     { if (m_lpBufCur + sizeof(LONG) > m_lpBufMax) Flush();
  263.         *(LONG FAR*)m_lpBufCur = l; m_lpBufCur += sizeof(LONG); return *this; }
  264. _AFX_INLINE CArchive& CArchive::operator<<(DWORD dw)
  265.     { if (m_lpBufCur + sizeof(DWORD) > m_lpBufMax) Flush();
  266.         *(DWORD FAR*)m_lpBufCur = dw; m_lpBufCur += sizeof(DWORD); return *this; }
  267. _AFX_INLINE CArchive& CArchive::operator<<(float f)
  268.     { if (m_lpBufCur + sizeof(float) > m_lpBufMax) Flush();
  269.         *(_AFXFLOAT FAR*)m_lpBufCur = *(_AFXFLOAT FAR*)&f; m_lpBufCur += sizeof(float); return *this; }
  270. _AFX_INLINE CArchive& CArchive::operator<<(double d)
  271.     { if (m_lpBufCur + sizeof(double) > m_lpBufMax) Flush();
  272.         *(_AFXDOUBLE FAR*)m_lpBufCur = *(_AFXDOUBLE FAR*)&d; m_lpBufCur += sizeof(double); return *this; }
  273. _AFX_INLINE CArchive& CArchive::operator>>(BYTE& by)
  274.     { if (m_lpBufCur + sizeof(BYTE) > m_lpBufMax)
  275.             FillBuffer(sizeof(BYTE) - (UINT)(m_lpBufMax - m_lpBufCur));
  276.         by = *(BYTE FAR*)m_lpBufCur; m_lpBufCur += sizeof(BYTE); return *this; }
  277. _AFX_INLINE CArchive& CArchive::operator>>(WORD& w)
  278.     { if (m_lpBufCur + sizeof(WORD) > m_lpBufMax)
  279.             FillBuffer(sizeof(WORD) - (UINT)(m_lpBufMax - m_lpBufCur));
  280.         w = *(WORD FAR*)m_lpBufCur; m_lpBufCur += sizeof(WORD); return *this; }
  281. _AFX_INLINE CArchive& CArchive::operator>>(DWORD& dw)
  282.     { if (m_lpBufCur + sizeof(DWORD) > m_lpBufMax)
  283.             FillBuffer(sizeof(DWORD) - (UINT)(m_lpBufMax - m_lpBufCur));
  284.         dw = *(DWORD FAR*)m_lpBufCur; m_lpBufCur += sizeof(DWORD); return *this; }
  285. _AFX_INLINE CArchive& CArchive::operator>>(float& f)
  286.     { if (m_lpBufCur + sizeof(float) > m_lpBufMax)
  287.             FillBuffer(sizeof(float) - (UINT)(m_lpBufMax - m_lpBufCur));
  288.         *(_AFXFLOAT FAR*)&f = *(_AFXFLOAT FAR*)m_lpBufCur; m_lpBufCur += sizeof(float); return *this; }
  289. _AFX_INLINE CArchive& CArchive::operator>>(double& d)
  290.     { if (m_lpBufCur + sizeof(double) > m_lpBufMax)
  291.             FillBuffer(sizeof(double) - (UINT)(m_lpBufMax - m_lpBufCur));
  292.         *(_AFXDOUBLE FAR*)&d = *(_AFXDOUBLE FAR*)m_lpBufCur; m_lpBufCur += sizeof(double); return *this; }
  293. _AFX_INLINE CArchive& CArchive::operator>>(LONG& l)
  294.     { if (m_lpBufCur + sizeof(LONG) > m_lpBufMax)
  295.             FillBuffer(sizeof(LONG) - (UINT)(m_lpBufMax - m_lpBufCur));
  296.         l = *(LONG FAR*)m_lpBufCur; m_lpBufCur += sizeof(LONG); return *this; }
  297. _AFX_INLINE CArchive::CArchive(const CArchive& /* arSrc */)
  298.     { }
  299. _AFX_INLINE void CArchive::operator=(const CArchive& /* arSrc */)
  300.     { }
  301. _AFX_INLINE CArchive& AFXAPI operator<<(CArchive& ar, const CObject* pOb)
  302.     { ar.WriteObject(pOb); return ar; }
  303. _AFX_INLINE CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb)
  304.     { pOb = ar.ReadObject(NULL); return ar; }
  305. _AFX_INLINE CArchive& AFXAPI operator>>(CArchive& ar, const CObject*& pOb)
  306.     { pOb = ar.ReadObject(NULL); return ar; }
  307.  
  308.  
  309. // CDumpContext
  310. _AFX_INLINE int CDumpContext::GetDepth() const
  311.     { return m_nDepth; }
  312. _AFX_INLINE void CDumpContext::SetDepth(int nNewDepth)
  313.     { m_nDepth = nNewDepth; }
  314. _AFX_INLINE CDumpContext::CDumpContext(const CDumpContext& /* dcSrc */)
  315.     { }
  316. _AFX_INLINE void CDumpContext::operator=(const CDumpContext& /* dcSrc */)
  317.     { }
  318.  
  319. /////////////////////////////////////////////////////////////////////////////
  320. // Inline helpers for implementation
  321.  
  322. _AFX_INLINE void* PASCAL _AfxGetPtrFromFarPtr(void FAR* lp)
  323. {
  324. #ifdef _NEARDATA
  325.     ASSERT(_AFX_FP_SEG(lp) == _segname("_DATA"));
  326.     return (void*)_AFX_FP_OFF(lp);
  327. #else
  328.     return lp;
  329. #endif
  330. }
  331.  
  332. /////////////////////////////////////////////////////////////////////////////
  333.  
  334. #endif //_AFX_INLINE
  335.