C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
object-factory.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2021 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_OBJECT_FACTORY_H
17#define SIMICS_OBJECT_FACTORY_H
18
19#include <type_traits> // is_base_of
20
22#include "simics/conf-object.h"
23
24namespace simics {
25
34template <typename T>
36 public:
37 static_assert(std::is_base_of<ConfObject, T>::value,
38 "T must be ConfObject-derived");
39
40 ObjectFactory() = default;
41
51 ConfObject *create(conf_object_t *obj) const override {
52 return new T(obj);
53 }
54
62 ObjectFactoryInterface *clone() const override {
63 return new ObjectFactory<T>();
64 }
65};
66
77template <typename T, typename A>
79 public:
80 static_assert(std::is_base_of<ConfObject, T>::value,
81 "T must be ConfObject-derived");
82
83 explicit ObjectFactoryWithArg(A *arg): arg_(arg) {}
84
94 ConfObject *create(conf_object_t *obj) const override {
95 return new T(obj, arg_);
96 }
97
105 ObjectFactoryInterface *clone() const override {
106 return new ObjectFactoryWithArg(arg_);
107 }
108
109 private:
110 A *arg_;
111};
112
113} // namespace simics
114
115#endif
Base class for all Simics configuration objects.
Definition: conf-object.h:126
Interface for a factory pattern to create ConfObject instances.
Definition: object-factory-interface.h:31
A factory for creating instances of ConfObject-derived classes with an argument.
Definition: object-factory.h:78
ConfObject * create(conf_object_t *obj) const override
Creates an instance of the ConfObject-derived class with an argument.
Definition: object-factory.h:94
ObjectFactoryWithArg(A *arg)
Definition: object-factory.h:83
ObjectFactoryInterface * clone() const override
Clones the current ObjectFactoryWithArg instance.
Definition: object-factory.h:105
A factory for creating instances of ConfObject-derived classes.
Definition: object-factory.h:35
ConfObject * create(conf_object_t *obj) const override
Creates an instance of the ConfObject-derived class.
Definition: object-factory.h:51
ObjectFactoryInterface * clone() const override
Clones the current ObjectFactory instance.
Definition: object-factory.h:62
Definition: after-bank.h:33