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
20
21#include <type_traits> // is_base_of
22
23namespace simics {
24
28template <typename T>
30 public:
32 static_assert(std::is_base_of<ConfObject, T>::value,
33 "T must be a descendant of ConfObject");
34 }
35
37 ConfObject *create(conf_object_t *obj) const override {
38 return new T(obj);
39 }
41 return new ObjectFactory<T>();
42 }
43};
44
48template <typename T, typename A>
50 public:
51 explicit ObjectFactoryWithArg(A *arg)
52 : arg_(arg) {
53 static_assert(std::is_base_of<ConfObject, T>::value,
54 "T must be a descendant of ConfObject");
55 }
56
58 ConfObject *create(conf_object_t *obj) const override {
59 return new T(obj, arg_);
60 }
62 return new ObjectFactoryWithArg(arg_);
63 }
64
65 private:
66 A *arg_;
67};
68
69} // namespace simics
70
71
72#endif
struct conf_object conf_object_t
Definition: bank-issue-callbacks-interface.h:23
A class inherited by a model class to support Simics configuration.
Definition: conf-object.h:114
An object factory creates class T object with argument.
Definition: object-factory.h:49
ConfObject * create(conf_object_t *obj) const override
iface::ObjectFactoryInterface
Definition: object-factory.h:58
ObjectFactoryWithArg(A *arg)
Definition: object-factory.h:51
iface::ObjectFactoryInterface * clone() const override
Definition: object-factory.h:61
An object factory creates class T object.
Definition: object-factory.h:29
ConfObject * create(conf_object_t *obj) const override
iface::ObjectFactoryInterface
Definition: object-factory.h:37
ObjectFactory()
Definition: object-factory.h:31
iface::ObjectFactoryInterface * clone() const override
Definition: object-factory.h:40
Definition: object-factory-interface.h:33
Definition: attr-value.h:23