00001
00002
00003 #ifndef __ARC_FILEINFO_H__
00004 #define __ARC_FILEINFO_H__
00005
00006 #include <list>
00007 #include <string>
00008
00009 #include <arc/DateTime.h>
00010 #include <arc/URL.h>
00011 #include <arc/StringConv.h>
00012
00013 namespace Arc {
00014
00016 class FileInfo {
00017
00018 public:
00019
00020 enum Type {
00021 file_type_unknown = 0,
00022 file_type_file = 1,
00023 file_type_dir = 2
00024 };
00025
00026 FileInfo(const std::string& name = "")
00027 : name(name),
00028 size((unsigned long long int)(-1)),
00029 created((time_t)(-1)),
00030 valid((time_t)(-1)),
00031 type(file_type_unknown),
00032 latency("") {}
00033
00034 ~FileInfo() {}
00035
00036 const std::string& GetName() const {
00037 return name;
00038 }
00039
00040 std::string GetLastName() const {
00041 std::string::size_type pos = name.rfind('/');
00042 if (pos != std::string::npos)
00043 return name.substr(pos + 1);
00044 else
00045 return name;
00046 }
00047
00048 void SetName(const std::string& n) {
00049 name = n;
00050 }
00051
00052 const std::list<URL>& GetURLs() const {
00053 return urls;
00054 }
00055
00056 void AddURL(const URL& u) {
00057 urls.push_back(u);
00058 }
00059
00060 bool CheckSize() const {
00061 return (size != (unsigned long long int)(-1));
00062 }
00063
00064 unsigned long long int GetSize() const {
00065 return size;
00066 }
00067
00068 void SetSize(const unsigned long long int s) {
00069 size = s;
00070 }
00071
00072 bool CheckCheckSum() const {
00073 return (!checksum.empty());
00074 }
00075
00076 const std::string& GetCheckSum() const {
00077 return checksum;
00078 }
00079
00080 void SetCheckSum(const std::string& c) {
00081 checksum = c;
00082 }
00083
00084 bool CheckCreated() const {
00085 return (created != -1);
00086 }
00087
00088 Time GetCreated() const {
00089 return created;
00090 }
00091
00092 void SetCreated(const Time& t) {
00093 created = t;
00094 }
00095
00096 bool CheckValid() const {
00097 return (valid != -1);
00098 }
00099
00100 Time GetValid() const {
00101 return valid;
00102 }
00103
00104 void SetValid(const Time& t) {
00105 valid = t;
00106 }
00107
00108 bool CheckType() const {
00109 return (type != file_type_unknown);
00110 }
00111
00112 Type GetType() const {
00113 return type;
00114 }
00115
00116 void SetType(const Type t) {
00117 type = t;
00118 }
00119
00120 bool CheckLatency() const {
00121 return (!latency.empty());
00122 }
00123
00124 std::string GetLatency() const {
00125 return latency;
00126 }
00127
00128 void SetLatency(const std::string l) {
00129 latency = l;
00130 }
00131
00132 std::map<std::string, std::string> GetMetaData() const {
00133 return metadata;
00134 }
00135
00136 void SetMetaData(const std::string att, const std::string val) {
00137 metadata[att] = val;
00138 }
00139
00140 bool operator<(const FileInfo& f) const {
00141 return (lower(this->name).compare(lower(f.name)) < 0);
00142 }
00143
00144 operator bool() const {
00145 return !name.empty();
00146 }
00147
00148 bool operator!() const {
00149 return name.empty();
00150 }
00151
00152 private:
00153
00154 std::string name;
00155 std::list<URL> urls;
00156 unsigned long long int size;
00157 std::string checksum;
00158 Time created;
00159 Time valid;
00160 Type type;
00161 std::string latency;
00162 std::map<std::string, std::string> metadata;
00163 };
00164
00165 }
00166
00167 #endif // __ARC_FILEINFO_H__