Scopira 20080306

file.h

00001 
00002 /*
00003  *  Copyright (c) 2003    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_FILE_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_FILE_H__
00016 
00017 #include <sys/stat.h>
00018 
00019 #include <string>
00020 
00021 #include <scopira/tool/export.h>
00022 
00023 namespace scopira
00024 {
00025   namespace tool
00026   {
00027     class file;
00028 
00029     const char dir_seperator_c = '/';
00030 
00032     const char * get_username(void);
00034     const char * get_homedir(void);
00035   }
00036 }
00037 
00047 class scopira::tool::file
00048 {
00049   public:
00050     typedef ::off_t offset_t;
00051   private:
00052     //const std::string m_filename;   // dont need this?
00053     bool dm_error;       // was there an error on stat? if so, reading from m_stat is useless
00054     struct stat dm_stat;
00055 
00056   public:
00058     SCOPIRA_EXPORT file(void);
00059 
00065     SCOPIRA_EXPORT file(const std::string &fname);
00066 
00072     SCOPIRA_EXPORT void set(const std::string &fname);
00073 
00079     SCOPIRA_EXPORT bool exists(void) const;
00080 
00086     SCOPIRA_EXPORT bool is_file(void) const;
00087 
00093     SCOPIRA_EXPORT bool is_dir(void) const;
00094 
00100     SCOPIRA_EXPORT offset_t size(void) const;
00101 
00107     SCOPIRA_EXPORT static bool check_path(const std::string& path);
00108 
00117     SCOPIRA_EXPORT static bool has_ext(const std::string &fname, const std::string &ext);
00118     
00125     SCOPIRA_EXPORT static void expand_homedir(std::string &path);
00126     
00133     SCOPIRA_EXPORT static void expand_envvar(std::string &path);
00134     
00143     SCOPIRA_EXPORT static void split_ext(const std::string &fullname, std::string &sansext, std::string &ext);
00144     
00152     SCOPIRA_EXPORT static void split_path(const std::string &fullname, std::string &path, std::string &name);
00153 
00160     SCOPIRA_EXPORT static std::string realpath(const std::string &name);
00161     
00167     SCOPIRA_EXPORT static void create_directory(const std::string &dirname);
00168 };
00169 
00170 #endif
00171