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