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

taxi_provider.hpp « partners_api - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2a9c63fec5de1e806d8a260ee5363668f58eae25 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once

#include "base/assert.hpp"

#include <string>
#include <vector>

namespace taxi
{
struct Product
{
  std::string m_productId; // unique id of product for provider
  std::string m_name;      // name of product
  std::string m_time;      // wait time
  std::string m_price;     // for some currencies this field contains symbol of currency but not always
  std::string m_currency;  // currency can be empty, for ex. when m_price equal to Metered
};

class Provider
{
public:
  enum Type
  {
    Uber,
    Yandex,
    Maxim,
    Rutaxi,
    Count
  };

  using Iter = std::vector<Product>::iterator;
  using ConstIter = std::vector<Product>::const_iterator;

  Provider(Type type, std::vector<Product> const & products) : m_type(type), m_products(products) {}

  Type GetType() const { return m_type; }
  std::vector<Product> const & GetProducts() const { return m_products; }
  Product const & operator[](size_t i) const
  {
    ASSERT_LESS(i, m_products.size(), ());
    return m_products[i];
  }
  Product & operator[](size_t i)
  {
    ASSERT_LESS(i, m_products.size(), ());
    return m_products[i];
  }

  Iter begin() { return m_products.begin(); }
  Iter end() { return m_products.end(); }
  ConstIter begin() const { return m_products.cbegin(); }
  ConstIter end() const { return m_products.cend(); }

private:
  Type m_type;
  std::vector<Product> m_products;
};

using ProvidersContainer = std::vector<Provider>;

enum class ErrorCode
{
  NoProducts,
  RemoteError,
};

struct ProviderError
{
  ProviderError(Provider::Type type, ErrorCode code) : m_type(type), m_code(code) {}

  Provider::Type m_type;
  ErrorCode m_code;
};

using ErrorsContainer = std::vector<ProviderError>;

inline std::string DebugPrint(Provider::Type type)
{
  switch (type)
  {
  case Provider::Type::Uber: return "Uber";
  case Provider::Type::Yandex: return "Yandex";
  case Provider::Type::Maxim: return "Maxim";
  case Provider::Type::Rutaxi: return "Rutaxi";
  case Provider::Type::Count: ASSERT(false, ()); return "";
  }
  UNREACHABLE();
}

inline std::string DebugPrint(ErrorCode code)
{
  switch (code)
  {
  case ErrorCode::NoProducts: return "NoProducts";
  case ErrorCode::RemoteError: return "RemoteError";
  }
  UNREACHABLE();
}

inline std::string DebugPrint(ProviderError error)
{
  return "ProviderError [" + DebugPrint(error.m_type) + ", " + DebugPrint(error.m_code) + "]";
}
}  // namespace taxi