cgma
CubitFileUtil.hpp
Go to the documentation of this file.
00001 //- Class:          CubitFileUtil
00002 //- Description:    Class with functions to get files from a directory, etc.
00003 //- Owner:          Steve Storm
00004 
00005 #ifndef CUBITFILEUTIL_HPP
00006 #define CUBITFILEUTIL_HPP
00007 
00008 #include <string>
00009 #include "CubitDefines.h"
00010 #include "CubitString.hpp"
00011 #include "CGMUtilConfigure.h"
00012 
00013 class CUBIT_UTIL_EXPORT CubitFileUtil
00014 {
00015 public:
00016 
00017   CubitFileUtil();
00018   //- Constructor
00019   
00020    ~CubitFileUtil();
00021   //- Destructor
00022 
00023    // returns platform specific path separator
00024    static const char* separator();
00025 
00026    // returns whether a given path is a directory
00027    static bool is_directory(const CubitString& path);
00028 
00029    // return whether a given path (file or directory) exists
00030    static bool path_exists(const CubitString& path);
00031    
00032    // returns whether a given path is an executable
00033    static bool is_executable(const CubitString& path);
00034   
00035    // returns whether a path is absolute 
00036    static bool is_absolute(const CubitString& path);
00037    
00038    // returns information about a file (returns 0 on success and errno on failure)
00039    static int file_info(const CubitString& path, off_t& size, time_t& modification_time, int& mode);
00040 
00041 
00043    static CubitString find_home_path(const CubitString& which_user="");
00044 
00046    static CubitStatus get_current_working_directory( CubitString& wd );
00047    static CubitStatus set_current_working_directory( const CubitString& wd );
00048 
00052    static CubitString add_name_to_path( const CubitString& path, const CubitString& name);
00053   
00054    static CubitStatus create_directory( const CubitString& wd );
00055    // Create a directory
00056   
00058    static CubitStatus remove_file( const CubitString& file );
00059 
00061    static CubitStatus rename_file( const CubitString& old_file, const CubitString& new_file );
00062 
00063    static CubitStatus get_full_path_str( const CubitString& part,
00064                                          CubitString &full_path );
00065    // Given a relative path, return the full path to the filename or 
00066    // directory.
00067 
00068    static CubitString make_path_platform_compatible( const CubitString& path );
00069    // Replaces slashes with backslashes or vice versa in the given path.
00070 
00071    static CubitString get_nice_filename( const CubitString& path );
00072    // Gets a nice looking filename.  All it does is return just the filename
00073    // without the path if the input filename is in the current working
00074    // directory (ie., so the filename doesn't contain the full path).
00075 
00076    static void split_path( const CubitString& path, CubitString& dirpart, CubitString& filepart );
00077    // Split a path string into directory and filename parts.  The function 
00078    // returns the directory part with a slash (or backslash for NT) on the end.
00079    // Note the logic is based entirely on looking for the last directory separator 
00080    // (slash or backslash) in the path - only the string is used (not lstat, for 
00081    // instance).  Because of this if you know you have a directory coming in put 
00082    // a slash on the end of your path, otherwise the last directory in your path 
00083    // will be parsed out as a file.
00084 
00085 //   static CubitString get_default_cubit_file_name();
00086    // Gets the default Cubit filename, when the user doesn't specify one (ie., 
00087    // at Cubit startup.  Format cubitXX.cub, where XX = integer.  Returned 
00088    // filename does not include full path (assumed current working directory).
00089 
00090    static int get_next_filenumber( const CubitString& filepattern,
00091                                    int &num_matches,
00092                                    int &first_match );
00093    // Gets the next next available number for a filename pattern (use absolute path).
00094    // The '*' character can be used to denote where a number is searched for.
00095    // (i.e., use a pattern of file.cub.* to return file.cub.2, if file.cub.1 already exists).
00096    // Also returns the number of files that matched the file.cub.* pattern in the directory,
00097    // and the first number found.  Handles cases like file.cub.3.4, etc..
00098    // (user started from a backup file).
00099    // Returns -1 if failure.
00100   
00101   static CubitString get_file_extension(const CubitString& file, bool remove_version = false /* remove .1, .2, ...*/ );
00102 
00104   static CubitString list_matching_files(const char *path, const char *file, std::vector<std::string> suffixes, CubitString& line);
00105 
00107   static int complete_filename(CubitString& line, int& num_additional_chars, bool& found_quote);
00108 
00109 private:
00110   static CubitBoolean all_chars_are( char ch, const char *str );
00111   // Check if all chars from src are ch
00112 
00113   static CubitBoolean is_int_number( const char *str );
00114   // Check if the string represents an integer number
00115   
00116   static CubitBoolean contains_char( char ch, const char *str );
00117   // Check if the string contains the given character
00118 };
00119 
00120 #endif
00121 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines