pathstr.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 5k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //+-------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //
  5. //  Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. //  File:       pathstr.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INC_CSCVIEW_PATHSTR_H
  11. #define _INC_CSCVIEW_PATHSTR_H
  12. #ifndef _INC_SHLWAPI
  13. #   include "shlwapi.h"
  14. #endif
  15. #ifndef _INC_CSCVIEW_STRCLASS_H
  16. #   include "strclass.h"
  17. #endif
  18. class CPath : public CString
  19. {
  20.     public:
  21.         CPath(void) { }
  22.         explicit CPath(LPCTSTR pszRoot, LPCTSTR pszDir = NULL, LPCTSTR pszFile = NULL, LPCTSTR pszExt = NULL);
  23.         CPath(const CPath& rhs);
  24.         CPath& operator = (const CPath& rhs);
  25.         CPath& operator = (LPCTSTR rhs);
  26.         //
  27.         // Component replacement.
  28.         //
  29.         void SetRoot(LPCTSTR pszRoot);
  30.         void SetPath(LPCTSTR pszPath);
  31.         void SetDirectory(LPCTSTR pszDir);
  32.         void SetFileSpec(LPCTSTR pszFileSpec);
  33.         void SetExtension(LPCTSTR pszExt);
  34.         //
  35.         // Component query
  36.         //
  37.         bool GetRoot(CPath *pOut) const;
  38.         bool GetPath(CPath *pOut) const;
  39.         bool GetDirectory(CPath *pOut) const;
  40.         bool GetFileSpec(CPath *pOut) const;
  41.         bool GetExtension(CPath *pOut) const;
  42.         //
  43.         // Component removal
  44.         //
  45.         void RemoveRoot(void);
  46.         void RemovePath(void);
  47.         void RemoveFileSpec(void);
  48.         void RemoveExtension(void);
  49.         void StripToRoot(void);
  50.         bool Append(LPCTSTR psz);
  51.         //
  52.         // DOS drive letter support.
  53.         //
  54.         bool BuildRoot(int iDrive);
  55.         int GetDriveNumber(void) const;
  56.         //
  57.         // Type identification.
  58.         //
  59.         bool IsDirectory(void) const;
  60.         bool IsFileSpec(void) const;
  61.         bool IsPrefix(LPCTSTR pszPrefix) const;
  62.         bool IsRelative(void) const;
  63.         bool IsRoot(void) const;
  64.         bool IsSameRoot(LPCTSTR pszPath) const;
  65.         bool IsUNC(void) const;
  66.         bool IsUNCServer(void) const;
  67.         bool IsUNCServerShare(void) const;
  68.         bool IsURL(void) const;
  69.         //
  70.         // Miscellaneous formatting.
  71.         //
  72.         bool MakePretty(void);
  73.         void QuoteSpaces(void);
  74.         void UnquoteSpaces(void);
  75.         void RemoveBlanks(void);
  76.         void AddBackslash(void);
  77.         void RemoveBackslash(void);
  78.         bool Canonicalize(void);
  79.         bool Compact(HDC hdc, int cxPixels);
  80.         bool CommonPrefix(LPCTSTR pszPath1, LPCTSTR pszPath2);
  81.         bool Exists(void) const;
  82.     private:
  83.         template <class T>
  84.         T& MAX(const T& a, const T& b)
  85.             { return a > b ? a : b; }
  86. };
  87. class CPathIter
  88. {
  89.     public:
  90.         CPathIter(const CPath& path);
  91.         ~CPathIter(void) { }
  92.         bool Next(CPath *pOut);
  93.         void Reset(void);
  94.     private:
  95.         CPath  m_path;
  96.         LPTSTR m_pszCurrent;
  97. };
  98. inline bool 
  99. CPath::Exists(
  100.     void
  101.     ) const
  102. {
  103.     return boolify(::PathFileExists((LPCTSTR)*this));
  104. }
  105. inline bool 
  106. CPath::IsDirectory(
  107.     void
  108.     ) const
  109. {
  110.     return boolify(::PathIsDirectory((LPCTSTR)*this));
  111. }
  112. inline bool 
  113. CPath::IsFileSpec(
  114.     void
  115.     ) const
  116. {
  117.     return boolify(::PathIsFileSpec((LPCTSTR)*this));
  118. }
  119. inline bool 
  120. CPath::IsPrefix(
  121.     LPCTSTR pszPrefix
  122.     ) const
  123. {
  124.     return boolify(::PathIsPrefix(pszPrefix, (LPCTSTR)*this));
  125. }
  126. inline bool 
  127. CPath::IsRelative(
  128.     void
  129.     ) const
  130. {
  131.     return boolify(::PathIsRelative((LPCTSTR)*this));
  132. }
  133. inline bool 
  134. CPath::IsRoot(
  135.     void
  136.     ) const
  137. {
  138.     return boolify(::PathIsRoot((LPCTSTR)*this));
  139. }
  140. inline bool 
  141. CPath::IsSameRoot(
  142.     LPCTSTR pszPath
  143.     ) const
  144. {
  145.     return boolify(::PathIsSameRoot(pszPath, (LPCTSTR)*this));
  146. }
  147. inline bool 
  148. CPath::IsUNC(
  149.     void
  150.     ) const
  151. {
  152.     return boolify(::PathIsUNC((LPCTSTR)*this));
  153. }
  154. inline bool 
  155. CPath::IsUNCServer(
  156.     void
  157.     ) const
  158. {
  159.     return boolify(::PathIsUNCServer((LPCTSTR)*this));
  160. }
  161. inline bool 
  162. CPath::IsUNCServerShare(
  163.     void
  164.     ) const
  165. {
  166.     return boolify(::PathIsUNCServerShare((LPCTSTR)*this));
  167. }
  168. inline bool 
  169. CPath::IsURL(
  170.     void
  171.     ) const
  172. {
  173.     return boolify(::PathIsURL((LPCTSTR)*this));
  174. }
  175. inline bool 
  176. CPath::MakePretty(
  177.     void
  178.     )
  179. {
  180.     return boolify(::PathMakePretty((LPTSTR)*this));
  181. }
  182. inline int
  183. CPath::GetDriveNumber(
  184.     void
  185.     ) const
  186. {
  187.     return ::PathGetDriveNumber(*this);
  188. }
  189. #endif // _INC_CSCVIEW_PATHSTR_H