C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
conf-object.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_CONF_OBJECT_H
17#define SIMICS_CONF_OBJECT_H
18
19#include <simics/base/conf-object.h>
20#include <simics/simulator/conf-object.h>
21
22#include <cassert>
23#include <stdexcept>
24#include <string>
25#include <unordered_map>
26
28
29namespace simics {
30
31class ConfObject;
32
39 public:
47 ConfObjectRef(conf_object_t *obj = nullptr) // NOLINT(runtime/explicit)
48 : o_(obj) {}
49 virtual ~ConfObjectRef() = default;
50
52
54 conf_object_t *object() const { return o_; }
55 operator conf_object_t *() const { return o_; }
57
59
60 const std::string &port_name() const { return port_name_; }
61 void set_port_name(const std::string &name) { port_name_ = name; }
63
65 void *data() const;
66
68 std::string name() const;
69
72 void require() const;
73
77 bool configured() const;
78
81 conf_object_t *port_obj_parent() const;
82
85
95 const interface_t *get_interface(const std::string &name) const;
96
97 [[deprecated("Use GROUP_ID or ConfClass::getGroupId instead")]]
98 uint64 group_id(const std::string &name) const;
99
100 private:
101 conf_object_t *o_ {nullptr};
103 std::string port_name_;
104};
105
112bool operator==(const ConfObjectRef &lhs, const ConfObjectRef &rhs);
113bool operator!=(const ConfObjectRef &lhs, const ConfObjectRef &rhs);
114
127 public:
129 explicit ConfObject(const ConfObjectRef &obj) : obj_(obj) {}
130 virtual ~ConfObject() = default;
131
132 // iface::ConfObjectInterface
133 void finalize() override {}
134 void objects_finalized() override {}
135
137 ConfObjectRef obj() const { return obj_; }
138
140 virtual bool finalized() {
141 return SIM_object_is_configured(obj_);
142 }
143
144 private:
145#if defined INTC_EXT
146 [[deprecated("Dead function to maintain ABI compatibility with "
147 "Simics Base version 6.0.215")]]
148 void init_log_groups();
149#endif
150
151 ConfObjectRef obj_;
152#if defined INTC_EXT
153 std::unordered_map<std::string, uint64> groups_;
154#endif
155};
156
168template <typename T> inline
169T *from_obj(conf_object_t *obj) {
170 static_assert(std::is_base_of<ConfObject, T>::value,
171 "type T is not derived from type ConfObject");
172 auto *d = static_cast<ConfObject *>(SIM_object_data(obj));
173 assert(d);
174 return static_cast<T*>(d);
175}
176
177} // namespace simics
178#endif
Abstract C++ interface contains methods for register model defined behavior after the construction an...
Definition: conf-object-interface.h:25
Represents Simics C type conf_object_t.
Definition: conf-object.h:38
conf_object_t * port_obj_parent() const
Return the parent object if the object is a port object, nullptr otherwise.
conf_object_t * object() const
Get a pointer to the configuration object represented by this ConfObjectRef.
Definition: conf-object.h:54
bool configured() const
Return true if the configuration object is configured, false otherwise.
void require() const
Ensure that the configuration object is instantiated (this is the same as calling SIM_require_object(...
std::string name() const
Get the name of the underlying configuration object.
const interface_t * get_interface(const std::string &name) const
Return an interface implemented by the underlying configuration object.
virtual ~ConfObjectRef()=default
ConfObjectRef(conf_object_t *obj=nullptr)
Not explicit constructor, allow conversion of conf_object_t to ConfObjectRef.
Definition: conf-object.h:47
const std::string & port_name() const
Get & set name for the port implements the interface.
Definition: conf-object.h:60
uint64 group_id(const std::string &name) const
void * data() const
Get the data of the underlying configuration object.
ConfObject & as_conf_object() const
Get a reference to the associated ConfObject.
void set_port_name(const std::string &name)
Definition: conf-object.h:61
Base class for all Simics configuration objects.
Definition: conf-object.h:126
ConfObject(const ConfObjectRef &obj)
Create a ConfObject from ConfObjectRef.
Definition: conf-object.h:129
virtual ~ConfObject()=default
void objects_finalized() override
Definition: conf-object.h:134
virtual bool finalized()
Return if the finalize method has been called.
Definition: conf-object.h:140
void finalize() override
Definition: conf-object.h:133
ConfObjectRef obj() const
Return a ConfObjectRef represents this object.
Definition: conf-object.h:137
void interface_t
Definition: interface-info.h:22
Definition: after-bank.h:33
T * from_obj(conf_object_t *obj)
Utility function to convert a conf_object_t* to a pointer to C++ class derived from simics::ConfObjec...
Definition: conf-object.h:169
bool operator==(const ConfObjectRef &lhs, const ConfObjectRef &rhs)
Compares two ConfObjectRef objects for equality.
bool operator!=(const ConfObjectRef &lhs, const ConfObjectRef &rhs)