| 1 | #pragma once | 
|---|---|
| 2 | |
| 3 | #include <unordered_map> | 
| 4 | #include <Poco/Exception.h> | 
| 5 | #include "GeodataProviders/IHierarchiesProvider.h" | 
| 6 | #include "RegionsHierarchy.h" | 
| 7 | |
| 8 | |
| 9 | /** Contains several hierarchies of regions. | 
| 10 | * Used to support several different perspectives on the ownership of regions by countries. | 
| 11 | * First of all, for the Crimea (Russian and Ukrainian points of view). | 
| 12 | */ | 
| 13 | class RegionsHierarchies | 
| 14 | { | 
| 15 | private: | 
| 16 | using Container = std::unordered_map<std::string, RegionsHierarchy>; | 
| 17 | Container data; | 
| 18 | |
| 19 | public: | 
| 20 | RegionsHierarchies(IRegionsHierarchiesDataProviderPtr data_provider); | 
| 21 | |
| 22 | /** Reloads, if necessary, all hierarchies of regions. | 
| 23 | */ | 
| 24 | void reload() | 
| 25 | { | 
| 26 | for (auto & elem : data) | 
| 27 | elem.second.reload(); | 
| 28 | } | 
| 29 | |
| 30 | |
| 31 | const RegionsHierarchy & get(const std::string & key) const | 
| 32 | { | 
| 33 | auto it = data.find(key); | 
| 34 | |
| 35 | if (data.end() == it) | 
| 36 | throw Poco::Exception( "There is no regions hierarchy for key "+ key); | 
| 37 | |
| 38 | return it->second; | 
| 39 | } | 
| 40 | }; | 
| 41 | 
