C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
conf-object-util.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2025 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_DETAIL_CONF_OBJECT_UTIL_H
17#define SIMICS_DETAIL_CONF_OBJECT_UTIL_H
18
19#include <stdexcept> // runtime_error
20
21#include "simics/conf-object.h"
22
23namespace simics {
24namespace detail {
25
29template <typename IFACE>
30IFACE* get_interface(conf_object_t *obj) {
31 // See bug 21722, the performance benchmark shows dynamic_cast
32 // is better than cache it by a map
33 auto *iface = dynamic_cast<IFACE*>(from_obj<ConfObject>(obj));
34 if (!iface) {
35 throw std::runtime_error {
36 "The configuration object needs derive from the interface class"
37 };
38 }
39 return iface;
40}
41
42} // namespace detail
43} // namespace simics
44
45#endif
IFACE * get_interface(conf_object_t *obj)
Return the Simics C++ interface class from a configuration object.
Definition: conf-object-util.h:30
Definition: after-bank.h:33