Ticket #8904: archivemember.patch
File archivemember.patch, 5.7 KB (added by , 17 years ago) |
---|
-
archive.cpp
30 30 namespace Common { 31 31 32 32 33 int Archive::matchPattern( StringList &list, const String &pattern) {33 int Archive::matchPattern(ArchiveMemberList &list, const String &pattern) { 34 34 // Get all "names" (TODO: "files" ?) 35 StringList allNames;35 ArchiveMemberList allNames; 36 36 getAllNames(allNames); 37 37 38 38 int matches = 0; … … 41 41 String lowercasePattern = pattern; 42 42 lowercasePattern.toLowercase(); 43 43 44 StringList::iterator it = allNames.begin();44 ArchiveMemberList::iterator it = allNames.begin(); 45 45 for ( ; it != allNames.end(); it++) { 46 if ( it->matchString(lowercasePattern)) {46 if ((*it)->getName().matchString(lowercasePattern)) { 47 47 list.push_back(*it); 48 48 matches++; 49 49 } … … 52 52 return matches; 53 53 } 54 54 55 /** 56 * FSDirectoryMemeber is the implementation of ArchiveMember used by 57 * by FSDirectory. It is right now a light wrapper or FSNode. 58 */ 59 class FSDirectoryMember : public ArchiveMember { 60 FilesystemNode _node; 55 61 62 public: 63 FSDirectoryMember(FilesystemNode &node) : _node(node) { 64 } 65 66 /* 67 NOTE/FIXME: since I assume that the only use case for getName() 68 is for error messages, I am returning the full path of the node 69 here. This seems better than we did before, when matchPattern 70 and getAllNames used to work with StringList, and we used to 71 put the relative path of the file to the list instead. 72 */ 73 String getName() const { 74 return _node.getPath(); 75 } 76 77 SeekableReadStream *open() { 78 return _node.openForReading(); 79 } 80 }; 81 82 typedef SharedPtr<FSDirectoryMember> FSDirectoryMemberPtr; 83 84 56 85 FSDirectory::FSDirectory(const FilesystemNode &node, int depth) 57 86 : _node(node), _cached(false), _depth(depth) { 58 87 } … … 159 188 160 189 } 161 190 162 int FSDirectory::getAllNames( StringList &list) {191 int FSDirectory::getAllNames(ArchiveMemberList &list) { 163 192 if (!_node.isDirectory()) 164 193 return 0; 165 194 … … 169 198 _cached = true; 170 199 } 171 200 172 // Small optimization: Ensure the StringList has to grow at most once173 list.reserve(list.size() + _fileCache.size());174 175 201 // Add all filenames from our cache 176 202 NodeCache::iterator it = _fileCache.begin(); 177 203 for ( ; it != _fileCache.end(); it++) { 178 list.push_back( (*it)._key);204 list.push_back(FSDirectoryMemberPtr(new FSDirectoryMember((*it)._value))); 179 205 } 180 206 181 207 return _fileCache.size(); 182 208 } 183 209 184 210 185 211 212 213 186 214 SearchSet::ArchiveList::iterator SearchSet::find(const String &name) const { 187 215 ArchiveList::iterator it = _list.begin(); 188 216 for ( ; it != _list.end(); it++) { … … 265 293 return false; 266 294 } 267 295 268 int SearchSet::matchPattern( StringList &list, const String &pattern) {296 int SearchSet::matchPattern(ArchiveMemberList &list, const String &pattern) { 269 297 // Shall we short circuit out if pattern is empty? 270 298 271 299 int matches = 0; … … 278 306 return matches; 279 307 } 280 308 309 281 310 SeekableReadStream *SearchSet::openFile(const String &name) { 282 311 if (name.empty()) { 283 312 return 0; -
archive.h
37 37 namespace Common { 38 38 39 39 /** 40 * ArchiveMember is the base class for the objects returned when Archive 41 * is searched using matchPattern() or getAllNames(), thus - possibly - 42 * yielding multiple matches. 43 */ 44 class ArchiveMember { 45 public: 46 virtual ~ArchiveMember() { } 47 48 /** 49 * Return a name (or description) of the instance. 50 */ 51 virtual String getName() const = 0; 52 53 /** 54 * Open the underlying file/handle/entity for reading. 55 */ 56 virtual SeekableReadStream *open() = 0; 57 }; 58 59 typedef List<SharedPtr<ArchiveMember> > ArchiveMemberList; 60 61 62 /** 40 63 * FilePtr is a convenient way to keep track of a SeekableReadStream without 41 64 * having to worry about releasing its memory. 42 65 */ … … 57 80 virtual bool hasFile(const String &name) = 0; 58 81 59 82 /** 60 * Add all the names present in the Archive which match pattern to61 * list. Returned names can be used as parameters to openFile.83 * Add all the objects present in the Archive which match pattern to 84 * list. 62 85 * Must not remove elements from the list. 63 86 * 64 87 * @return the number of names added to list 65 88 */ 66 virtual int matchPattern( StringList &list, const String &pattern);89 virtual int matchPattern(ArchiveMemberList &list, const String &pattern); 67 90 68 91 /** 69 * Add all the names present in the Archive to list. Returned 70 * names can be used as parameters to openFile. 92 * Add all the names present in the Archive to list. 71 93 * Must not remove elements from the list. 72 94 * 73 95 * @return the number of names added to list 74 96 */ 75 virtual int getAllNames( StringList &list) = 0;97 virtual int getAllNames(ArchiveMemberList &list) = 0; 76 98 77 99 /** 78 100 * Create a stream bound to a file in the archive. … … 138 160 FSDirectory *getSubDirectory(const String &name); 139 161 140 162 virtual bool hasFile(const String &name); 141 virtual int getAllNames( StringList &list);163 virtual int getAllNames(ArchiveMemberList &list); 142 164 virtual SeekableReadStream *openFile(const String &name); 143 165 }; 144 166 … … 191 213 void setPriority(const String& name, uint priority); 192 214 193 215 virtual bool hasFile(const String &name); 194 virtual int matchPattern( StringList &list, const String &pattern);195 virtual int getAllNames( StringList &list) {216 virtual int matchPattern(ArchiveMemberList &list, const String &pattern); 217 virtual int getAllNames(ArchiveMemberList &list) { 196 218 return matchPattern(list, "*"); 197 219 } 198 220 … … 239 261 240 262 241 263 virtual bool hasFile(const String &name); 242 virtual int getAllNames( StringList &list) {264 virtual int getAllNames(ArchiveMemberList &list) { 243 265 return matchPattern(list, "*"); 244 266 } 245 267