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

banners.hpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 50f2164cd81675efa3c8ed78b07dad8d369981a0 (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
#pragma once

#include "std/ctime.hpp"
#include "std/iostream.hpp"
#include "std/string.hpp"
#include "std/unordered_map.hpp"

class FeatureType;

namespace banner
{
class Banner
{
public:
  Banner() = default;
  explicit Banner(string const & id);

  bool IsEmpty() const { return m_id.empty(); }
  string GetMessageBase() const { return m_messageBase; }
  string GetIconName() const { return m_iconName; }
  string GetDefaultUrl() const { return m_defaultUrl; }
  string GetId() const { return m_id; }
  bool IsActive() const;

  /// Replaces inline variables in the URL, uses the default banner URL if url is not specified.
  string GetFormattedUrl(string const & url = {}) const;

  /// Usually called from BannerSet.
  void SetProperty(string const & name, string const & value);

private:
  string m_id;
  string m_messageBase;
  string m_iconName;
  string m_defaultUrl;
  time_t m_activeAfter;
  time_t m_activeBefore;
  unordered_map<string, string> m_properties;

  string GetProperty(string const & name) const;
};

class BannerSet
{
public:
  void LoadBanners();
  void ReadBanners(istream & s);

  bool HasBannerForType(uint32_t type) const;
  Banner const & GetBannerForType(uint32_t type) const;

  bool HasBannerForFeature(FeatureType const & ft) const;
  Banner const & GetBannerForFeature(FeatureType const & ft) const;

private:
  unordered_map<uint32_t, Banner> m_banners;

  void Add(Banner const & banner, string const & type);
};
}