MrSID Decode SDK for Raster Reference Manual  9.5.4.4709
lt_fileSpec.h
Go to the documentation of this file.
00001 /* //////////////////////////////////////////////////////////////////////////
00002 //                                                                         //
00003 // This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue,   //
00004 // Suite 200, Seattle, WA 98104.  Unauthorized use or distribution         //
00005 // prohibited.  Access to and use of this code is permitted only under     //
00006 // license from LizardTech, Inc.  Portions of the code are protected by    //
00007 // US and foreign patents and other filings. All Rights Reserved.          //
00008 //                                                                         //
00010 /* PUBLIC */
00011 
00012 #ifndef LT_FILESPEC_H
00013 #define LT_FILESPEC_H
00014 
00015 // lt_lib_base
00016 #include "lt_base.h"
00017 #include "lt_system.h"
00018 
00019 LT_BEGIN_NAMESPACE(LizardTech)
00023 #ifdef LT_OS_WIN
00024 #define LT_UTIL_MAX_PATH _MAX_PATH
00025 #else
00026 #define LT_UTIL_MAX_PATH 2048
00027 #endif
00028 
00029 #if defined(LT_OS_WIN) && !defined(_NATIVE_WCHAR_T_DEFINED) && !defined (SWIG)
00030 // Work within projects whether using native wchar_t or not ("/Zc:wchar_t-").
00031 #define WCHAR_INTERNAL __wchar_t
00032 #else
00033 #define WCHAR_INTERNAL wchar_t
00034 #endif
00035 
00039 class LTFileSpec
00040 {
00041 public:
00042    enum
00043    {
00044       fSlash = '/',
00045       bSlash = '\\',
00046 #ifdef LT_OS_WIN
00047       platformSlash = '\\'
00048 #else
00049       platformSlash = '/'
00050 #endif
00051    };
00052 
00053 
00054 public:
00058    LTFileSpec(void);
00059 
00063    ~LTFileSpec(void);
00064 
00065 #ifndef SWIG
00066 
00074    enum EncodingType { NATIVE, UTF8 };
00075    LTFileSpec(const char *p1,
00076               EncodingType encoding = NATIVE);
00077    LTFileSpec(const char *p1, const char *p2,
00078               EncodingType encoding = NATIVE);
00079    LTFileSpec(const char *p1, const char *p2, const char *p3,
00080               EncodingType encoding = NATIVE);
00081 #endif
00082 
00088    explicit LTFileSpec(const WCHAR_INTERNAL *p1);
00089    LTFileSpec(const WCHAR_INTERNAL *p1, const WCHAR_INTERNAL *p2);
00090    LTFileSpec(const WCHAR_INTERNAL *p1, const WCHAR_INTERNAL *p2, const WCHAR_INTERNAL *p3);
00091    
00092 #ifndef SWIG
00093 
00097    explicit LTFileSpec(const lt_uint16 *path);
00098    LTFileSpec(const lt_uint16 *p1, const lt_uint16 *p2);
00099    LTFileSpec(const lt_uint16 *p1, const lt_uint16 *p2, const lt_uint16 *p3);
00100 #endif
00101 
00102    LTFileSpec(const LTFileSpec &p1);
00103    LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2);
00104    LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2, const LTFileSpec &p3);
00105 #ifndef SWIG
00106    LTFileSpec(const LTFileSpec &p1, const char *p2,
00107               EncodingType encoding);
00108    LTFileSpec(const LTFileSpec &p1, const char *p2, const char *p3,
00109               EncodingType encoding);
00110    LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2, const char *p3,
00111               EncodingType encoding);
00112 #endif
00113    LTFileSpec(const LTFileSpec &p1, const WCHAR_INTERNAL *p2);
00114    LTFileSpec(const LTFileSpec &p1, const WCHAR_INTERNAL *p2, const WCHAR_INTERNAL *p3);
00115    LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2, const WCHAR_INTERNAL *p3);
00116 
00117 #ifndef SWIG
00118    LTFileSpec(const LTFileSpec &p1, const lt_uint16 *p2);
00119    LTFileSpec(const LTFileSpec &p1, const lt_uint16 *p2, const lt_uint16 *p3);
00120    LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2, const lt_uint16 *p3);
00121 #endif
00122 
00128    LTFileSpec& operator=(const LTFileSpec &that);
00129 
00133    bool operator!=(const LTFileSpec& fs) const;
00134 
00138    bool operator==(const LTFileSpec& fs) const;
00139 
00140    // is the fileSpec empty
00141    bool empty(void) const;
00142    
00146    const char *utf8(void) const;
00147    
00154    const char *n_str(void) const;
00155    
00162    const WCHAR_INTERNAL *w_str(void) const;
00163 
00178    LTFileSpec dirname(void) const;
00179    
00194    const char *basename(void) const;
00195    
00204    const char* getSuffix() const;
00205 
00218    LTFileSpec replaceSuffix(const char* ext) const;
00219 
00230    LTFileSpec removeSuffix() const;
00231 
00235    bool absolute() const;
00236 
00237 protected:
00238    
00243    void init(const char *p1, const char *p2, const char *p3);
00244    
00245    size_t getPrefixLength(void) const;
00246 private:
00247    // using a utf8 string to hold the path because it is the easiest
00248    // to play with (null and backslash searching, no lead bytes).
00249    char *m_path8;
00250    mutable char *m_pathA;     // this will be updated in n_str()
00251    mutable WCHAR_INTERNAL *m_pathW;  // this will be updated in w_str()
00252 
00253 };
00254 
00255 LT_END_NAMESPACE(LizardTech)
00256 
00257 #undef WCHAR_INTERNAL
00258 #endif // LT_FILESPEC_H