Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sc_list.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2004 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.3 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_list.h -- Simple implementation of a doubly linked list.
00021 
00022   Original Author: Stan Y. Liao, Synopsys, Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 #ifndef SC_LIST_H
00037 #define SC_LIST_H
00038 
00039 //Some forward declarations
00040 class sc_plist_elem;
00041 template<class T> class sc_plist_iter; 
00042 
00043 typedef void (*sc_plist_map_fn)( void* data, void* arg );
00044 
00045 class sc_plist_base {
00046     friend class sc_plist_base_iter;
00047 
00048 public:
00049     sc_plist_base();
00050     ~sc_plist_base();
00051     
00052     typedef sc_plist_elem* handle_t;
00053 
00054     handle_t push_back(void* d);
00055     handle_t push_front(void* d);
00056     void* pop_back();
00057     void* pop_front();
00058     handle_t insert_before(handle_t h, void* d);
00059     handle_t insert_after(handle_t h, void* d);
00060     void* remove(handle_t h);
00061     void* get(handle_t h) const;
00062     void set(handle_t h, void* d);
00063     void mapcar( sc_plist_map_fn f, void* arg );
00064 
00065     void* front() const;
00066     void* back() const;
00067 
00068     void erase_all();
00069     bool empty() const { return (head == 0); }
00070     int size() const;
00071 
00072 private:
00073     handle_t head;
00074     handle_t tail;
00075 };
00076 
00077 
00078 class sc_plist_base_iter {
00079 public:
00080     typedef sc_plist_elem* handle_t;
00081     
00082     sc_plist_base_iter( sc_plist_base* l, bool from_tail = false );
00083     ~sc_plist_base_iter();
00084 
00085     void reset( sc_plist_base* l, bool from_tail = false );
00086     bool empty() const;
00087     void operator++(int);
00088     void operator--(int);
00089     void* get() const;
00090     void  set(void* d);
00091     void remove();
00092     void remove(int direction);
00093 
00094     void set_handle(handle_t h);
00095     handle_t get_handle() const { return ptr; }
00096     
00097 private:
00098     sc_plist_base* lst;
00099     sc_plist_elem* ptr;
00100 };
00101 
00102 /*---------------------------------------------------------------------------*/
00103 
00104 template< class T >
00105 class sc_plist : public sc_plist_base {
00106     friend class sc_plist_iter <T>;
00107 
00108 public:
00109     typedef sc_plist_iter<T> iterator;
00110 
00111     sc_plist() { } 
00112     ~sc_plist() { } 
00113 
00114     handle_t push_back(T d)  { return sc_plist_base::push_back((void*)d);  }
00115     handle_t push_front(T d) { return sc_plist_base::push_front((void*)d); }
00116     T pop_back()           { return (T) sc_plist_base::pop_back(); }
00117     T pop_front()          { return (T) sc_plist_base::pop_front(); }
00118     handle_t insert_before(handle_t h, T d) 
00119     {
00120         return sc_plist_base::insert_before(h, (void*) d);
00121     }
00122     handle_t insert_after(handle_t h, T d)
00123     {
00124         return sc_plist_base::insert_after(h, (void*) d);
00125     }
00126     T remove(handle_t h)
00127     {
00128         return (T)sc_plist_base::remove(h);
00129     }
00130     T get(handle_t h) const { return (T)sc_plist_base::get(h); }
00131     void set(handle_t h, T d) { sc_plist_base::set(h, (void*)d); }
00132 
00133     T front() const { return (T)sc_plist_base::front(); }
00134     T back() const { return (T)sc_plist_base::back(); }
00135 };
00136 
00137 template< class T >
00138 class sc_plist_iter : public sc_plist_base_iter {
00139 public:
00140     sc_plist_iter( sc_plist<T>* l, bool from_tail = false )
00141         : sc_plist_base_iter( l, from_tail )
00142     {
00143 
00144     }
00145     sc_plist_iter( sc_plist<T>& l, bool from_tail = false )
00146         : sc_plist_base_iter( &l, from_tail )
00147     {
00148 
00149     }
00150     ~sc_plist_iter()
00151     {
00152 
00153     }
00154 
00155     void reset( sc_plist<T>* l, bool from_tail = false )
00156     {
00157         sc_plist_base_iter::reset( l, from_tail );
00158     }
00159     void reset( sc_plist<T>& l, bool from_tail = false )
00160     {
00161         sc_plist_base_iter::reset( &l, from_tail );
00162     }
00163 
00164     T operator*() const { return (T) sc_plist_base_iter::get(); }
00165     T get() const     { return (T) sc_plist_base_iter::get(); }
00166     void set(T d)     { sc_plist_base_iter::set((void*) d); }
00167 };
00168 
00169 #endif

Generated on Fri Jan 14 08:29:03 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18