CMS 3D CMS Logo

Filename.h

Go to the documentation of this file.
00001 #ifndef CLASSLIB_FILENAME_H
00002 # define CLASSLIB_FILENAME_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "classlib/iobase/FileAcl.h"
00007 # include "classlib/utils/Time.h"
00008 # include <string>
00009 # include <vector>
00010 # include <iosfwd>
00011 
00012 namespace lat {
00013 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00014 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00015 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00016 
00017 class Filename;
00018 class FileAcl;
00019 class File;
00020 class Time;
00021 class IOStatus;
00022 class logstream;
00023 class Environment;
00024 
00025 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00026 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00027 
00028 logstream    &operator<<(logstream &out, const Filename &name);
00029 std::ostream &operator<<(std::ostream &out, const Filename &name);
00030 
00031 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00032 
00053 class Filename
00054 {
00055 public:
00056     typedef std::vector< std::pair<std::string, std::string> > AbbrevList;
00057 
00058     Filename (void);
00059     Filename (const char *name);
00060     Filename (const std::string &name);
00061     Filename (const Filename &dir, const Filename &file,bool appendonly=false);
00062     // implicit copy constructor
00063     // implicit destructor
00064     // implicit assignment operator
00065 
00066     // Comparisons
00067     friend bool operator== (const Filename &x, const Filename &y);
00068     friend bool operator== (const char *x, const Filename &y);
00069     friend bool operator== (const std::string &x, const Filename &y);
00070     friend bool operator== (const Filename &x, const char *y);
00071     friend bool operator== (const Filename &x, const std::string &y);
00072 
00073     friend bool operator!= (const Filename &x, const Filename &y);
00074     friend bool operator!= (const char *x, const Filename &y);
00075     friend bool operator!= (const std::string &x, const Filename &y);
00076     friend bool operator!= (const Filename &x, const char *y);
00077     friend bool operator!= (const Filename &x, const std::string &y);
00078 
00079     friend bool operator< (const Filename &x, const Filename &y);
00080     friend bool operator< (const char *x, const Filename &y);
00081     friend bool operator< (const std::string &x, const Filename &y);
00082     friend bool operator< (const Filename &x, const char *y);
00083     friend bool operator< (const Filename &x, const std::string &y);
00084 
00085     friend bool operator<= (const Filename &x, const Filename &y);
00086     friend bool operator<= (const char *x, const Filename &y);
00087     friend bool operator<= (const std::string &x, const Filename &y);
00088     friend bool operator<= (const Filename &x, const char *y);
00089     friend bool operator<= (const Filename &x, const std::string &y);
00090 
00091     friend bool operator> (const Filename &x, const Filename &y);
00092     friend bool operator> (const char *x, const Filename &y);
00093     friend bool operator> (const std::string &x, const Filename &y);
00094     friend bool operator> (const Filename &x, const char *y);
00095     friend bool operator> (const Filename &x, const std::string &y);
00096 
00097     friend bool operator>= (const Filename &x, const Filename &y);
00098     friend bool operator>= (const char *x, const Filename &y);
00099     friend bool operator>= (const std::string &x, const Filename &y);
00100     friend bool operator>= (const Filename &x, const char *y);
00101     friend bool operator>= (const Filename &x, const std::string &y);
00102 
00103     // Basic access to the name
00104     bool                empty (void) const;
00105     std::string::size_type size (void) const;
00106     void                resize (std::string::size_type n, char c = '\0');
00107                 operator const char * (void) const;
00108     // /**/             operator const std::string & (void) const;
00109     char &              operator[] (ptrdiff_t n);
00110     char                operator[] (ptrdiff_t n) const;
00111     const char *        name (void) const;
00112 
00113     // Various checks about the name
00114     bool                isAbsolute (bool considerExpansions = false) const;
00115     bool                isRelative (void) const;
00116 
00117     bool                exists (void) const;
00118     bool                isDirectory (void) const;
00119     bool                isRegular (void) const;
00120     bool                isSymlink (Filename *target = 0) const;
00121 
00122     bool                isAccessibleDirectory (void) const;
00123     bool                isOwnershipPreserved (void) const;
00124     bool                isReadable (void) const;
00125     bool                isWritable (void) const;
00126     bool                isExecutable (void) const;
00127 
00128     bool                status (IOStatus &s, bool traverseLinks = true) const;
00129     void                setStatus (const IOStatus &s) const;
00130     bool                times (Time *ctime, Time *mtime, Time *atime) const;
00131 
00132     // Name variants: representations
00133     Filename            asDirectory (void) const;
00134     Filename            asFile (void) const;
00135 
00136     // Name variants: basic parts
00137     Filename            drive (void) const;     // Win32 only
00138     Filename            share (void) const;     // Win32 only
00139 
00140     Filename            directory (void) const;
00141     Filename            nondirectory (void) const;
00142     Filename            relativeTo (const Filename &dir) const;
00143     Filename            extension (bool *has = 0, bool period = false) const;
00144     Filename            sansExtension (void) const;
00145 
00146     Filename &          append (const char *component);
00147     Filename &          append (const std::string &component);
00148 
00149     // Conversions: system translations
00150     Filename            truename (void) const;
00151     Filename            chaseLinks (void) const;
00152 
00153     // Name variants: autosave
00154     Filename            autosaveName (void) const;
00155     bool                isAutosaveName (void) const;
00156 
00157     // Name variants: backup
00158     Filename            findBackupName (std::vector<Filename> &deletions) const;
00159     Filename            backupName (void) const;
00160     bool                isBackupName (void) const;
00161     Filename            sansVersions (bool keepVersionNr = false) const;
00162 
00163     // Conversions: logical
00164     Filename            expand (const Filename &defaultDir = 0) const;
00165     Filename            substitute (const Environment &env) const;
00166     Filename            abbreviate (const AbbrevList &abbrevs) const;
00167     Filename            abbreviate (void) const;
00168 
00169     // Completion and globbing
00170     bool                complete (const Filename &dir, bool *exact);
00171     size_t              complete (std::vector<Filename> &list,
00172                                   const Filename &dir) const;
00173     size_t              glob (std::vector<Filename> &list,
00174                               const Filename &dir,
00175                               bool absolute = false) const;
00176 
00177     // File (system) operations (FIXME: nonstatic?)
00178     static void         symlink (Filename target, Filename link);
00179     static void         makedir (Filename name,
00180                                  FileAcl mode = 0755,
00181                                  bool recursive = false,
00182                                  bool allowExisting = false);
00183     static void         remove (Filename name,
00184                                 bool recursive = false,
00185                                 bool force = false);
00186     static void         rename (Filename name, Filename to);
00187     static void         move (Filename from, Filename to);
00188     static void         copy (Filename from, Filename to,
00189                               bool keepDate = false);
00190 
00191     // Global state
00192     static Filename     cwd (void);
00193     static Filename     cwd (char drive);
00194 
00195     // System details
00196     static Filename     null (void);
00197     static Filename     root (void);
00198     static Filename     updir (void);
00199     static Filename     thisdir (void);
00200 
00201 private:
00202     void                normalise (void);
00203 
00204     static Filename     abbreviate (std::string name);
00205     static void         expandUser (std::string &namestr,
00206                                     std::string::size_type pos,
00207                                     std::string &dirstr);
00208     void                expandPrefix (Filename &name, const Filename &defdir);
00209     static void         expandClean (std::string &namestr, bool strip);
00210 
00211     // Implementation-specific functions
00212     static bool         domakedir (Filename name, FileAcl mode, bool allowExisting);
00213     static int          doremove (const char *path);
00214 
00215     std::string         m_name;
00216 };
00217 
00218 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00219 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00220 
00221 } // namespace lat
00222 #endif // CLASSLIB_FILENAME_H

Generated on Tue Jun 9 17:38:51 2009 for CMSSW by  doxygen 1.5.4