ARC SDK
FileInfo.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_FILEINFO_H__
4 #define __ARC_FILEINFO_H__
5 
6 #include <list>
7 #include <string>
8 
9 #include <arc/DateTime.h>
10 #include <arc/URL.h>
11 #include <arc/StringConv.h>
12 
13 namespace Arc {
14 
16 
25  class FileInfo {
26 
27  public:
28 
30  enum Type {
34  };
35 
37  FileInfo(const std::string& name = "")
38  : name(name),
39  size((unsigned long long int)(-1)),
40  modified((time_t)(-1)),
41  valid((time_t)(-1)),
42  type(file_type_unknown),
43  latency("") {
44  if (!name.empty()) metadata["name"] = name;
45  }
46 
48  const std::string& GetName() const {
49  return name;
50  }
51 
53  std::string GetLastName() const {
54  std::string::size_type pos = name.rfind('/');
55  if (pos != std::string::npos)
56  return name.substr(pos + 1);
57  else
58  return name;
59  }
60 
62  void SetName(const std::string& n) {
63  name = n;
64  metadata["name"] = n;
65  }
66 
68  const std::list<URL>& GetURLs() const {
69  return urls;
70  }
71 
73  void AddURL(const URL& u) {
74  urls.push_back(u);
75  }
76 
78  bool CheckSize() const {
79  return (size != (unsigned long long int)(-1));
80  }
81 
83  unsigned long long int GetSize() const {
84  return size;
85  }
86 
88  void SetSize(const unsigned long long int s) {
89  size = s;
90  metadata["size"] = tostring(s);
91  }
92 
94  bool CheckCheckSum() const {
95  return (!checksum.empty());
96  }
97 
99  const std::string& GetCheckSum() const {
100  return checksum;
101  }
102 
104  void SetCheckSum(const std::string& c) {
105  checksum = c;
106  metadata["checksum"] = c;
107  }
108 
110  bool CheckModified() const {
111  return (modified != -1);
112  }
113 
115  Time GetModified() const {
116  return modified;
117  }
118 
120  void SetModified(const Time& t) {
121  modified = t;
122  metadata["mtime"] = t.str();
123  }
124 
126  bool CheckValid() const {
127  return (valid != -1);
128  }
129 
131  Time GetValid() const {
132  return valid;
133  }
134 
136  void SetValid(const Time& t) {
137  valid = t;
138  metadata["validity"] = t.str();
139  }
140 
142  bool CheckType() const {
143  return (type != file_type_unknown);
144  }
145 
147  Type GetType() const {
148  return type;
149  }
150 
152  void SetType(const Type t) {
153  type = t;
154  if (t == file_type_file) metadata["type"] = "file";
155  else if (t == file_type_dir) metadata["type"] = "dir";
156  }
157 
159  bool CheckLatency() const {
160  return (!latency.empty());
161  }
162 
164  std::string GetLatency() const {
165  return latency;
166  }
167 
169  void SetLatency(const std::string l) {
170  latency = l;
171  metadata["latency"] = l;
172  }
173 
175  std::map<std::string, std::string> GetMetaData() const {
176  return metadata;
177  }
178 
180  void SetMetaData(const std::string att, const std::string val) {
181  metadata[att] = val;
182  }
183 
185  bool operator<(const FileInfo& f) const {
186  return (lower(this->name).compare(lower(f.name)) < 0);
187  }
188 
190  operator bool() const {
191  return !name.empty();
192  }
193 
195  bool operator!() const {
196  return name.empty();
197  }
198 
199  private:
200 
201  std::string name;
202  std::list<URL> urls; // Physical enpoints/URLs.
203  unsigned long long int size; // Size of file in bytes.
204  std::string checksum; // Checksum of file.
205  Time modified; // Creation/modification time.
206  Time valid; // Valid till time.
207  Type type; // File type - usually file_type_file
208  std::string latency; // Access latenct of file (applies to SRM only)
209  std::map<std::string, std::string> metadata; // Generic metadata attribute-value pairs
210  };
211 
212 } // namespace Arc
213 
214 #endif // __ARC_FILEINFO_H__