1 /*
2  * Copyright 2018 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 
17 #pragma once
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "model/devices/device.h"
26 
27 namespace rootcanal {
28 
29 // Create customized devices from a centralized shop.
30 class DeviceBoutique {
31  public:
32   DeviceBoutique();
33   virtual ~DeviceBoutique() = default;
34 
35   // Register a constructor for a device type.
36   static bool Register(
37       std::string const& device_type,
38       std::function<std::shared_ptr<Device>(const std::vector<std::string>&)>
39           method);
40 
41   // Call the function that matches arg[0] with args
42   static std::shared_ptr<Device> Create(const std::vector<std::string>& args);
43 
44  private:
45   static std::unordered_map<std::string, std::function<std::shared_ptr<Device>(
46                                              const std::vector<std::string>&)>>&
47   GetMap();
48 };
49 
50 }  // namespace rootcanal
51