]> git.tdb.fi Git - libs/datafile.git/blob - source/directorycollection.cpp
Introduce the concept of future objects
[libs/datafile.git] / source / directorycollection.cpp
1 #include <msp/fs/stat.h>
2 #include "directorycollection.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace DataFile {
8
9 DirectoryCollection::DirectoryCollection()
10 {
11         set_directory(".");
12 }
13
14 void DirectoryCollection::set_directory(const FS::Path &d)
15 {
16         dirs.clear();
17         add_directory(d);
18 }
19
20 void DirectoryCollection::add_directory(const FS::Path &d)
21 {
22         dirs.push_back(d);
23 }
24
25 bool DirectoryCollection::lookup_file(const string &name, FS::Path &result) const
26 {
27         for(list<FS::Path>::const_iterator i=dirs.begin(); i!=dirs.end(); ++i)
28         {
29                 FS::Path file_path = *i/name;
30                 if(FS::exists(file_path))
31                 {
32                         result = file_path;
33                         return true;
34                 }
35         }
36
37         return false;
38 }
39
40 } // namespace DataFile
41 } // namespace Msp