1 | #pragma once |
2 | |
3 | #include "IHierarchiesProvider.h" |
4 | |
5 | #include <unordered_map> |
6 | #include <Common/FileUpdatesTracker.h> |
7 | |
8 | |
9 | // Represents local file with regions hierarchy dump |
10 | class RegionsHierarchyDataSource : public IRegionsHierarchyDataSource |
11 | { |
12 | private: |
13 | std::string path; |
14 | FileUpdatesTracker updates_tracker; |
15 | |
16 | public: |
17 | RegionsHierarchyDataSource(const std::string & path_) : path(path_), updates_tracker(path_) {} |
18 | |
19 | bool isModified() const override; |
20 | |
21 | IRegionsHierarchyReaderPtr createReader() override; |
22 | }; |
23 | |
24 | |
25 | // Provides access to directory with multiple data source files: one file per regions hierarchy |
26 | class RegionsHierarchiesDataProvider : public IRegionsHierarchiesDataProvider |
27 | { |
28 | private: |
29 | // path to file with default regions hierarchy |
30 | std::string path; |
31 | |
32 | using HierarchyFiles = std::unordered_map<std::string, std::string>; |
33 | HierarchyFiles hierarchy_files; |
34 | |
35 | public: |
36 | /** path must point to the file with the hierarchy of regions "by default". It will be accessible by an empty key. |
37 | * In addition, a number of files are searched for, the name of which (before the extension, if any) is added arbitrary _suffix. |
38 | * Such files are loaded, and the hierarchy of regions is put on the `suffix` key. |
39 | * |
40 | * For example, if /opt/geo/regions_hierarchy.txt is specified, |
41 | * then the /opt/geo/regions_hierarchy_ua.txt file will also be loaded, if any, it will be accessible by the `ua` key. |
42 | */ |
43 | RegionsHierarchiesDataProvider(const std::string & path_); |
44 | |
45 | std::vector<std::string> listCustomHierarchies() const override; |
46 | |
47 | IRegionsHierarchyDataSourcePtr getDefaultHierarchySource() const override; |
48 | IRegionsHierarchyDataSourcePtr getHierarchySource(const std::string & name) const override; |
49 | |
50 | private: |
51 | void discoverFilesWithCustomHierarchies(); |
52 | }; |
53 | |