SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_list.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_list.h -- Simple implementation of a doubly linked list.
23
24 Original Author: Stan Y. Liao, Synopsys, Inc.
25
26 CHANGE LOG AT END OF FILE
27 *****************************************************************************/
28
29
30#ifndef SC_LIST_H
31#define SC_LIST_H
32
34
35namespace sc_core {
36
37//Some forward declarations
38class sc_plist_elem;
39template<class T> class sc_plist_iter;
40
41typedef void (*sc_plist_map_fn)( void* data, void* arg );
42
44 friend class sc_plist_base_iter;
45
46public:
49
50 typedef sc_plist_elem* handle_t;
51
54 void* pop_back();
55 void* pop_front();
58 void* remove(handle_t h);
59 void* get(handle_t h) const;
60 void set(handle_t h, void* d);
61 void mapcar( sc_plist_map_fn f, void* arg );
62
63 void* front() const;
64 void* back() const;
65
66 void erase_all();
67 bool empty() const { return (head == 0); }
68 int size() const;
69
70private:
71 handle_t head;
72 handle_t tail;
73};
74
75
77public:
78 typedef sc_plist_elem* handle_t;
79
80 sc_plist_base_iter( sc_plist_base* l, bool from_tail = false );
82
83 void reset( sc_plist_base* l, bool from_tail = false );
84 bool empty() const;
85 void operator++(int);
86 void operator--(int);
87 void* get() const;
88 void set(void* d);
89 void remove();
90 void remove(int direction);
91
93 handle_t get_handle() const { return ptr; }
94
95private:
96 sc_plist_base* lst;
97 sc_plist_elem* ptr;
98};
99
100/*---------------------------------------------------------------------------*/
101
102template< class T >
103class sc_plist : public sc_plist_base {
104 friend class sc_plist_iter <T>;
105
106public:
108
109 sc_plist() { }
111
112 handle_t push_back(T d) { return sc_plist_base::push_back((void*)d); }
114 T pop_back() { return (T) sc_plist_base::pop_back(); }
117 {
118 return sc_plist_base::insert_before(h, (void*) d);
119 }
121 {
122 return sc_plist_base::insert_after(h, (void*) d);
123 }
125 {
126 return (T)sc_plist_base::remove(h);
127 }
128 T get(handle_t h) const { return (T)sc_plist_base::get(h); }
129 void set(handle_t h, T d) { sc_plist_base::set(h, (void*)d); }
130
131 T front() const { return (T)sc_plist_base::front(); }
132 T back() const { return (T)sc_plist_base::back(); }
133};
134
135template< class T >
137public:
138 sc_plist_iter( sc_plist<T>* l, bool from_tail = false )
139 : sc_plist_base_iter( l, from_tail )
140 {
141
142 }
143 sc_plist_iter( sc_plist<T>& l, bool from_tail = false )
144 : sc_plist_base_iter( &l, from_tail )
145 {
146
147 }
149 {
150
151 }
152
153 void reset( sc_plist<T>* l, bool from_tail = false )
154 {
155 sc_plist_base_iter::reset( l, from_tail );
156 }
157 void reset( sc_plist<T>& l, bool from_tail = false )
158 {
159 sc_plist_base_iter::reset( &l, from_tail );
160 }
161
162 T operator*() const { return (T) sc_plist_base_iter::get(); }
163 T get() const { return (T) sc_plist_base_iter::get(); }
164 void set(T d) { sc_plist_base_iter::set((void*) d); }
165};
166
167} // namespace sc_core
168
169// $Log: sc_list.h,v $
170// Revision 1.5 2011/09/01 15:16:50 acg
171// Philipp A. Hartmann: revert unnecessary virtual destructors.
172//
173// Revision 1.4 2011/08/26 20:46:18 acg
174// Andy Goodrich: moved the modification log to the end of the file to
175// eliminate source line number skew when check-ins are done.
176//
177// Revision 1.3 2011/08/24 22:05:56 acg
178// Torsten Maehne: initialization changes to remove warnings.
179//
180// Revision 1.2 2011/02/18 20:38:44 acg
181// Andy Goodrich: Updated Copyright notice.
182//
183// Revision 1.1.1.1 2006/12/15 20:20:06 acg
184// SystemC 2.3
185//
186// Revision 1.3 2006/01/13 18:53:10 acg
187// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
188// the source.
189
190#endif
#define SC_API
Definition: sc_cmnhdr.h:148
void(* sc_plist_map_fn)(void *data, void *arg)
Definition: sc_list.h:41
void set(handle_t h, T d)
Definition: sc_list.h:129
T back() const
Definition: sc_list.h:132
handle_t insert_before(handle_t h, T d)
Definition: sc_list.h:116
handle_t insert_after(handle_t h, T d)
Definition: sc_list.h:120
T get(handle_t h) const
Definition: sc_list.h:128
handle_t push_back(T d)
Definition: sc_list.h:112
handle_t push_front(T d)
Definition: sc_list.h:113
T remove(handle_t h)
Definition: sc_list.h:124
sc_plist_iter< T > iterator
Definition: sc_list.h:107
T front() const
Definition: sc_list.h:131
T operator*() const
Definition: sc_list.h:162
sc_plist_iter(sc_plist< T > &l, bool from_tail=false)
Definition: sc_list.h:143
void reset(sc_plist< T > &l, bool from_tail=false)
Definition: sc_list.h:157
void reset(sc_plist< T > *l, bool from_tail=false)
Definition: sc_list.h:153
sc_plist_iter(sc_plist< T > *l, bool from_tail=false)
Definition: sc_list.h:138
handle_t insert_after(handle_t h, void *d)
sc_plist_elem * handle_t
Definition: sc_list.h:50
handle_t push_back(void *d)
handle_t insert_before(handle_t h, void *d)
void * get(handle_t h) const
void mapcar(sc_plist_map_fn f, void *arg)
void * back() const
handle_t push_front(void *d)
void * front() const
void set(handle_t h, void *d)
bool empty() const
Definition: sc_list.h:67
void * remove(handle_t h)
sc_plist_base_iter(sc_plist_base *l, bool from_tail=false)
void set_handle(handle_t h)
void reset(sc_plist_base *l, bool from_tail=false)
sc_plist_elem * handle_t
Definition: sc_list.h:78
void remove(int direction)
handle_t get_handle() const
Definition: sc_list.h:93