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