MCPcopy Create free account
hub / github.com/comaps/comaps / ReadRegionDataImpl

Function ReadRegionDataImpl

generator/region_meta.cpp:30–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28namespace feature
29{
30bool ReadRegionDataImpl(std::string const & countryName, RegionData & data)
31{
32 /// @todo How LEAP_SPEEDS_FILE was generated before? It's always absent now.
33 if (Platform::IsFileExistsByFullPath(LEAP_SPEEDS_FILE))
34 {
35 try
36 {
37 auto crossMwmDataReader = GetPlatform().GetReader(LEAP_SPEEDS_FILE);
38 std::string crossMwmDataBuffer;
39 crossMwmDataReader->ReadAsString(crossMwmDataBuffer);
40 base::Json crossMwmData(crossMwmDataBuffer.data());
41
42 json_t const * crossMwmJsonData = nullptr;
43 FromJSONObjectOptionalField(crossMwmData.get(), countryName, crossMwmJsonData);
44 if (crossMwmJsonData)
45 {
46 double leapSpeed = FromJSONObject<double>(crossMwmJsonData, "leapspeed");
47 if (leapSpeed > 0.0)
48 data.SetLeapWeightSpeed(leapSpeed);
49 }
50 }
51 catch (FileAbsentException const & e)
52 {
53 LOG(LERROR, ("Error missing file", LEAP_SPEEDS_FILE, ":", e.Msg()));
54 return false;
55 }
56 catch (Reader::Exception const & e)
57 {
58 LOG(LERROR, ("Error reading", LEAP_SPEEDS_FILE, ":", e.Msg()));
59 return false;
60 }
61 catch (base::Json::Exception const & e)
62 {
63 LOG(LERROR, ("Error parsing JSON in", LEAP_SPEEDS_FILE, ":", e.Msg()));
64 return false;
65 }
66 }
67
68 try
69 {
70 auto reader = GetPlatform().GetReader(COUNTRIES_META_FILE);
71 std::string buffer;
72 reader->ReadAsString(buffer);
73 base::Json root(buffer.data());
74
75 json_t const * jsonData = nullptr;
76 FromJSONObjectOptionalField(root.get(), countryName, jsonData);
77 if (!jsonData)
78 return false;
79
80 std::vector<std::string> languages;
81 FromJSONObjectOptionalField(jsonData, "languages", languages);
82 if (!languages.empty())
83 data.SetLanguages(languages);
84
85 std::string driving;
86 FromJSONObjectOptionalField(jsonData, "driving", driving);
87 if (driving == "l" || driving == "r")

Callers 1

ReadRegionDataFunction · 0.85

Calls 11

ParseHolidayReferenceFunction · 0.85
SetLeapWeightSpeedMethod · 0.80
AddPublicHolidayMethod · 0.80
getMethod · 0.65
GetReaderMethod · 0.45
ReadAsStringMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45
SetLanguagesMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected