C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
port.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_PORT_H
17#define SIMICS_PORT_H
18
19#include <stdexcept>
20#include <string>
21
22#include "simics/conf-object.h"
23#include "simics/conf-class.h" // array_index
24
25namespace simics {
26
34template <typename TParent>
35class Port : public ConfObject {
36 public:
37 explicit Port(const ConfObjectRef &obj)
38 : ConfObject(obj),
39 parent_(from_obj<TParent>(parent_conf_obj())),
40 name_(obj.name().substr(
41 strlen(SIM_object_name(parent_conf_obj())) + 1)),
42 index_(array_index(name_)) {}
43 virtual ~Port() = default;
44
47 TParent *parent() const {
48 return parent_;
49 }
50
52 const std::string &name() {
53 return name_;
54 }
55
57 int index() const {
58 return index_;
59 }
60
61 private:
63 conf_object_t *parent_conf_obj() {
64 auto p = SIM_port_object_parent(obj());
65 if (p == nullptr) {
66 throw std::runtime_error {
67 "No parent found for " + obj().name()
68 };
69 }
70 return p;
71 }
72
74 TParent *parent_;
76 std::string name_;
78 int index_;
79};
80
81} // namespace simics
82
83#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
const std::string & name() const
Get the name of the underlying configuration object.
A class inherited by a model class to support Simics configuration.
Definition: conf-object.h:114
ConfObjectRef obj() const
Return a ConfObjectRef represents this object.
Definition: conf-object.h:134
Represents a Simics port object base class.
Definition: port.h:35
TParent * parent() const
Return a pointer to the C++ object associated with the Simics parent object.
Definition: port.h:47
Port(const ConfObjectRef &obj)
Definition: port.h:37
const std::string & name()
Return the port name.
Definition: port.h:52
int index() const
Return the index of an array-type object name.
Definition: port.h:57
virtual ~Port()=default
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
int array_index(const std::string &name)
Return the array index if name is using an array format like array[N].