1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #pragma once
17
18 #include <string>
19 #include <utility>
20 #include <vector>
21
22 #include "linkerconfig/configwriter.h"
23
24 namespace android {
25 namespace linkerconfig {
26 namespace modules {
27 class Link {
28 public:
Link(std::string origin_namespace,std::string target_namespace)29 Link(std::string origin_namespace, std::string target_namespace)
30 : origin_namespace_(std::move(origin_namespace)),
31 target_namespace_(std::move(target_namespace)) {
32 allow_all_shared_libs_ = false;
33 }
34 Link(const Link&) = delete;
35 Link(Link&&) = default;
36 Link& operator=(Link&&) = default;
37
38 template <typename... Args>
39 void AddSharedLib(const std::string& lib_name, Args&&... lib_names);
40 void AddSharedLib(const std::vector<std::string>& lib_names);
41 void AllowAllSharedLibs();
42 void WriteConfig(ConfigWriter& writer) const;
43
44 // accessors
GetSharedLibs()45 std::vector<std::string> GetSharedLibs() const {
46 return shared_libs_;
47 }
To()48 std::string To() const {
49 return target_namespace_;
50 }
51
52 private:
53 const std::string origin_namespace_;
54 const std::string target_namespace_;
55 std::vector<std::string> shared_libs_;
56 bool allow_all_shared_libs_;
57 };
58
59 template <typename... Args>
AddSharedLib(const std::string & lib_name,Args &&...lib_names)60 void Link::AddSharedLib(const std::string& lib_name, Args&&... lib_names) {
61 if (!allow_all_shared_libs_) {
62 shared_libs_.push_back(lib_name);
63 if constexpr (sizeof...(Args) > 0) {
64 AddSharedLib(std::forward<Args>(lib_names)...);
65 }
66 }
67 }
68 } // namespace modules
69 } // namespace linkerconfig
70 } // namespace android
71