Welcome to mirror list, hosted at ThFree Co, Russian Federation.

taxi_places_loader.cpp « partners_api - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 07f40d5db0274d8023506d4febf40d300caa59f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "partners_api/taxi_places_loader.hpp"

#include "platform/platform.hpp"

namespace taxi
{
namespace places
{
SupportedPlaces Loader::LoadFor(Provider::Type const type)
{
  auto const filename = GetFileNameByProvider(type);

  std::string fileData;
  try
  {
    auto const fileReader = GetPlatform().GetReader(filename);
    fileReader->ReadAsString(fileData);
  }
  catch (FileAbsentException const & ex)
  {
    LOG(LERROR, ("Exception while get reader for file:", filename, "reason:", ex.what()));
    return {};
  }
  catch (FileReader::Exception const & ex)
  {
    LOG(LERROR, ("Exception while reading file:", filename, "reason:", ex.what()));
    return {};
  }

  ASSERT(!fileData.empty(), ());

  SupportedPlaces places;

  try
  {
    coding::DeserializerJson des(fileData);
    des(places);
  }
  catch (my::Json::Exception const & ex)
  {
    LOG(LWARNING,
        ("Exception while parsing file:", filename, "reason:", ex.what(), "json:", fileData));
    return {};
  }

  return places;
}

std::string Loader::GetFileNameByProvider(Provider::Type const type)
{
  switch (type)
  {
  case Provider::Type::Maxim: return "taxi_places/maxim.json";
  case Provider::Type::Rutaxi: return "taxi_places/rutaxi.json";
  case Provider::Type::Uber: return "taxi_places/uber.json";
  case Provider::Type::Yandex: return "taxi_places/yandex.json";
  case Provider::Type::Count: LOG(LERROR, ("Incorrect taxi provider")); return "";
  }
  CHECK_SWITCH();
}
}  // namespace places
}  // namespace taxi