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

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

#include "indexer/data_source.hpp"
#include "indexer/feature.hpp"

#include "defines.hpp"

namespace ugc
{
Loader::Loader(DataSourceBase const & dataSource) : m_dataSource(dataSource) {}

UGC Loader::GetUGC(FeatureID const & featureId)
{
  auto const handle = m_dataSource.GetMwmHandleById(featureId.m_mwmId);

  if (!handle.IsAlive())
    return {};

  auto const & value = *handle.GetValue<MwmValue>();

  if (!value.m_cont.IsExist(UGC_FILE_TAG))
    return {};

  UGC ugc;
  EntryPtr entry;
  {
    std::lock_guard<std::mutex> lock(m_mutex);
    auto it = m_deserializers.find(featureId.m_mwmId);

    if (it == m_deserializers.end())
    {
      auto const result = m_deserializers.emplace(featureId.m_mwmId, make_shared<Entry>());
      it = result.first;
    }
    entry = it->second;
  }

  ASSERT(entry, ());

  {
    std::lock_guard<std::mutex> lock(entry->m_mutex);
    auto readerPtr = value.m_cont.GetReader(UGC_FILE_TAG);
    entry->m_deserializer.Deserialize(*readerPtr.GetPtr(), featureId.m_index, ugc);
  }

  return ugc;
}
}  // namespace ugc