DPsim
PtrFactory.h
1 /* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #pragma once
10 
11 #include <memory>
12 #include <utility>
13 
16 template <typename T> class SharedFactory {
17 
18 public:
19  template <typename... Args> static std::shared_ptr<T> make(Args &&...args) {
20  return std::shared_ptr<T>(new T(std::forward<Args>(args)...));
21  }
22 };
23 
24 template <typename T> class UniqueFactory {
25 
26 public:
27  template <typename... Args> static std::unique_ptr<T> make(Args &&...args) {
28  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
29  }
30 };