• 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 <map>
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "linkerconfig/configwriter.h"
25 #include "linkerconfig/namespace.h"
26 
27 namespace android {
28 namespace linkerconfig {
29 namespace modules {
30 class Section {
31  public:
Section(const std::string & name)32   Section(const std::string& name) : name_(name) {
33   }
34   template <typename T, typename... Args>
35   void AddBinaryPath(T&& binary_path, Args&&... binary_paths);
36   std::shared_ptr<Namespace> CreateNamespace(const std::string& namespace_name,
37                                              bool is_isolated = false,
38                                              bool is_visible = false);
39   void WriteConfig(ConfigWriter& writer);
40   void WriteBinaryPaths(ConfigWriter& writer);
41   std::string GetName();
42 
43  private:
44   const std::string name_;
45   std::vector<std::string> binary_paths_;
46   std::map<std::string, std::shared_ptr<Namespace>> namespaces_;
47 };
48 
49 template <typename T, typename... Args>
AddBinaryPath(T && binary_path,Args &&...binary_paths)50 void Section::AddBinaryPath(T&& binary_path, Args&&... binary_paths) {
51   binary_paths_.push_back(std::forward<T>(binary_path));
52   if constexpr (sizeof...(Args) > 0) {
53     AddBinaryPath(std::forward<Args>(binary_paths)...);
54   }
55 }
56 }  // namespace modules
57 }  // namespace linkerconfig
58 }  // namespace android