aboutsummaryrefslogtreecommitdiff
path: root/src/tracking/change_tracker.h
blob: a9c98005db3ef8d086f8f8fc838c208917a73188 (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
#ifndef CHANGE_SRC_TRACKING_CHANGE_TRACKER_H_
#define CHANGE_SRC_TRACKING_CHANGE_TRACKER_H_

#include <mutex>
#include <sstream>
#include <unordered_map>

#include "utility/logger.h"

namespace tracking {

class ChangeTracker {
	public:
		ChangeTracker(utility::Logger*, const std::string&);
		ChangeTracker(utility::Logger*);
		~ChangeTracker();

		// Begin tracking changes to a given path if not already covered.
		void track(const std::string&);

	private:
		const std::string      diff_cmd_;
		utility::Logger* const logger_;
		std::mutex             write_mutex_;

		std::unordered_map<
			std::string,
			std::unique_ptr<std::stringstream>
		> children_;

		bool is_tracked(const boost::filesystem::path&) const;

		// threadsafe child emplacement
		auto create_child(const boost::filesystem::path&);

};

}

#endif  // CHANGE_SRC_TRACKING_CHANGE_TRACKER_H_