aboutsummaryrefslogtreecommitdiff
path: root/src/tracking/change_tracker.h
blob: 04a5a00fa41ef0427a14f583822b9b8365934ddf (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
#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();

		bool is_tracked(const std::string&) const;

		bool 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_;

		// threadsafe child emplacement
		auto create_child(const std::string&);

};

}

#endif  // CHANGE_SRC_TRACKING_CHANGE_TRACKER_H_