2017-11-28 22:15:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-11-28 11:37:12 +00:00
|
|
|
#include "IHierarchiesProvider.h"
|
2017-11-28 22:15:06 +00:00
|
|
|
|
|
|
|
#include <unordered_map>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <Common/FileUpdatesTracker.h>
|
2017-11-28 22:15:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Represents local file with regions hierarchy dump
|
2018-12-10 15:25:45 +00:00
|
|
|
class RegionsHierarchyDataSource : public IRegionsHierarchyDataSource
|
2017-11-28 22:15:06 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string path;
|
|
|
|
FileUpdatesTracker updates_tracker;
|
|
|
|
|
|
|
|
public:
|
2018-12-10 15:25:45 +00:00
|
|
|
RegionsHierarchyDataSource(const std::string & path_) : path(path_), updates_tracker(path_) {}
|
2017-11-28 22:15:06 +00:00
|
|
|
|
|
|
|
bool isModified() const override;
|
|
|
|
|
|
|
|
IRegionsHierarchyReaderPtr createReader() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Provides access to directory with multiple data source files: one file per regions hierarchy
|
2018-12-10 15:25:45 +00:00
|
|
|
class RegionsHierarchiesDataProvider : public IRegionsHierarchiesDataProvider
|
2017-11-28 22:15:06 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
// path to file with default regions hierarchy
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
using HierarchyFiles = std::unordered_map<std::string, std::string>;
|
|
|
|
HierarchyFiles hierarchy_files;
|
|
|
|
|
|
|
|
public:
|
2017-11-28 22:18:38 +00:00
|
|
|
/** path must point to the file with the hierarchy of regions "by default". It will be accessible by an empty key.
|
2017-11-28 22:15:06 +00:00
|
|
|
* In addition, a number of files are searched for, the name of which (before the extension, if any) is added arbitrary _suffix.
|
|
|
|
* Such files are loaded, and the hierarchy of regions is put on the `suffix` key.
|
|
|
|
*
|
|
|
|
* For example, if /opt/geo/regions_hierarchy.txt is specified,
|
|
|
|
* then the /opt/geo/regions_hierarchy_ua.txt file will also be loaded, if any, it will be accessible by the `ua` key.
|
|
|
|
*/
|
|
|
|
RegionsHierarchiesDataProvider(const std::string & path);
|
|
|
|
|
|
|
|
std::vector<std::string> listCustomHierarchies() const override;
|
|
|
|
|
|
|
|
IRegionsHierarchyDataSourcePtr getDefaultHierarchySource() const override;
|
|
|
|
IRegionsHierarchyDataSourcePtr getHierarchySource(const std::string & name) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void discoverFilesWithCustomHierarchies();
|
|
|
|
};
|