• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
IsAllSharedLibsAllowed()44   bool IsAllSharedLibsAllowed() const {
45     return allow_all_shared_libs_;
46   }
47 
48   // accessors
Empty()49   bool Empty() const {
50     return !allow_all_shared_libs_ && shared_libs_.empty();
51   }
GetSharedLibs()52   std::vector<std::string> GetSharedLibs() const {
53     return shared_libs_;
54   }
To()55   std::string To() const {
56     return target_namespace_;
57   }
58 
59  private:
60   const std::string origin_namespace_;
61   const std::string target_namespace_;
62   std::vector<std::string> shared_libs_;
63   bool allow_all_shared_libs_;
64 };
65 
66 template <typename... Args>
AddSharedLib(const std::string & lib_name,Args &&...lib_names)67 void Link::AddSharedLib(const std::string& lib_name, Args&&... lib_names) {
68   if (!allow_all_shared_libs_) {
69     shared_libs_.push_back(lib_name);
70     if constexpr (sizeof...(Args) > 0) {
71       AddSharedLib(std::forward<Args>(lib_names)...);
72     }
73   }
74 }
75 }  // namespace modules
76 }  // namespace linkerconfig
77 }  // namespace android
78