Adobe.com
Contents Suites Classes Class Index Member Index

IAIFilePath.hpp

Go to the documentation of this file.
00001 /*
00002  *        Name: IAIFilePath.hpp
00003  *     Purpose: C++ access class for File Path suite
00004  *
00005  * ADOBE SYSTEMS INCORPORATED
00006  * Copyright 2004-2007 Adobe Systems Incorporated.
00007  * All rights reserved.
00008  *
00009  * NOTICE:  Adobe permits you to use, modify, and distribute this file 
00010  * in accordance with the terms of the Adobe license agreement 
00011  * accompanying it. If you have received this file from a source other 
00012  * than Adobe, then your use, modification, or distribution of it 
00013  * requires the prior written permission of Adobe.
00014  *
00015  */
00016 
00017 #ifndef __IAIFilePath__
00018 #define __IAIFilePath__
00019 
00020 #include "IAIUnicodeString.h"
00021 
00022 /*HACK for int32_t and uint32_t redefinition error in VS2012: In case of VS2012 compiler, "memory" file includes stdint.h which, 
00023                 for some reason, points to dvacore/sys/win/stdint.h. As a result, datatypes defined in stdint.h throw redefinition errors.      */
00024 #if defined(_MSC_VER) && _MSC_VER >= 1700
00025 #define _ADOBE_STDINT_H_
00026 #endif
00027 
00028 #include <memory>
00029 
00030 #if defined(_MSC_VER) && _MSC_VER >= 1700
00031 #undef _ADOBE_STDINT_H_
00032 #endif
00033 
00034 
00035 #ifdef MAC_ENV
00036     #ifdef __OBJC__
00037         #import <Foundation/NSURL.h>
00038         #import <Foundation/NSString.h>
00039     #endif
00040     #ifndef __COREFOUNDATION_CFURL__
00041         #include <CoreFoundation/CFURL.h>
00042     #endif
00043     #if defined(IOS_ENV)
00044                 typedef short FSVolumeRefNum;
00045         #else
00046         #ifndef __FILES__
00047             #include <Carbon/Carbon.h>
00048         #endif
00049     #endif      // !defined(IOS_ENV)
00050 #else
00051 
00052 typedef signed long OSStatus;
00053 #endif
00054 
00055 struct FSSpec;
00056 struct MiFile;
00057 
00058 namespace ai {
00059 
00060 #ifdef WIN_ENV
00061 const ai::uint32 MaxPath = 259;
00062 #endif
00063 #ifdef MAC_ENV
00064 const ai::uint32 MaxPath = 1023;
00065 #endif
00066 const ai::uint32 MaxFile = 255;
00067 
00068 class FilePath
00069 {
00070         public:
00071 
00072         /* Some file system operations can be very slow. For example, on Windows,
00073                 UNC path names are used to access files on remote volumes. Determining
00074                 the availability of those remote volumes can require significant time
00075                 especially in the presence of the Windows client for NFS. For this
00076                 reason volume availability information is cached. */
00077 
00082         static void ResetVolumeCache() AINOTHROW;
00083 
00085         FilePath() AINOTHROW;
00087         FilePath(const FilePath&);
00088 
00089 #ifdef AI_HAS_RVALUE_REFERENCES
00090 
00091         FilePath(FilePath&& rhs) AINOEXCEPT;
00092 #endif
00093 
00104         explicit FilePath(const ai::UnicodeString &path, bool expandName = true,
00105                     bool dontStripTrailingSpace = false);
00106 
00115         explicit FilePath(const MiFile&);
00116 
00117 
00118         
00119         explicit FilePath(const SPPlatformFileReference&);
00120 
00121         #ifdef MAC_ENV
00122 
00126         explicit FilePath(const CFStringRef);
00127 
00139 #if DEPRICATED_IN_10_8
00140         explicit FilePath(const FSRef&);
00141 #endif
00142 
00147         explicit FilePath(const CFURLRef);
00148     
00149     #ifdef __OBJC__
00150 
00153     explicit FilePath( NSData* inBookmarkData, const FilePath& inRelativeToPath = FilePath() );
00154     #endif //__OBJC__
00155     
00156         #endif  // MAC_ENV
00157 
00159         ~FilePath();
00160 
00162         void swap(FilePath& rhs) AINOEXCEPT;
00163 
00165         FilePath& operator=(const FilePath&);
00166 
00167 #ifdef AI_HAS_RVALUE_REFERENCES
00168 
00169         FilePath& operator=(FilePath&&) AINOEXCEPT;
00170 #endif
00171 
00175         bool IsEmpty() const;
00176 
00180         void MakeEmpty();
00181 
00190         bool Equal(const FilePath& filePath, const bool resolveLinks = false) const;
00192         bool operator==(const FilePath&) const;
00194         bool operator!=(const FilePath&) const;
00195 
00197         bool operator<(const FilePath&) const;
00198 
00203         bool StartsWithDelimiter() const;
00204 
00209         bool EndsWithDelimiter() const;
00210 
00218         void AddComponent(const ai::UnicodeString &addend = ai::UnicodeString());
00226         void AddComponent(const FilePath &addend);
00227 
00231         void RemoveComponent();
00232 
00238         void AddExtension(const ai::UnicodeString &ext);
00244         void AddExtension(const std::string &ext);
00248         void RemoveExtension();
00249 
00261         bool Exists(const bool resolveLinks,
00262                                 ai::UnicodeString *longPath = 0, bool *isFile = 0) const;
00263 
00269         void Resolve();
00270 
00271         /*****************************************************************************/
00272         /* Set operations */
00273 
00282         void Set(const ai::UnicodeString &path, bool expandName = true, bool dontStripTrailingSpace = false);
00283 
00287         void SetFromMiFile(const MiFile&);
00288 
00289         void SetFromSPFileRef(const SPPlatformFileReference&);
00290 
00291         #ifdef MAC_ENV
00292 
00296         void SetFromCFString(const CFStringRef);
00297 
00308 #if DEPRICATED_IN_10_8
00309         OSStatus SetFromFSRef(const FSRef&);
00310 #endif
00311 
00315         void SetFromCFURL(const CFURLRef);
00316     
00317     #ifdef __OBJC__
00318 
00321     BOOL SetFromBookmarkData( NSData* inBookmarkData, const FilePath& inRelativeToPath = FilePath(), NSError** inError = NULL );
00322     #endif //__OBJC__
00323         
00324     #endif      // MAC_ENV
00325 
00326 
00327         /*****************************************************************************/
00328         /* Get operations */
00329 
00334         ai::UnicodeString GetFileName(const bool displayName = false) const;
00335 
00339         ai::UnicodeString GetFileNameNoExt() const;
00340 
00345         ai::UnicodeString GetFileExtension() const;
00346 
00351         ai::UnicodeString GetFullPath(const bool displayName = false) const;
00352 
00359         ai::UnicodeString GetDirectory(const bool displayName = false) const;
00360 
00368         ai::UnicodeString GetShortPath() const;
00369 
00378         FilePath GetParent() const;
00379 
00381         //On hold due to lack of demand
00382         //FilePath GetRelativePath(const FilePath &base) const;
00383 
00385         //On hold due to lack of demand
00386         //FilePath GetAbsolutePath(const FilePath &base) const;
00387 
00391         static const char GetDelimiter() AINOTHROW;
00392 
00393         #ifdef MAC_ENV
00394     
00395     #if DEPRICATED_IN_10_8
00396 
00410     void GetVolumeAndParent(FSVolumeRefNum *vol, UInt32 *parent) const;
00411     #endif
00412     
00413     #ifdef __OBJC__
00414 
00421         void GetVolumeAndParent(NSURL **volume, NSURL **parent) const;
00422     #endif
00423     #endif
00424 
00431         AIErr GetCreatorAndType(ai::uint32 *creator, ai::uint32 *type) const;
00432 
00439         ai::UnicodeString GetAsURL(const bool displayName) const;
00440 
00441         void GetAsSPPlatformFileRef(SPPlatformFileReference&) const;
00442 
00444         AIErr GetAsMiFile(MiFile&) const;
00445 
00447         AIErr GetAsMiFile(MiFile*&) const;
00448 
00449         AIBoolean IsOnNetwork() const;
00450 
00451         #ifdef MAC_ENV
00452 
00456         CFStringRef GetAsCFString() const;
00457 
00468 #if DEPRICATED_IN_10_8
00469         OSStatus GetAsFSRef(FSRef& result) const;
00470 #endif
00471 
00475         CFURLRef GetAsCFURL() const;
00476 
00477     #ifdef __OBJC__
00478     NSString* GetAsNSString         () const;
00479     
00480     NSURL*  GetAsNSURL              () const;
00481     
00482     NSData* GetAsBookmarkData       (  const FilePath& inRelativeToPath = FilePath(), NSError** inError = NULL ) const;
00483     
00484     NSData* GetAsMinimalBookmarkData(  const FilePath& inRelativeToPath = FilePath(), NSError** inError = NULL ) const;
00485     
00486     BOOL    IsAlias                 () const;
00487     
00488     BOOL    IsEjectable             () const;
00489     #endif
00490         
00491 #endif  // MAC_ENV
00492 
00493         private:
00494         class FilePathImpl *impl;
00495 };
00496 
00498 // Inline members
00499 //
00500 
00501 // Swap
00502 inline void FilePath::swap(FilePath& rhs) AINOEXCEPT
00503 {
00504         std::swap(impl, rhs.impl);
00505 }
00506 
00507 #ifdef AI_HAS_RVALUE_REFERENCES
00508 
00509 // Move constructor
00510 inline FilePath::FilePath(FilePath&& rhs) AINOEXCEPT : impl{rhs.impl}
00511 {
00512         rhs.impl = nullptr;
00513 }
00514 
00515 // Move assignment operator
00516 inline FilePath& FilePath::operator=(FilePath&& rhs) AINOEXCEPT
00517 {
00518         swap(rhs);
00519         return *this;
00520 }
00521 
00522 #endif // AI_HAS_RVALUE_REFERENCES
00523 
00524 inline void FilePath::AddComponent(const FilePath &addend)
00525 {
00526         AddComponent(addend.GetFullPath());
00527 }
00528 
00529 inline void FilePath::AddExtension(const std::string &ext)
00530 {
00531         AddExtension(ai::UnicodeString(ext));
00532 }
00533 
00534 } // namespace ai
00535 
00536 #endif // __IAIFilePath__


Contents Suites Classes Class Index Member Index
Adobe Solutions Network
 
Copyright © 2014 Adobe Systems Incorporated. All rights reserved.
Terms of Use Online Privacy Policy Adobe and accessibility Avoid software piracy Permissions and Trademarks