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

ads_base.cpp « partners_api - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d42c5c42decf98d84a49657fd5a8632dc4117d07 (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
#include "partners_api/ads_base.hpp"

#include "indexer/classificator.hpp"
#include "indexer/feature_data.hpp"

#include "coding/string_utf8_multilang.hpp"

#include <algorithm>

namespace ads
{
Container::Container()
{
  AppendExcludedTypes({{"sponsored", "booking"},
                       {"tourism", "hotel"},
                       {"tourism", "apartment"},
                       {"tourism", "camp_site"},
                       {"tourism", "chalet"},
                       {"tourism", "guest_house"},
                       {"tourism", "hostel"},
                       {"tourism", "motel"},
                       {"tourism", "resort"}});
}

void Container::AppendEntry(std::initializer_list<std::initializer_list<char const *>> && types,
                            std::string const & id)
{
  m_typesToBanners.Append(std::move(types), id);
}

void Container::AppendExcludedTypes(
    std::initializer_list<std::initializer_list<char const *>> && types)
{
  m_excludedTypes.Append(std::move(types));
}

void Container::AppendSupportedCountries(
    std::initializer_list<storage::CountryId> const & countries)
{
  m_supportedCountries.insert(countries.begin(), countries.end());
}

void Container::AppendSupportedUserLanguages(std::initializer_list<std::string> const & languages)
{
  for (auto const & language : languages)
  {
    int8_t const langIndex = StringUtf8Multilang::GetLangIndex(language);
    if (langIndex == StringUtf8Multilang::kUnsupportedLanguageCode)
      continue;
    m_supportedUserLanguages.insert(langIndex);
  }
}

bool Container::HasBanner(feature::TypesHolder const & types, storage::CountryId const & countryId,
                          std::string const & userLanguage) const
{
  if (!m_supportedCountries.empty() &&
      m_supportedCountries.find(countryId) == m_supportedCountries.end())
  {
    auto const userLangCode = StringUtf8Multilang::GetLangIndex(userLanguage);
    if (m_supportedUserLanguages.find(userLangCode) == m_supportedUserLanguages.end())
      return false;
  }
  return !m_excludedTypes.Contains(types);
}

std::string Container::GetBannerId(feature::TypesHolder const & types,
                                   storage::CountryId const & countryId,
                                   std::string const & userLanguage) const
{
  if (!HasBanner(types, countryId, userLanguage))
    return {};

  auto const it = m_typesToBanners.Find(types);
  if (m_typesToBanners.IsValid(it))
    return it->second;

  return GetBannerIdForOtherTypes();
}

std::string Container::GetBannerIdForOtherTypes() const
{
  return {};
}

bool Container::HasSearchBanner() const
{
  return false;
}

std::string Container::GetSearchBannerId() const
{
  return {};
}
}  // namespace ads