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__
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
bool CheckType() const
Check if file type is known.
Definition: FileInfo.h:142
std::string str(const TimeFormat &=time_format) const
Returns a string representation of the time, using the specified format.
void SetType(const Type t)
Set file type.
Definition: FileInfo.h:152
unsigned long long int GetSize() const
Returns file size.
Definition: FileInfo.h:83
bool CheckCheckSum() const
Check if checksum is known.
Definition: FileInfo.h:94
void SetLatency(const std::string l)
Set access latency.
Definition: FileInfo.h:169
bool operator!() const
Returns true if file name is not defined.
Definition: FileInfo.h:195
A class for storing and manipulating times.
Definition: DateTime.h:125
void SetName(const std::string &n)
Set name of the file (file path).
Definition: FileInfo.h:62
std::string GetLatency() const
Returns access latency.
Definition: FileInfo.h:164
Type GetType() const
Returns file type.
Definition: FileInfo.h:147
bool operator<(const FileInfo &f) const
Returns true if this file&#39;s name is before f&#39;s name alphabetically.
Definition: FileInfo.h:185
void SetValid(const Time &t)
Set validity time.
Definition: FileInfo.h:136
void SetModified(const Time &t)
Set modified time.
Definition: FileInfo.h:120
bool CheckLatency() const
Check if access latency is known.
Definition: FileInfo.h:159
void AddURL(const URL &u)
Add a replica to this file.
Definition: FileInfo.h:73
std::string tostring(T t, int width=0, int precision=0)
This method converts any type to a string of the width given.
Definition: StringConv.h:92
const std::list< URL > & GetURLs() const
Returns the list of file replicas (for index services).
Definition: FileInfo.h:68
bool CheckModified() const
Check if modified time is known.
Definition: FileInfo.h:110
std::map< std::string, std::string > GetMetaData() const
Returns map of generic metadata.
Definition: FileInfo.h:175
bool CheckSize() const
Check if file size is known.
Definition: FileInfo.h:78
Unknown.
Definition: FileInfo.h:31
const std::string & GetCheckSum() const
Returns checksum.
Definition: FileInfo.h:99
Time GetValid() const
Returns validity time.
Definition: FileInfo.h:131
Time GetModified() const
Returns modified time.
Definition: FileInfo.h:115
std::string GetLastName() const
Returns the last component of the file name (like the "basename" command).
Definition: FileInfo.h:53
Class to represent general URLs.
Definition: URL.h:88
std::string lower(const std::string &s)
This method converts the given string to lower case.
void SetSize(const unsigned long long int s)
Set file size.
Definition: FileInfo.h:88
Type
Type of file object.
Definition: FileInfo.h:30
bool CheckValid() const
Check if validity time is known.
Definition: FileInfo.h:126
void SetMetaData(const std::string att, const std::string val)
Set an attribute of generic metadata.
Definition: FileInfo.h:180
FileInfo stores information about files (metadata).
Definition: FileInfo.h:25
const std::string & GetName() const
Returns the name (file path) of the file.
Definition: FileInfo.h:48
FileInfo(const std::string &name="")
Construct a new FileInfo with optional name (file path).
Definition: FileInfo.h:37
void SetCheckSum(const std::string &c)
Set checksum.
Definition: FileInfo.h:104
File-type.
Definition: FileInfo.h:32
Directory-type.
Definition: FileInfo.h:33