00001 // $Id: SLFile.hpp,v 1.9 2004/04/15 00:04:52 mr_lex Exp $ 00002 #ifndef SL_FILE_HPP 00003 #define SL_FILE_HPP 00004 00005 #include <boost/shared_ptr.hpp> 00006 00007 // these three ones are for SLFile::getTimestamp() 00008 #include <sys/types.h> 00009 #include <sys/stat.h> 00010 #include <unistd.h> 00011 00012 #include "segusoland.hpp" 00013 #include "SLString.hpp" 00014 #include "SLFileExt.hpp" 00015 #include "SLIOException.hpp" 00016 00017 SL_NAMESPACE_BEGIN 00018 00031 class SLFile { 00032 public: 00037 class IOException : public SLIOException { 00038 public: 00040 IOException::IOException(const SLString &message) : 00041 SLIOException(message) 00042 {} 00043 }; 00044 00045 class Timestamp; 00046 00047 00054 SLFile(const char *path); 00055 00061 SLFile(const char *directory, const char *file); 00062 00069 const SLString &getShortName() const; 00070 00074 const SLFileExt &getExt() const; 00075 00079 const char *getOSDependantPath() const; 00080 00084 const char *getOSDependantName() const; 00085 00095 const char *getOSDependantParent() const; 00096 00103 Timestamp getTimestamp() const 00104 throw(SLFile::IOException); 00105 00109 bool hasExt(const SLFileExt &ext) const; 00110 00111 //SLFileMetaData &getMetaData(); 00112 00113 protected: 00117 class Data; 00118 00122 boost::shared_ptr<Data> _shared_ptr; 00123 }; 00124 00125 00126 00133 class SLFile::Timestamp { 00134 public: 00139 Timestamp(time_t unix_tstamp) 00140 : 00141 _unix_tstamp(unix_tstamp) 00142 { 00143 _char_tstamp[0] = '\0'; 00144 } 00145 00150 Timestamp(const char *char_tstamp) 00151 : 00152 _unix_tstamp(0) 00153 { 00154 unsigned int i; 00155 for (i = 0; i < sizeof(_char_tstamp); i++) { 00156 _char_tstamp[i] = char_tstamp[i]; 00157 // yeah, no '\0' test as it would decrease speed here. 00158 } 00159 _char_tstamp[i] = '\0'; 00160 } 00161 00166 bool operator==(Timestamp &other) { 00167 if (to_time_t() == other.to_time_t()) { 00168 return true; 00169 } 00170 else { 00171 return false; 00172 } 00173 } 00174 00179 const char *to_cstr() { 00180 if (_char_tstamp[0] == '\0') { 00181 sprintf((char *)_char_tstamp, "%lld", (long long int)_unix_tstamp); 00182 } 00183 return _char_tstamp; 00184 } 00185 00190 time_t to_time_t() { 00191 if (_unix_tstamp == 0) { 00192 _unix_tstamp = (time_t)atoll(_char_tstamp); 00193 } 00194 return _unix_tstamp; 00195 } 00196 00197 protected: 00198 time_t _unix_tstamp; 00199 char _char_tstamp[13]; 00200 }; 00201 00202 00203 00204 00205 SL_NAMESPACE_END 00206 #endif // #define SL_FILE_HPP 00207 00208 // $Log: SLFile.hpp,v $ 00209 // Revision 1.9 2004/04/15 00:04:52 mr_lex 00210 // NEW: files plugin + autotools up to date 00211 // 00212 // Revision 1.8 2004/04/14 12:04:26 mr_lex 00213 // NEW: Timestamp class for collaboration with files plugin 00214 // 00215 // Revision 1.7 2004/04/05 01:42:30 mr_lex 00216 // FIX: bug with abstract class & plugins 00217 // 00218 // Revision 1.6 2004/04/03 15:07:34 mr_lex 00219 // NEW: plugin system and toolkit nearly mature 00220 // 00221 // Revision 1.5 2004/03/30 00:54:00 mr_lex 00222 // NEW: list sorting + fixed some issues with const types 00223 // 00224 // Revision 1.4 2004/03/29 13:01:33 mr_lex 00225 // FIX: finished converting to shared_ptr 00226 //