]> git.tdb.fi Git - libs/datafile.git/blob - source/directorycollection.cpp
Restructure the tool and make it able to handle multiple input files
[libs/datafile.git] / source / directorycollection.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include "directorycollection.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace DataFile {
9
10 DirectoryCollection::DirectoryCollection()
11 {
12         set_directory(".");
13 }
14
15 void DirectoryCollection::set_directory(const FS::Path &d)
16 {
17         dirs.clear();
18         add_directory(d);
19 }
20
21 void DirectoryCollection::add_directory(const FS::Path &d)
22 {
23         dirs.push_back(d);
24 }
25
26 void DirectoryCollection::load_names()
27 {
28         for(list<FS::Path>::const_iterator i=dirs.begin(); i!=dirs.end(); ++i)
29         {
30                 list<string> names = FS::list_files(*i);
31                 for(list<string>::const_iterator j=names.begin(); j!=names.end(); ++j)
32                         add_future(*j);
33         }
34 }
35
36 bool DirectoryCollection::lookup_file(const string &name, FS::Path &result) const
37 {
38         for(list<FS::Path>::const_iterator i=dirs.begin(); i!=dirs.end(); ++i)
39         {
40                 FS::Path file_path = *i/name;
41                 if(FS::exists(file_path))
42                 {
43                         result = file_path;
44                         return true;
45                 }
46         }
47
48         return false;
49 }
50
51 } // namespace DataFile
52 } // namespace Msp