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

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

#include "indexer/feature_meta.hpp"

#include "std/mutex.hpp"
#include "std/shared_ptr.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"

#include "3party/pugixml/src/pugixml.hpp"

class Reader;

namespace editor
{
struct TypeAggregatedDescription
{
  using EType = feature::Metadata::EType;
  using TFeatureFields = vector<EType>;

  bool IsEmpty() const
  {
    return IsNameEditable() || IsAddressEditable() || !m_editableFields.empty();
  }

  TFeatureFields const & GetEditableFields() const { return m_editableFields; }

  bool IsNameEditable() const { return m_name; }
  bool IsAddressEditable() const { return m_address; }

  TFeatureFields m_editableFields;

  bool m_name = false;
  bool m_address = false;
};

class EditorConfig
{
public:
  EditorConfig() = default;

  // TODO(mgsergio): Reduce overhead by matching uint32_t types instead of strings.
  bool GetTypeDescription(vector<string> classificatorTypes,
                          TypeAggregatedDescription & outDesc) const;
  vector<string> GetTypesThatCanBeAdded() const;

  void SetConfig(pugi::xml_document const & doc);

  // TODO(mgsergio): Implement this getter to avoid hard-code in XMLFeature::ApplyPatch.
  // It should return [[phone, contact:phone], [website, contact:website, url], ...].
  //vector<vector<string>> GetAlternativeFields() const;

private:
  pugi::xml_document m_document;
};

// Class which provides methods for EditorConfig concurrently using.
class EditorConfigWrapper
{
public:
  EditorConfigWrapper() = default;

  void Set(shared_ptr<EditorConfig> config)
  {
    lock_guard<mutex> lock(m_mu);
    m_config = config;
  }

  shared_ptr<EditorConfig const> Get() const
  {
    lock_guard<mutex> lock(m_mu);
    return m_config;
  }

private:
  // It's possible to use atomic_{load|store} here instead of mutex,
  // but seems that libstdc++4.9 doesn't support it. Need to rewrite
  // this code as soon as libstdc++5 will be ready for lastest Debian
  // release, or as soon as atomic_shared_ptr will be ready.
  mutable mutex m_mu;
  shared_ptr<EditorConfig> m_config = make_shared<EditorConfig>();

  // Just in case someone tryes to pass EditorConfigWrapper by value instead of referense.
  DISALLOW_COPY_AND_MOVE(EditorConfigWrapper);
};
}  // namespace editor