sc_event.hh revision 12924:f74f34bd41ce
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_EXT_CORE_SC_EVENT_HH__
31#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
32
33#include <vector>
34
35#include "sc_time.hh"
36
37namespace sc_core
38{
39
40class sc_event;
41class sc_event_and_expr;
42class sc_event_or_expr;
43class sc_interface;
44class sc_object;
45class sc_port_base;
46
47class sc_event_finder
48{
49  protected:
50    void warn_unimpl(const char *func) const;
51
52  public:
53    // Should be "implementation defined" but used in the tests.
54    virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
55};
56
57template <class IF>
58class sc_event_finder_t : public sc_event_finder
59{
60  public:
61    sc_event_finder_t(const sc_port_base &,
62                      const sc_event & (IF::*event_method)() const)
63    {
64        warn_unimpl(__PRETTY_FUNCTION__);
65    }
66
67    const sc_event &
68    find_event(sc_interface *if_p=NULL) const override
69    {
70        warn_unimpl(__PRETTY_FUNCTION__);
71        return *(const sc_event *)nullptr;
72    }
73};
74
75class sc_event_and_list
76{
77  public:
78    sc_event_and_list();
79    sc_event_and_list(const sc_event_and_list &);
80    sc_event_and_list(const sc_event &);
81    sc_event_and_list &operator = (const sc_event_and_list &);
82
83    int size() const;
84    void swap(sc_event_and_list &);
85
86    sc_event_and_list &operator &= (const sc_event &);
87    sc_event_and_list &operator &= (const sc_event_and_list &);
88
89    sc_event_and_expr operator & (const sc_event &) const;
90    sc_event_and_expr operator & (const sc_event_and_list &);
91};
92
93class sc_event_or_list
94{
95  public:
96    sc_event_or_list();
97    sc_event_or_list(const sc_event_or_list &);
98    sc_event_or_list(const sc_event &);
99    sc_event_or_list& operator = (const sc_event_or_list &);
100    ~sc_event_or_list();
101
102    int size() const;
103    void swap(sc_event_or_list &);
104
105    sc_event_or_list &operator |= (const sc_event &);
106    sc_event_or_list &operator |= (const sc_event_or_list &);
107
108    sc_event_or_expr operator | (const sc_event &) const;
109    sc_event_or_expr operator | (const sc_event_or_list &) const;
110};
111
112class sc_event_and_expr
113{
114  public:
115    operator const sc_event_and_list &() const;
116};
117
118sc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
119sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
120
121class sc_event_or_expr
122{
123  public:
124    operator const sc_event_or_list &() const;
125};
126
127sc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
128sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
129
130class sc_event
131{
132  public:
133    sc_event();
134    explicit sc_event(const char *);
135    ~sc_event();
136
137    const char *name() const;
138    const char *basename() const;
139    bool in_hierarchy() const;
140    sc_object *get_parent_object() const;
141
142    void notify();
143    void notify(const sc_time &);
144    void notify(double, sc_time_unit);
145    void cancel();
146
147    // Nonstandard
148    // Returns whether this event is currently triggered.
149    bool triggered() const;
150
151    // Deprecated
152    void notify_delayed();
153    void notify_delayed(const sc_time &);
154
155    sc_event_and_expr operator & (const sc_event &) const;
156    sc_event_and_expr operator & (const sc_event_and_list &) const;
157    sc_event_or_expr operator | (const sc_event &) const;
158    sc_event_or_expr operator | (const sc_event_or_list &) const;
159
160  private:
161    // Disabled
162    sc_event(const sc_event &) {}
163    sc_event &operator = (const sc_event &) { return *this; }
164};
165
166const std::vector<sc_event *> &sc_get_top_level_events();
167sc_event *sc_find_event(const char *);
168
169} // namespace sc_core
170
171#endif  //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
172