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

index.cpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec00db4d9d93adbdac03671dd44e2d1751e31e8d (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "index.hpp"
#include "data_header.hpp"

#include "../platform/platform.hpp"
#include "../platform/file_name_utils.hpp"

#include "../coding/internal/file_data.hpp"


//////////////////////////////////////////////////////////////////////////////////
// MwmValue implementation
//////////////////////////////////////////////////////////////////////////////////

MwmValue::MwmValue(string const & name)
  : m_cont(GetPlatform().GetReader(name))
{
  m_factory.Load(m_cont);
}

string MwmValue::GetFileName() const
{
  string s = m_cont.GetFileName();
  pl::GetNameFromURLRequest(s);
  pl::GetNameWithoutExt(s);
  return s;
}

//////////////////////////////////////////////////////////////////////////////////
// Index::MwmLock implementation
//////////////////////////////////////////////////////////////////////////////////

string Index::MwmLock::GetFileName() const
{
  MwmValue * p = GetValue();
  return (p ? p->GetFileName() : string());
}

//////////////////////////////////////////////////////////////////////////////////
// Index implementation
//////////////////////////////////////////////////////////////////////////////////

int Index::GetInfo(string const & name, MwmInfo & info) const
{
  MwmValue value(name);

  feature::DataHeader const & h = value.GetHeader();
  info.m_limitRect = h.GetBounds();

  pair<int, int> const scaleR = h.GetScaleRange();
  info.m_minScale = static_cast<uint8_t>(scaleR.first);
  info.m_maxScale = static_cast<uint8_t>(scaleR.second);

  return h.GetVersion();
}

MwmValue * Index::CreateValue(string const & name) const
{
  return new MwmValue(name);
}

Index::Index()
{
}

Index::~Index()
{
  Cleanup();
}

namespace
{
  void DeleteMapFiles(string const & path, bool deleteReady)
  {
    (void)my::DeleteFileX(path);
    (void)my::DeleteFileX(path + RESUME_FILE_EXTENSION);
    (void)my::DeleteFileX(path + DOWNLOADING_FILE_EXTENSION);

    if (deleteReady)
      (void)my::DeleteFileX(path + READY_FILE_EXTENSION);
  }

  string GetFullPath(string const & fileName)
  {
    return GetPlatform().WritablePathForFile(fileName);
  }

  void ReplaceFileWithReady(string const & fileName)
  {
    string const path = GetFullPath(fileName);
    DeleteMapFiles(path, false);
    CHECK ( my::RenameFileX(path + READY_FILE_EXTENSION, path), (path) );
  }
}

bool Index::DeleteMap(string const & fileName)
{
  threads::MutexGuard mutexGuard(m_lock);
  UNUSED_VALUE(mutexGuard);

  if (!RemoveImpl(fileName))
    return false;

  DeleteMapFiles(GetFullPath(fileName), true);
  return true;
}

bool Index::UpdateMap(string const & fileName, m2::RectD & rect)
{
  threads::MutexGuard mutexGuard(m_lock);
  UNUSED_VALUE(mutexGuard);

  MwmId const id = GetIdByName(fileName);
  if (id != INVALID_MWM_ID)
  {
    m_info[id].m_status = MwmInfo::STATUS_UPDATE;
    return false;
  }

  ReplaceFileWithReady(fileName);

  (void)AddImpl(fileName, rect);
  return true;
}

void Index::UpdateMwmInfo(MwmId id)
{
  switch (m_info[id].m_status)
  {
  case MwmInfo::STATUS_TO_REMOVE:
    if (m_info[id].m_lockCount == 0)
    {
      DeleteMapFiles(m_name[id], true);

      CHECK(RemoveImpl(id), ());
    }
    break;

  case MwmInfo::STATUS_UPDATE:
    if (m_info[id].m_lockCount == 0)
    {
      ClearCache(id);

      ReplaceFileWithReady(m_name[id]);

      m_info[id].m_status = MwmInfo::STATUS_ACTIVE;
    }
    break;
  }
}

//////////////////////////////////////////////////////////////////////////////////
// Index::FeaturesLoaderGuard implementation
//////////////////////////////////////////////////////////////////////////////////

Index::FeaturesLoaderGuard::FeaturesLoaderGuard(Index const & parent, MwmId id)
  : m_lock(parent, id),
    /// @note This guard is suitable when mwm is loaded
    m_vector(m_lock.GetValue()->m_cont, m_lock.GetValue()->GetHeader())
{
}

bool Index::FeaturesLoaderGuard::IsWorld() const
{
  return (m_lock.GetValue()->GetHeader().GetType() == feature::DataHeader::world);
}

void Index::FeaturesLoaderGuard::GetFeature(uint32_t offset, FeatureType & ft)
{
  m_vector.Get(offset, ft);
}