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#include <string>
22#include <cassert>
23#include <unordered_map>
24#include <stdexcept>
25
27
28namespace simics {
29
30class ConfObject;
31
38 public:
46 ConfObjectRef(conf_object_t *obj = nullptr) // NOLINT(runtime/explicit)
47 : o_(obj) {}
48 virtual ~ConfObjectRef() = default;
49
50 bool operator==(const ConfObjectRef &other) const {
51 return o_ == other.object() && port_name() == other.port_name();
52 }
53
55
57 conf_object_t *object() const { return o_; }
58 operator conf_object_t *() const { return o_; }
60
62
63 const std::string &port_name() const { return port_name_; }
64 void set_port_name(const std::string &name) { port_name_ = name; }
66
68 void *data() const;
69
71 const std::string &name() const;
72
75 void require() const;
76
80 bool configured() const;
81
85
88
98 const interface_t *get_interface(const std::string &name) const;
99
100 uint64 group_id(const std::string &name) const;
101
102 private:
103 conf_object_t *o_;
105 std::string port_name_;
108 mutable std::string name_;
109};
110
116 template <typename IFACE>
117 friend IFACE* get_interface(conf_object_t *obj);
119
120 public:
122 explicit ConfObject(const ConfObjectRef &obj) : obj_(obj) {
123 init_log_groups();
124 }
125 virtual ~ConfObject() = default;
126
127 friend class ConfObjectRef;
128
129 // iface::ConfObjectInterface
130 void finalize() override {}
131 void objects_finalized() override {}
132
134 ConfObjectRef obj() const { return obj_; }
135
137 virtual bool finalized() {
138 return SIM_object_is_configured(obj_);
139 }
140
141 private:
142 void init_log_groups();
143
144 ConfObjectRef obj_;
145 std::unordered_map<std::string, uint64> groups_;
146};
147
150template <typename T> inline
152 static_assert(std::is_base_of<ConfObject, T>::value,
153 "type T is not derived from type ConfObject");
154 void *d = SIM_object_data(obj);
155 assert(d);
156 // for performance reason, downcast by static_cast here
157 // it should be safe with the above static_assert
158 return static_cast<T*>(d);
159}
160
161} // namespace simics
162#endif
struct conf_object conf_object_t
Definition: bank-issue-callbacks-interface.h:23
Represents Simics C type conf_object_t.
Definition: conf-object.h:37
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:57
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(...
const interface_t * get_interface(const std::string &name) const
Return an interface implemented by the underlying configuration object.
virtual ~ConfObjectRef()=default
const std::string & name() const
Get the name of the underlying configuration object.
ConfObjectRef(conf_object_t *obj=nullptr)
Not explicit constructor, allow conversion of conf_object_t to ConfObjectRef.
Definition: conf-object.h:46
const std::string & port_name() const
Get & set name for the port implements the interface.
Definition: conf-object.h:63
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:64
bool operator==(const ConfObjectRef &other) const
Definition: conf-object.h:50
A class inherited by a model class to support Simics configuration.
Definition: conf-object.h:114
ConfObject(const ConfObjectRef &obj)
Create a ConfObject from ConfObjectRef.
Definition: conf-object.h:122
virtual ~ConfObject()=default
void objects_finalized() override
Definition: conf-object.h:131
virtual bool finalized()
Return if the finalize method has been called.
Definition: conf-object.h:137
void finalize() override
Definition: conf-object.h:130
ConfObjectRef obj() const
Return a ConfObjectRef represents this object.
Definition: conf-object.h:134
Abstract C++ interface contains methods for register model defined behavior after the construction an...
Definition: conf-object-interface.h:26
void interface_t
Definition: interface-info.h:22
Definition: attr-value.h:23
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:151
IFACE * get_interface(conf_object_t *obj)
Return the Simics C++ interface class from a configuration object.
Definition: utility.h:27