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/utility.h" // array_index
24
25namespace simics {
26
44template <typename TParent>
45class Port : public ConfObject {
46 public:
47 using ParentType = TParent;
48
49 explicit Port(const ConfObjectRef &obj)
50 : ConfObject(obj) {
51 if (obj.object() == nullptr) {
52 throw std::invalid_argument(
53 "ConfObjectRef passed to Port constructor is null");
54 }
55
56 parent_ = from_obj<ParentType>(parent_conf_obj());
57 name_ = obj.name().substr(
58 strlen(SIM_object_name(parent_conf_obj())) + 1);
59 index_ = array_index(name_);
60 }
61 virtual ~Port() = default;
62
65 ParentType *parent() const {
66 return parent_;
67 }
68
70 const std::string &name() const {
71 return name_;
72 }
73
76 int index() const {
77 return index_;
78 }
79
80 private:
82 conf_object_t *parent_conf_obj() {
83 auto p = SIM_port_object_parent(obj());
84 if (p == nullptr) {
85 throw std::runtime_error {
86 "The object " + obj().name() + " is not a port object"
87 };
88 }
89 return p;
90 }
91
93 TParent *parent_ {nullptr};
95 std::string name_ {""};
97 int index_ {-1};
98};
99
100} // namespace simics
101
102#endif
Represents Simics C type conf_object_t.
Definition: conf-object.h:38
conf_object_t * object() const
Get a pointer to the configuration object represented by this ConfObjectRef.
Definition: conf-object.h:54
std::string name() const
Get the name of the underlying configuration object.
Base class for all Simics configuration objects.
Definition: conf-object.h:126
ConfObjectRef obj() const
Return a ConfObjectRef represents this object.
Definition: conf-object.h:137
Extends ConfObject to add utilities to a Simics port object.
Definition: port.h:45
TParent ParentType
Definition: port.h:47
Port(const ConfObjectRef &obj)
Definition: port.h:49
int index() const
Definition: port.h:76
const std::string & name() const
Definition: port.h:70
ParentType * parent() const
Definition: port.h:65
virtual ~Port()=default
Definition: after-bank.h:33
int array_index(const std::string &name)
This function looks for a pattern in the input string that resembles an array index,...