// FileName.h #ifndef dataset_util__FileName_H #define dataset_util__FileName_H // Class to hold and manipulate a file name. #include #include class FileName { public: // typedefs typedef std::string Name; public: // static methods // Character used to delimit directories. static char delimiter() { return '/'; } // String representation of theis character. static Name string_delimiter() { return "/"; } private: // data // String representation of file name. Name m_name; public: // methods // Constructor. explicit FileName(Name name =""); // Return the string representation. Name name() const { return m_name; } // Return string name with no path. // /.../myfile -> myfile Name nopath_name() const; // Return string name with full path. // Uses fullpath(). // myfile -> /.../myfile Name fullpath_name() const; // Return string name of directory. // Uses directory(); // /.../myfile -> /... Name directory_name() const; // Is this a valid file name? // Does not require that file exists. bool is_valid() const; // Is this a full path (/...)? bool is_fullpath() const; // Is this a relative file name (.../...)? bool is_relative() const; // Return name with full path. // CWD is prepended if not absolute. FileName fullpath() const; // Return parent directory. FileName directory() const; // Return the full name removing up to maxlink symbolic links. // Returns invalid if the process fails. // First argument is the maximum nunber of links to resolve. // Returns error if this number is exceeded and the second argument // is true. FileName unlinked(int maxlink =1000, bool maxlink_error =true) const; }; // Output stream. std::ostream& operator<<(std::ostream& lhs, const FileName& rhs); #endif