00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef SG_TLS_FILES_H
00030 #define SG_TLS_FILES_H
00031
00032 #include "SG_TLS_config.h"
00033 #include "SG_TLS_cl_base_dbl_obj.h"
00034 #include <sys/stat.h>
00035 #include <time.h>
00036
00037 #if SG_TLS_MEMORY_MANAGER
00038 #include "SG_TLS_debug_new.h"
00039 #endif
00040
00041 namespace SGE{
00042
00048 template <typename IDType2=int>
00049 class _SG_TLS_EXPORT CL_BASE_OBJ_FILE :
00050 public virtual CL_BASE_DBL_OBJ<std::string, IDType2>
00051 {
00052 public:
00057 _SG_TLS_INLINE
00058 CL_BASE_OBJ_FILE(const std::string & _Name)
00059 : CL_BASE_DBL_OBJ<std::string, IDType2>(_Name)
00060 {
00061
00062 Loaded = false;
00063 ParseFilePath(_Name, (std::string*)&(CL_BASE_OBJ<std::string>::ID), &Path);
00064 ParseFileType((std::string)CL_BASE_OBJ<std::string>::ID, (std::string*)&(CL_BASE_OBJ<std::string>::ID), &Extension);
00065
00066 #if _SG_TLS_FILE_TEST
00067 FileAttrib = NULL;
00068 #endif
00069 }
00070
00074 _SG_TLS_INLINE
00075 ~CL_BASE_OBJ_FILE()
00076 {
00077 if (Loaded)
00078 UnLoad();
00079 }
00080
00086 _SG_TLS_INLINE
00087 bool
00088 IsLoaded()const
00089 { return Loaded; }
00090
00095 _SG_TLS_INLINE virtual
00096 int Load()
00097 {
00098 #if _SG_TLS_FILE_TEST
00099
00100 FileAttrib = new struct stat;
00101 stat(GetFullName().data(), FileAttrib);
00102
00103 #endif
00104
00105 Loaded = true;
00106 return 1;
00107 }
00108
00109 _SG_TLS_INLINE virtual
00110 int UnLoad()
00111 {
00112 Loaded = false;
00113 return 1;
00114 }
00119 _SG_TLS_INLINE
00120 const std::string & GetPath()const
00121 {return Path;}
00122
00127 _SG_TLS_INLINE
00128 const std::string & GetExtension()const
00129 {return Extension;}
00130
00135 _SG_TLS_INLINE
00136 const std::string GetFullName()const
00137 {return Path+ CL_BASE_OBJ<std::string>::ID+ Extension;}
00138
00139 #if _SG_TLS_FILE_TEST
00140
00145 _SG_TLS_INLINE bool Exists()const
00146 {
00147 return FileExists(GetFullName());
00148 }
00149
00155 static bool FileExists(const std::string & _Name)
00156 {
00157 std::ifstream File(_Name.c_str());
00158 if( File.is_open())
00159 {
00160 File.close();
00161 return true;
00162 }
00163
00164 return false;
00165 }
00166
00167
00168 #if 0
00169 static bool FileCopy(const std::string & _Src, const std::string & _Dst)
00170 {
00171 Sys File::Copy("myfile.txt", "copyofmyfile.txt");
00172 }
00173
00174 static bool FileMove(const std::string & _Src, const std::string & _Dst)
00175 {
00176 }
00177 static bool FileDelete(const std::string & _Src)
00178 {
00179 }
00180 #endif
00181
00182
00188 _SG_TLS_INLINE bool IsFileModified()
00189 {
00190 if (!Loaded)
00191 {
00192 SG_NOTICE_LOG("File Not Loaded");
00193 return false;
00194 }
00195
00196 struct stat NewFileAttrib;
00197 stat(GetFullName().data(), &NewFileAttrib);
00198
00199 struct tm* OrigFileClock = gmtime(&(FileAttrib->st_mtime));
00200 struct tm* CurFileClock = gmtime(&(NewFileAttrib.st_mtime));
00201
00202
00203 if (CurFileClock->tm_sec =! OrigFileClock->tm_sec)
00204 return true;
00205 if (CurFileClock->tm_min =! OrigFileClock->tm_min)
00206 return true;
00207 if (CurFileClock->tm_hour =! OrigFileClock->tm_hour)
00208 return true;
00209 #if 0//???see later...sec, min and hours should be far enought to test in our case...
00210 if (CurFileClock->tm_mday =! OrigFileClock->tm_mday)
00211 return true;
00212 if (CurFileClock->tm_mon =! OrigFileClock->tm_mon)
00213 return true;
00214 if (CurFileClock->tm_year =! OrigFileClock->tm_year)
00215 return true;
00216 if (CurFileClock->tm_wday =! OrigFileClock->tm_wday)
00217 return true;
00218 if (CurFileClock->tm_yday =! OrigFileClock->tm_yday)
00219 return true;
00220 if (CurFileClock->tm_isdst =! OrigFileClock->tm_isdst)
00221 return true;
00222 #endif
00223 return false;
00224 }
00225
00226 protected:
00227 struct stat * FileAttrib;
00228 #endif
00229
00230 protected:
00234 _SG_TLS_INLINE
00235 void ParseFileName()
00236 {
00237 ParseFilePath(ID, &Path, &ID);
00238 ParseFileType(ID, &ID, &Extension);
00239 }
00240
00241 std::string Path;
00242 std::string Extension;
00243
00244 private:
00245 bool Loaded;
00246 };
00247
00248 };
00249 #if SG_TLS_MEMORY_MANAGER
00250 #include "SG_TLS_debug_new_off.h"
00251 #endif
00252
00253 #endif //SG_TLS_CL_BASE_OBJ_H