1 #include "collectdircontent.hxx"
3 PathFilePair
IncludesCollection::split_path(const string
& filePath
) {
6 string::size_type pos
= filePath
.rfind (sepU
);
7 string::size_type posW
= filePath
.rfind (sepW
);
8 if ((posW
!= string::npos
) && ((posW
> pos
) || (pos
== string::npos
))) pos
= posW
;
9 if (pos
!= string::npos
) {
10 string dirName
= filePath
.substr(0, pos
);
11 return PathFilePair(dirName
, filePath
.substr(pos
+ 1, filePath
.length()));
13 return PathFilePair(".", filePath
);
16 void IncludesCollection::add_to_collection(const string
& dirPath
) {
17 DirContent dirContent
;
19 WIN32_FIND_DATA FindFileData
;
21 hFind
= FindFirstFile((dirPath
+ "\\*").c_str(), &FindFileData
);
22 if (hFind
== INVALID_HANDLE_VALUE
) {
23 // Invalid File Handle - no need to try it anymore
24 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
28 string
winFileName(FindFileData
.cFileName
);
29 transform(winFileName
.begin(), winFileName
.end(), winFileName
.begin(), ::tolower
);
30 dirContent
.insert(winFileName
);
31 } while (FindNextFile(hFind
, &FindFileData
));
35 pdir
= opendir(dirPath
.c_str()); //"." refers to the current dir
37 // Invalid File Handle - no need to try it anymore
38 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
41 while ((pent
= readdir(pdir
))) {
42 dirContent
.insert(pent
->d_name
);
44 #endif // defined( WNT )
45 allIncludes
.insert(EntriesPair(dirPath
, dirContent
));
48 bool IncludesCollection::exists(string filePath
) {
50 transform(filePath
.begin(), filePath
.end(), filePath
.begin(), ::tolower
);
51 #endif // defined( WNT )
52 PathFilePair dirFile
= split_path(filePath
);
53 string dirPath
= dirFile
.first
;
54 string fileName
= dirFile
.second
;
55 DirMap::iterator mapIter
= allIncludes
.find(dirPath
);
56 if (mapIter
== allIncludes
.end()) {
57 add_to_collection(dirPath
);
58 mapIter
= allIncludes
.find(dirPath
);
60 DirContent dirContent
= (*mapIter
).second
;
61 DirContent::iterator dirIter
= dirContent
.find(fileName
);
62 if (dirIter
== dirContent
.end()) {
72 IncludesCollection
* create_IncludesCollection() {
73 return new IncludesCollection
;
76 void delete_IncludesCollection(IncludesCollection
*m
) {
80 int call_IncludesCollection_exists(IncludesCollection
* m
, const char * filePath
) {
81 return m
->exists(filePath
);