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

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

#include "base/assert.hpp"

namespace storage
{
QueuedCountry::QueuedCountry(TIndex const & index, MapOptions opt)
    : m_index(index), m_init(opt), m_left(opt), m_current(MapOptions::Nothing)
{
  ASSERT(GetIndex().IsValid(), ("Only valid countries may be downloaded."));
  ASSERT(m_left != MapOptions::Nothing, ("Empty file set was requested for downloading."));
  SwitchToNextFile();
}

void QueuedCountry::AddOptions(MapOptions opt)
{
  for (MapOptions file : {MapOptions::Map, MapOptions::CarRouting})
  {
    if (HasOptions(opt, file) && !HasOptions(m_init, file))
    {
      m_init = SetOptions(m_init, file);
      m_left = SetOptions(m_left, file);
    }
  }
}

void QueuedCountry::RemoveOptions(MapOptions opt)
{
  for (MapOptions file : {MapOptions::Map, MapOptions::CarRouting})
  {
    if (HasOptions(opt, file) && HasOptions(m_init, file))
    {
      m_init = UnsetOptions(m_init, file);
      m_left = UnsetOptions(m_left, file);
    }
  }
  if (HasOptions(opt, m_current))
    m_current = LeastSignificantOption(m_left);
}

bool QueuedCountry::SwitchToNextFile()
{
  // static_casts are needed here because MapOptions values are
  // actually enum flags (see 3party/enum_flags.hpp) and bitwise
  // operators are overloaded for them.
  ASSERT(HasOptions(m_left, m_current),
         ("Current file (", m_current, ") is not specified in left files (", m_left, ")."));
  m_left = UnsetOptions(m_left, m_current);
  m_current = LeastSignificantOption(m_left);
  return m_current != MapOptions::Nothing;
}
}  // namespace storage