object.hh (12950:af1f0b5e8dfb) object.hh (12955:9c8bf6a5f2e3)
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_CORE_OBJECT_HH__
31#define __SYSTEMC_CORE_OBJECT_HH__
32
33#include <string>
34#include <vector>
35
36#include "systemc/ext/core/sc_attr.hh"
37#include "systemc/ext/core/sc_object.hh"
38
39namespace sc_gem5
40{
41
42class Object;
43
44typedef std::vector<sc_core::sc_object *> Objects;
45typedef std::vector<sc_core::sc_event *> Events;
46typedef Objects::iterator ObjectsIt;
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_CORE_OBJECT_HH__
31#define __SYSTEMC_CORE_OBJECT_HH__
32
33#include <string>
34#include <vector>
35
36#include "systemc/ext/core/sc_attr.hh"
37#include "systemc/ext/core/sc_object.hh"
38
39namespace sc_gem5
40{
41
42class Object;
43
44typedef std::vector<sc_core::sc_object *> Objects;
45typedef std::vector<sc_core::sc_event *> Events;
46typedef Objects::iterator ObjectsIt;
47typedef Events::iterator EventsIt;
47
48class Object
49{
50 public:
48
49class Object
50{
51 public:
51 Object(sc_core::sc_object *sc_obj);
52 Object(sc_core::sc_object *sc_obj, const char *);
53 Object(sc_core::sc_object *sc_obj, const Object &);
52 Object(sc_core::sc_object *_sc_obj);
53 Object(sc_core::sc_object *_sc_obj, const char *);
54 Object(sc_core::sc_object *_sc_obj, const Object &);
54 Object &operator = (const Object &);
55
56 virtual ~Object();
57
58 /*
59 * sc_object methods.
60 */
61 const char *name() const;
62 const char *basename() const;
63
64 void print(std::ostream & =std::cout) const;
65 void dump(std::ostream & =std::cout) const;
66
67 const std::vector<sc_core::sc_object *> &get_child_objects() const;
68 const std::vector<sc_core::sc_event *> &get_child_events() const;
69 sc_core::sc_object *get_parent_object() const;
70
71 bool add_attribute(sc_core::sc_attr_base &);
72 sc_core::sc_attr_base *get_attribute(const std::string &);
73 sc_core::sc_attr_base *remove_attribute(const std::string &);
74 void remove_all_attributes();
75 int num_attributes() const;
76 sc_core::sc_attr_cltn &attr_cltn();
77 const sc_core::sc_attr_cltn &attr_cltn() const;
78
79 sc_core::sc_simcontext *simcontext() const;
80
55 Object &operator = (const Object &);
56
57 virtual ~Object();
58
59 /*
60 * sc_object methods.
61 */
62 const char *name() const;
63 const char *basename() const;
64
65 void print(std::ostream & =std::cout) const;
66 void dump(std::ostream & =std::cout) const;
67
68 const std::vector<sc_core::sc_object *> &get_child_objects() const;
69 const std::vector<sc_core::sc_event *> &get_child_events() const;
70 sc_core::sc_object *get_parent_object() const;
71
72 bool add_attribute(sc_core::sc_attr_base &);
73 sc_core::sc_attr_base *get_attribute(const std::string &);
74 sc_core::sc_attr_base *remove_attribute(const std::string &);
75 void remove_all_attributes();
76 int num_attributes() const;
77 sc_core::sc_attr_cltn &attr_cltn();
78 const sc_core::sc_attr_cltn &attr_cltn() const;
79
80 sc_core::sc_simcontext *simcontext() const;
81
82 static Object *
83 getFromScObject(sc_core::sc_object *sc_obj)
84 {
85 return sc_obj->_gem5_object;
86 }
87
88 sc_core::sc_object *sc_obj() { return _sc_obj; }
89
90 EventsIt addChildEvent(sc_core::sc_event *e);
91 void delChildEvent(EventsIt it);
92
81 private:
93 private:
82 sc_core::sc_object *sc_obj;
94 sc_core::sc_object *_sc_obj;
83
84 std::string _basename;
85 std::string _name;
86
87 Objects children;
88 Events events;
89 sc_core::sc_object *parent;
90 ObjectsIt parentIt;
91
92 sc_core::sc_attr_cltn cltn;
93};
94
95extern Objects topLevelObjects;
96extern Objects allObjects;
97
98sc_core::sc_object *findObject(
99 const char *name, const Objects &objects=topLevelObjects);
100
101} // namespace sc_gem5
102
103#endif //__SYSTEMC_CORE_OBJECT_HH__
95
96 std::string _basename;
97 std::string _name;
98
99 Objects children;
100 Events events;
101 sc_core::sc_object *parent;
102 ObjectsIt parentIt;
103
104 sc_core::sc_attr_cltn cltn;
105};
106
107extern Objects topLevelObjects;
108extern Objects allObjects;
109
110sc_core::sc_object *findObject(
111 const char *name, const Objects &objects=topLevelObjects);
112
113} // namespace sc_gem5
114
115#endif //__SYSTEMC_CORE_OBJECT_HH__