SystemC  2.3.2
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 */
34 #ifndef SC_LIST_H
35 #define SC_LIST_H
36 
37 #include <sysc/kernel/sc_cmnhdr.h>
38 
39 namespace sc_core {
40 
41 //Some forward declarations
42 class sc_plist_elem;
43 template<class T> class sc_plist_iter;
44 
45 typedef void (*sc_plist_map_fn)( void* data, void* arg );
46 
48  friend class sc_plist_base_iter;
49 
50 public:
51  sc_plist_base();
52  ~sc_plist_base();
53 
54  typedef sc_plist_elem* handle_t;
55 
56  handle_t push_back(void* d);
57  handle_t push_front(void* d);
58  void* pop_back();
59  void* pop_front();
60  handle_t insert_before(handle_t h, void* d);
61  handle_t insert_after(handle_t h, void* d);
62  void* remove(handle_t h);
63  void* get(handle_t h) const;
64  void set(handle_t h, void* d);
65  void mapcar( sc_plist_map_fn f, void* arg );
66 
67  void* front() const;
68  void* back() const;
69 
70  void erase_all();
71  bool empty() const { return (head == 0); }
72  int size() const;
73 
74 private:
75  handle_t head;
76  handle_t tail;
77 };
78 
79 
81 public:
82  typedef sc_plist_elem* handle_t;
83 
84  sc_plist_base_iter( sc_plist_base* l, bool from_tail = false );
86 
87  void reset( sc_plist_base* l, bool from_tail = false );
88  bool empty() const;
89  void operator++(int);
90  void operator--(int);
91  void* get() const;
92  void set(void* d);
93  void remove();
94  void remove(int direction);
95 
96  void set_handle(handle_t h);
97  handle_t get_handle() const { return ptr; }
98 
99 private:
100  sc_plist_base* lst;
101  sc_plist_elem* ptr;
102 };
103 
104 /*---------------------------------------------------------------------------*/
105 
106 template< class T >
107 class sc_plist : public sc_plist_base {
108  friend class sc_plist_iter <T>;
109 
110 public:
112 
113  sc_plist() { }
114  ~sc_plist() { }
115 
116  handle_t push_back(T d) { return sc_plist_base::push_back((void*)d); }
117  handle_t push_front(T d) { return sc_plist_base::push_front((void*)d); }
118  T pop_back() { return (T) sc_plist_base::pop_back(); }
119  T pop_front() { return (T) sc_plist_base::pop_front(); }
121  {
122  return sc_plist_base::insert_before(h, (void*) d);
123  }
125  {
126  return sc_plist_base::insert_after(h, (void*) d);
127  }
128  T remove(handle_t h)
129  {
130  return (T)sc_plist_base::remove(h);
131  }
132  T get(handle_t h) const { return (T)sc_plist_base::get(h); }
133  void set(handle_t h, T d) { sc_plist_base::set(h, (void*)d); }
134 
135  T front() const { return (T)sc_plist_base::front(); }
136  T back() const { return (T)sc_plist_base::back(); }
137 };
138 
139 template< class T >
140 class sc_plist_iter : public sc_plist_base_iter {
141 public:
142  sc_plist_iter( sc_plist<T>* l, bool from_tail = false )
143  : sc_plist_base_iter( l, from_tail )
144  {
145 
146  }
147  sc_plist_iter( sc_plist<T>& l, bool from_tail = false )
148  : sc_plist_base_iter( &l, from_tail )
149  {
150 
151  }
153  {
154 
155  }
156 
157  void reset( sc_plist<T>* l, bool from_tail = false )
158  {
159  sc_plist_base_iter::reset( l, from_tail );
160  }
161  void reset( sc_plist<T>& l, bool from_tail = false )
162  {
163  sc_plist_base_iter::reset( &l, from_tail );
164  }
165 
166  T operator*() const { return (T) sc_plist_base_iter::get(); }
167  T get() const { return (T) sc_plist_base_iter::get(); }
168  void set(T d) { sc_plist_base_iter::set((void*) d); }
169 };
170 
171 } // namespace sc_core
172 
173 // $Log: sc_list.h,v $
174 // Revision 1.5 2011/09/01 15:16:50 acg
175 // Philipp A. Hartmann: revert unnecessary virtual destructors.
176 //
177 // Revision 1.4 2011/08/26 20:46:18 acg
178 // Andy Goodrich: moved the modification log to the end of the file to
179 // eliminate source line number skew when check-ins are done.
180 //
181 // Revision 1.3 2011/08/24 22:05:56 acg
182 // Torsten Maehne: initialization changes to remove warnings.
183 //
184 // Revision 1.2 2011/02/18 20:38:44 acg
185 // Andy Goodrich: Updated Copyright notice.
186 //
187 // Revision 1.1.1.1 2006/12/15 20:20:06 acg
188 // SystemC 2.3
189 //
190 // Revision 1.3 2006/01/13 18:53:10 acg
191 // Andy Goodrich: Added $Log command so that CVS comments are reproduced in
192 // the source.
193 
194 #endif
handle_t push_front(void *d)
bool empty() const
Definition: sc_list.h:71
handle_t get_handle() const
Definition: sc_list.h:97
void set(handle_t h, void *d)
handle_t insert_before(handle_t h, T d)
Definition: sc_list.h:120
void reset(sc_plist< T > &l, bool from_tail=false)
Definition: sc_list.h:161
sc_plist_iter< T > iterator
Definition: sc_list.h:111
T back() const
Definition: sc_list.h:136
void(* sc_plist_map_fn)(void *data, void *arg)
Definition: sc_list.h:45
sc_plist_iter(sc_plist< T > *l, bool from_tail=false)
Definition: sc_list.h:142
handle_t insert_after(handle_t h, T d)
Definition: sc_list.h:124
attempt to take front() on an empty list") SC_DEFINE_MESSAGE(SC_ID_BACK_ON_EMPTY_LIST_
handle_t push_back(void *d)
attempt to take attempt to take back() on an empty list") SC_DEFINE_MESSAGE(SC_ID_IEEE_1666_DEPRECATION_
void * back() const
sc_plist_iter(sc_plist< T > &l, bool from_tail=false)
Definition: sc_list.h:147
T front() const
Definition: sc_list.h:135
void reset(sc_plist_base *l, bool from_tail=false)
sc_plist_elem * handle_t
Definition: sc_list.h:82
handle_t push_front(T d)
Definition: sc_list.h:117
T operator*() const
Definition: sc_list.h:166
void * get(handle_t h) const
sc_plist_elem * handle_t
Definition: sc_list.h:54
void * remove(handle_t h)
handle_t insert_before(handle_t h, void *d)
handle_t insert_after(handle_t h, void *d)
handle_t push_back(T d)
Definition: sc_list.h:116
#define SC_API
Definition: sc_cmnhdr.h:168
void * front() const
void reset(sc_plist< T > *l, bool from_tail=false)
Definition: sc_list.h:157