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/*
2 © 2017 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_INJECTION_INJECT_BASE_H
15#define SIMICS_SYSTEMC_INJECTION_INJECT_BASE_H
16
17
18
21
22#include <tlm>
23
24#include <string>
25
26namespace simics {
27namespace systemc {
28namespace injection {
29
30#define INJECT_SET_VALUE(setter, type, extension) \
31 if (key == #setter) { \
32 type v = 0; \
33 \
34 if (!parser->value(&v)) { \
35 return false; \
36 } \
37 this->template get_extension<extension>(gp)->setter(v); \
38 return true; \
39 }
40
42template <typename TPAYLOAD>
43class InjectBase : public Registrant<InjectInterface<TPAYLOAD> > {
44 public:
45 InjectBase() : gp_(NULL) {}
46 virtual ~InjectBase() {}
47 virtual bool setValue(AttrDictParser *parser, const std::string &key,
48 attr_value_t *attr, TPAYLOAD *gp) = 0;
49 void attrToValue(AttrDictParser *parser, TPAYLOAD *gp) override {
50 gp_ = gp;
51 parser->parse(this);
52 }
53 void released(TPAYLOAD *gp) override {}
54 bool parse(AttrDictParser *parser, const std::string &key,
55 attr_value_t *attr) override {
56 return setValue(parser, key, attr, gp_);
57 }
58 template<typename T>
59 T *get_extension(TPAYLOAD *gp) {
60 T *t = gp->template get_extension<T>();
61 if (t)
62 return t;
63
64 // The created extension is deleted in the InjectRegistry when the
65 // GP is deleted.
66 gp->set_extension(new T);
67 return gp->template get_extension<T>();
68 }
69
70 private:
71 TPAYLOAD *gp_;
72};
73
74} // namespace injection
75} // namespace systemc
76} // namespace simics
77
78#endif
Definition: registry.h:86
Definition: attr_dict_parser.h:38
bool parse(ParserInterface *parser)
Definition: inject_base.h:43
virtual bool setValue(AttrDictParser *parser, const std::string &key, attr_value_t *attr, TPAYLOAD *gp)=0
InjectBase()
Definition: inject_base.h:45
void released(TPAYLOAD *gp) override
Definition: inject_base.h:53
void attrToValue(AttrDictParser *parser, TPAYLOAD *gp) override
Definition: inject_base.h:49
virtual ~InjectBase()
Definition: inject_base.h:46
T * get_extension(TPAYLOAD *gp)
Definition: inject_base.h:59
bool parse(AttrDictParser *parser, const std::string &key, attr_value_t *attr) override
Definition: inject_base.h:54
Definition: adapter.h:79