1#include "NamesProvider.h"
2
3#include <IO/ReadBufferFromFile.h>
4#include "NamesFormatReader.h"
5
6
7bool LanguageRegionsNamesDataSource::isModified() const
8{
9 return updates_tracker.isModified();
10}
11
12size_t LanguageRegionsNamesDataSource::estimateTotalSize() const
13{
14 return Poco::File(path).getSize();
15}
16
17ILanguageRegionsNamesReaderPtr LanguageRegionsNamesDataSource::createReader()
18{
19 updates_tracker.fixCurrentVersion();
20 auto file_reader = std::make_shared<DB::ReadBufferFromFile>(path);
21 return std::make_unique<LanguageRegionsNamesFormatReader>(std::move(file_reader));
22}
23
24std::string LanguageRegionsNamesDataSource::getLanguage() const
25{
26 return language;
27}
28
29std::string LanguageRegionsNamesDataSource::getSourceName() const
30{
31 return path;
32}
33
34
35RegionsNamesDataProvider::RegionsNamesDataProvider(const std::string & directory_) : directory(directory_)
36{
37}
38
39ILanguageRegionsNamesDataSourcePtr RegionsNamesDataProvider::getLanguageRegionsNamesSource(const std::string & language) const
40{
41 const auto data_file = getDataFilePath(language);
42 if (Poco::File(data_file).exists())
43 return std::make_unique<LanguageRegionsNamesDataSource>(data_file, language);
44 else
45 return {};
46}
47
48std::string RegionsNamesDataProvider::getDataFilePath(const std::string & language) const
49{
50 return directory + "/regions_names_" + language + ".txt";
51}
52