aboutsummaryrefslogtreecommitdiff
path: root/src/support/filesystem_context.cc
blob: 21548a502846fa6f626fa07a1adcdd823e501251 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "filesystem_context.h"

#include <algorithm>
#include <iterator>

#include "support/xalan_string.h"

namespace InputXSLT {

void FilesystemContext::iterate(
	const boost::filesystem::path& directory,
	const std::function<void(const boost::filesystem::path&)>& func
) {
	std::vector<boost::filesystem::path> directoryItems;

	std::copy_if(
		boost::filesystem::directory_iterator(directory),
		boost::filesystem::directory_iterator(),
		std::back_inserter(directoryItems),
		[](const boost::filesystem::path& p) -> bool {
			return boost::filesystem::is_regular_file(p) ||
			       boost::filesystem::is_directory(p);
		}
	);

	std::sort(
		directoryItems.begin(),
		directoryItems.end()
	);

	std::for_each(
		directoryItems.begin(),
		directoryItems.end(),
		func
	);
}

FilesystemContext::FilesystemContext(const boost::filesystem::path& path):
	path_(boost::filesystem::canonical(
		path.parent_path()
	)) { }

FilesystemContext::FilesystemContext(const std::string& path):
	path_(boost::filesystem::canonical(path)) { }

boost::filesystem::path FilesystemContext::resolve(
	const xalan::XalanDOMString& path) const {
	return this->resolve(toString(path));
}

boost::filesystem::path FilesystemContext::resolve(
	const boost::filesystem::path& path) const {
	if ( path.is_absolute() ) {
		return path;
	} else {
		return absolute(this->path_ / path);
	}
}

}