SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
inject_base.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2017 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_SYSTEMC_INJECTION_INJECT_BASE_H
17#define SIMICS_SYSTEMC_INJECTION_INJECT_BASE_H
18
19
20
23
24#include <tlm>
25
26#include <string>
27
28namespace simics {
29namespace systemc {
30namespace injection {
31
32#define INJECT_SET_VALUE(setter, type, extension) \
33 if (key == #setter) { \
34 type v = 0; \
35 \
36 if (!parser->value(&v)) { \
37 return false; \
38 } \
39 this->template get_extension<extension>(gp)->setter(v); \
40 return true; \
41 }
42
44template <typename TPAYLOAD>
45class InjectBase : public Registrant<InjectInterface<TPAYLOAD> > {
46 public:
47 InjectBase() : gp_(NULL) {}
48 virtual ~InjectBase() {}
49 virtual bool setValue(AttrDictParser *parser, const std::string &key,
50 attr_value_t *attr, TPAYLOAD *gp) = 0;
51 virtual void attrToValue(AttrDictParser *parser, TPAYLOAD *gp) {
52 gp_ = gp;
53 parser->parse(this);
54 }
55 virtual void released(TPAYLOAD *gp) {}
56 virtual bool parse(AttrDictParser *parser, const std::string &key,
57 attr_value_t *attr) {
58 return setValue(parser, key, attr, gp_);
59 }
60 template<typename T>
61 T *get_extension(TPAYLOAD *gp) {
62 T *t = gp->template get_extension<T>();
63 if (t)
64 return t;
65
66 // The created extension is deleted in the InjectRegistry when the
67 // GP is deleted.
68 gp->set_extension(new T);
69 return gp->template get_extension<T>();
70 }
71
72 private:
73 TPAYLOAD *gp_;
74};
75
76} // namespace injection
77} // namespace systemc
78} // namespace simics
79
80#endif
Definition: registry.h:88
Definition: attr_dict_parser.h:40
bool parse(ParserInterface *parser)
Definition: inject_base.h:45
virtual void attrToValue(AttrDictParser *parser, TPAYLOAD *gp)
Definition: inject_base.h:51
virtual void released(TPAYLOAD *gp)
Definition: inject_base.h:55
virtual bool parse(AttrDictParser *parser, const std::string &key, attr_value_t *attr)
Definition: inject_base.h:56
virtual bool setValue(AttrDictParser *parser, const std::string &key, attr_value_t *attr, TPAYLOAD *gp)=0
InjectBase()
Definition: inject_base.h:47
virtual ~InjectBase()
Definition: inject_base.h:48
T * get_extension(TPAYLOAD *gp)
Definition: inject_base.h:61
Definition: pci_bus_interface.h:24