forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatalog.cc
62 lines (49 loc) · 1.79 KB
/
catalog.cc
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
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/service_manager/catalog.h"
#include <vector>
namespace service_manager {
namespace {
std::map<Manifest::ServiceName, const Manifest*> CreateManifestMap(
const std::vector<Manifest>& manifests) {
std::map<Manifest::ServiceName, const Manifest*> map;
for (const auto& manifest : manifests) {
map[manifest.service_name] = &manifest;
for (const auto& entry : CreateManifestMap(manifest.packaged_services))
map[entry.first] = entry.second;
}
return map;
}
std::map<Manifest::ServiceName, const Manifest*> CreateParentManifestMap(
const std::vector<Manifest>& manifests) {
std::map<Manifest::ServiceName, const Manifest*> map;
for (const auto& parent : manifests) {
for (const auto& child : parent.packaged_services)
map[child.service_name] = &parent;
for (const auto& entry : CreateParentManifestMap(parent.packaged_services))
map[entry.first] = entry.second;
}
return map;
}
} // namespace
Catalog::Catalog(const std::vector<Manifest>& manifests)
: manifests_(manifests),
manifest_map_(CreateManifestMap(manifests_)),
parent_manifest_map_(CreateParentManifestMap(manifests_)) {}
Catalog::~Catalog() = default;
const Manifest* Catalog::GetManifest(
const Manifest::ServiceName& service_name) {
const auto it = manifest_map_.find(service_name);
if (it == manifest_map_.end())
return nullptr;
return it->second;
}
const Manifest* Catalog::GetParentManifest(
const Manifest::ServiceName& service_name) {
auto it = parent_manifest_map_.find(service_name);
if (it == parent_manifest_map_.end())
return nullptr;
return it->second;
}
} // namespace service_manager