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

booking_filter_params.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c1e721b416a329e52537191557ccfbb1327fda8b (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#pragma once

#include "partners_api/booking_availability_params.hpp"
#include "partners_api/booking_params_base.hpp"

#include "platform/safe_callback.hpp"

#include "indexer/feature_decl.hpp"

#include <algorithm>
#include <functional>
#include <memory>
#include <utility>
#include <vector>

namespace search
{
class Results;
}

namespace booking
{
namespace filter
{
using Results = platform::SafeCallback<void(std::shared_ptr<ParamsBase> const & params,
                                            std::vector<FeatureID> const & sortedFeatures)>;
using ResultsUnsafe = std::function<void(search::Results const & results)>;
using ResultsRawUnsafe = std::function<void(std::vector<FeatureID> const & results)>;

template <typename R>
struct ParamsImpl
{
  ParamsImpl() = default;
  ParamsImpl(std::shared_ptr<ParamsBase> apiParams, R const & cb)
    : m_apiParams(apiParams)
    , m_callback(cb)
  {
  }

  bool IsEmpty() const { return !m_apiParams || m_apiParams->IsEmpty(); }

  std::shared_ptr<ParamsBase> m_apiParams;
  R m_callback;
};

using Params = ParamsImpl<Results>;
using ParamsInternal = ParamsImpl<ResultsUnsafe>;
using ParamsRawInternal = ParamsImpl<ResultsRawUnsafe>;

enum class Type
{
  Deals,
  Availability
};

using Types = std::vector<Type>;

template <typename T>
struct TaskImpl
{
  TaskImpl(Type const type, T && filterParams)
    : m_type(type)
    , m_filterParams(std::move(filterParams))
  {
  }

  Type m_type;
  T m_filterParams;
};

using Task = TaskImpl<Params>;
using TaskInternal = TaskImpl<ParamsInternal>;
using TaskRawInternal = TaskImpl<ParamsRawInternal>;

enum ApplicationMode
{
  /// Apply filters independently on provided list of search results.
  /// Every filter will be applied on its own copy of search results.
  Independent,
  /// Apply each filter one by one on provided list of search results.
  /// All filters will be applied on the same copy of search results.
  Consecutive
};

template <typename T>
class TasksImpl
{
public:
  using Iter = std::vector<Task>::iterator;
  using ConstIter = std::vector<Task>::const_iterator;

  TasksImpl() = default;
  explicit TasksImpl(ApplicationMode const mode) : m_applyMode(mode) {}

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

  Iter Find(Type const type)
  {
    return std::find_if(m_tasks.begin(), m_tasks.end(),[type](Task const & task)
    {
      return task.m_type == type;
    });
  }

  ConstIter Find(Type const type) const
  {
    return std::find_if(m_tasks.cbegin(), m_tasks.cend(),[type](Task const & task)
    {
      return task.m_type == type;
    });
  }

  bool IsEmpty() const
  {
    return m_tasks.empty();
  }

  void Clear()
  {
    m_tasks.clear();
  }

  template <typename ... Args>
  void EmplaceBack(Args && ... args)
  {
    m_tasks.emplace_back(std::forward<Args>(args)...);
  }

  ApplicationMode GetMode() const
  {
    return m_applyMode;
  }

private:
  std::vector<T> m_tasks;
  ApplicationMode m_applyMode = ApplicationMode::Independent;
};

using Tasks = TasksImpl<Task>;
using TasksInternal = std::vector<TaskInternal>;
using TasksRawInternal = std::vector<TaskRawInternal>;
}  // namespace filter
}  // namespace booking