home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / WFILPATH.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  7KB  |  206 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1995, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WFilePath
  14.  *
  15.  *************************************************************************/
  16.  
  17. #ifndef _WFILPATH_HPP_INCLUDED
  18. #define _WFILPATH_HPP_INCLUDED
  19.  
  20. #ifndef _WNO_PRAGMA_PUSH
  21. #pragma pack(push,8);
  22. #pragma enum int;
  23. #endif
  24.  
  25. #ifndef _WDEF_HPP_INCLUDED
  26. #  include "wdef.hpp"
  27. #endif
  28.  
  29. #ifndef _WOBJECT_HPP_INCLUDED
  30. #  include "wobject.hpp"
  31. #endif
  32.  
  33. #ifndef _WSTRING_HPP_INCLUDED
  34. #  include "wstring.hpp"
  35. #endif
  36.  
  37. #include <stdlib.h>
  38.  
  39. #define _WFILEPATH_NONE         ( 0x0 )
  40. #define _WFILEPATH_DRIVE        ( 0x1 )
  41. #define _WFILEPATH_DIR          ( 0x2 )
  42. #define _WFILEPATH_FNAME        ( 0x4 )
  43. #define _WFILEPATH_EXT          ( 0x8 )
  44. #define _WFILEPATH_ALL          ( 0xF )
  45.  
  46. class WCMCLASS WFilePath : public WString {
  47.     WDeclareSubclass( WFilePath, WString )
  48.     
  49.     public:
  50.  
  51.         /**********************************************************
  52.          * Constructors and Destructors
  53.          *********************************************************/
  54.     
  55.         WFilePath();
  56.         WFilePath( const WChar *string, WULong numChars=USE_STR_LEN );
  57.         WFilePath( const WResourceID & id, WModuleHandle module=_ApplicationModule );
  58.         WFilePath( const WString & s, WBool makeCopy=FALSE );
  59.         WFilePath( const WFilePath & filePath );
  60.  
  61.         ~WFilePath();
  62.  
  63.         /**********************************************************
  64.          * Properties
  65.          *********************************************************/
  66.  
  67.         // AbsolutePath
  68.         //
  69.         //    Convert a relative path to an absolute path.  Must pass
  70.         //    in a WFilePath used to determine which drive the absolute
  71.         //    path refers to.
  72.  
  73.         WFilePath GetAbsolutePath( const WFilePath & dir ) const;
  74.  
  75.         // Directory
  76.         //
  77.         //    The path (if any), always ending with a "\"
  78.         //    (i.e. "\inst\" in "c:\inst\test.exe")
  79.  
  80.         WBool   SetDirectory( const WString & directory );
  81.         WString GetDirectory() const;
  82.  
  83.         // Drive
  84.         //
  85.         //    The drive (if any), including the colon
  86.         //    (i.e. "c:" in "c:\inst\test.exe")
  87.  
  88.         WBool   SetDrive( const WString & drive );
  89.         WString GetDrive() const;
  90.  
  91.         // Extension
  92.         //
  93.         //    The extension (if any) including a leading period
  94.         //    (i.e. ".exe" in "c:\inst\test.exe")
  95.  
  96.         WBool   SetExtension( const WString & extension );
  97.         WString GetExtension() const;
  98.  
  99.         // FileName
  100.         //
  101.         //    The name part of the file (i.e. "test" in "c:\inst\test.exe")
  102.  
  103.         WBool   SetFileName( const WString & fileName );
  104.         WString GetFileName() const;
  105.  
  106.         // FileParts
  107.         //
  108.         //    Returns a WString with the given set of file parts.
  109.  
  110.         WString GetFileParts( WUInt flags=_WFILEPATH_ALL ) const;
  111.  
  112.         /**********************************************************
  113.          * Methods
  114.          *********************************************************/
  115.  
  116.         // CleanDirectory()
  117.         //
  118.         //    Removes extraneous directory separators such as
  119.         //    .\, foo\..\, etc.
  120.  
  121.         void CleanDirectory();
  122.  
  123.         // Exists
  124.         //
  125.         //    Checks to see if a file or directory exists.  Can
  126.         //    optionally return the attributes of the file.
  127.  
  128.         WBool Exists( WDWord *attributes=NULL ) const;
  129.  
  130.         // MakePath
  131.         //
  132.         //    Rebuild the filepath out of the given parts.  If NULL
  133.         //    is passed, can optionally use the current part.
  134.  
  135.         WBool MakePath( const WChar * drive, const WChar * path,
  136.                         const WChar * name, const WChar * ext,
  137.                         WUInt useCurrentIfNull=_WFILEPATH_NONE );
  138.  
  139.         // Search
  140.         //
  141.         //    Search for the file using the same rules used to
  142.         //    load DLLs.  Returns a null path if not found.
  143.  
  144.         WFilePath Search() const;
  145.  
  146.         /**********************************************************
  147.          * Overrides
  148.          *********************************************************/
  149.     
  150.         virtual WBool SetDirty( WBool dirty=TRUE );
  151.  
  152.         //
  153.         // == operator
  154.         //
  155.  
  156.         friend int WEXPORT operator==( const WFilePath & a, const WFilePath & b );
  157.         friend int WEXPORT operator==( const WFilePath & a, const WString & b );
  158.         friend int WEXPORT operator==( const WFilePath & a, const WAnsiChar *b );
  159.         friend int WEXPORT operator==( const WFilePath & a, const WUnicodeChar *b );
  160.         friend int WEXPORT operator==( const WAnsiChar *a, const WFilePath & b );
  161.         friend int WEXPORT operator==( const WUnicodeChar *a, const WFilePath & b );
  162.         friend int WEXPORT operator==( const WFilePath & a, WAnsiChar *b );
  163.         friend int WEXPORT operator==( const WFilePath & a, WUnicodeChar *b );
  164.         friend int WEXPORT operator==( WAnsiChar *a, const WFilePath & b );
  165.         friend int WEXPORT operator==( WUnicodeChar *a, const WFilePath & b );
  166.  
  167.         //
  168.         // != operator
  169.         //
  170.  
  171.         friend int WEXPORT operator!=( const WFilePath & a, const WFilePath & b );
  172.         friend int WEXPORT operator!=( const WFilePath & a, const WString & b );
  173.         friend int WEXPORT operator!=( const WFilePath & a, const WAnsiChar *b );
  174.         friend int WEXPORT operator!=( const WFilePath & a, const WUnicodeChar *b );
  175.         friend int WEXPORT operator!=( const WAnsiChar *a, const WFilePath & b );
  176.         friend int WEXPORT operator!=( const WUnicodeChar *a, const WFilePath & b );
  177.         friend int WEXPORT operator!=( const WFilePath & a, WAnsiChar *b );
  178.         friend int WEXPORT operator!=( const WFilePath & a, WUnicodeChar *b );
  179.         friend int WEXPORT operator!=( WAnsiChar *a, const WFilePath & b );
  180.         friend int WEXPORT operator!=( WUnicodeChar *a, const WFilePath & b );
  181.  
  182.         /**********************************************************
  183.          * Other
  184.          *********************************************************/
  185.     
  186.     private:
  187.  
  188.         WBool SplitPath();
  189.         void UpdatePath();
  190.  
  191.     private:
  192.  
  193.         WInt            _driveEnd;
  194.         WInt            _pathEnd;
  195.         WInt            _nameEnd;
  196.         WInt            _extEnd;
  197.         WBool           _rebuilding;
  198. };
  199.  
  200. #ifndef _WNO_PRAGMA_PUSH
  201. #pragma enum pop;
  202. #pragma pack(pop);
  203. #endif
  204.  
  205. #endif // _WFILPATH_HPP_INCLUDED
  206.