src/sysc/utils/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-2005 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.4 (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 namespace sc_core {
00040 
00041 //Some forward declarations
00042 class sc_plist_elem;
00043 template<class T> class sc_plist_iter; 
00044 
00045 typedef void (*sc_plist_map_fn)( void* data, void* arg );
00046 
00047 class sc_plist_base {
00048     friend class sc_plist_base_iter;
00049 
00050 public:
00051     sc_plist_base();
00052     ~sc_plist_base();
00053     
00054     typedef sc_plist_elem* handle_t;
00055 
00056     handle_t push_back(void* d);
00057     handle_t push_front(void* d);
00058     void* pop_back();
00059     void* pop_front();
00060     handle_t insert_before(handle_t h, void* d);
00061     handle_t insert_after(handle_t h, void* d);
00062     void* remove(handle_t h);
00063     void* get(handle_t h) const;
00064     void set(handle_t h, void* d);
00065     void mapcar( sc_plist_map_fn f, void* arg );
00066 
00067     void* front() const;
00068     void* back() const;
00069 
00070     void erase_all();
00071     bool empty() const { return (head == 0); }
00072     int size() const;
00073 
00074 private:
00075     handle_t head;
00076     handle_t tail;
00077 };
00078 
00079 
00080 class sc_plist_base_iter {
00081 public:
00082     typedef sc_plist_elem* handle_t;
00083     
00084     sc_plist_base_iter( sc_plist_base* l, bool from_tail = false );
00085     ~sc_plist_base_iter();
00086 
00087     void reset( sc_plist_base* l, bool from_tail = false );
00088     bool empty() const;
00089     void operator++(int);
00090     void operator--(int);
00091     void* get() const;
00092     void  set(void* d);
00093     void remove();
00094     void remove(int direction);
00095 
00096     void set_handle(handle_t h);
00097     handle_t get_handle() const { return ptr; }
00098     
00099 private:
00100     sc_plist_base* lst;
00101     sc_plist_elem* ptr;
00102 };
00103 
00104 /*---------------------------------------------------------------------------*/
00105 
00106 template< class T >
00107 class sc_plist : public sc_plist_base {
00108     friend class sc_plist_iter <T>;
00109 
00110 public:
00111     typedef sc_plist_iter<T> iterator;
00112 
00113     sc_plist() { } 
00114     ~sc_plist() { } 
00115 
00116     handle_t push_back(T d)  { return sc_plist_base::push_back((void*)d);  }
00117     handle_t push_front(T d) { return sc_plist_base::push_front((void*)d); }
00118     T pop_back()           { return (T) sc_plist_base::pop_back(); }
00119     T pop_front()          { return (T) sc_plist_base::pop_front(); }
00120     handle_t insert_before(handle_t h, T d) 
00121     {
00122         return sc_plist_base::insert_before(h, (void*) d);
00123     }
00124     handle_t insert_after(handle_t h, T d)
00125     {
00126         return sc_plist_base::insert_after(h, (void*) d);
00127     }
00128     T remove(handle_t h)
00129     {
00130         return (T)sc_plist_base::remove(h);
00131     }
00132     T get(handle_t h) const { return (T)sc_plist_base::get(h); }
00133     void set(handle_t h, T d) { sc_plist_base::set(h, (void*)d); }
00134 
00135     T front() const { return (T)sc_plist_base::front(); }
00136     T back() const { return (T)sc_plist_base::back(); }
00137 };
00138 
00139 template< class T >
00140 class sc_plist_iter : public sc_plist_base_iter {
00141 public:
00142     sc_plist_iter( sc_plist<T>* l, bool from_tail = false )
00143         : sc_plist_base_iter( l, from_tail )
00144     {
00145 
00146     }
00147     sc_plist_iter( sc_plist<T>& l, bool from_tail = false )
00148         : sc_plist_base_iter( &l, from_tail )
00149     {
00150 
00151     }
00152     ~sc_plist_iter()
00153     {
00154 
00155     }
00156 
00157     void reset( sc_plist<T>* l, bool from_tail = false )
00158     {
00159         sc_plist_base_iter::reset( l, from_tail );
00160     }
00161     void reset( sc_plist<T>& l, bool from_tail = false )
00162     {
00163         sc_plist_base_iter::reset( &l, from_tail );
00164     }
00165 
00166     T operator*() const { return (T) sc_plist_base_iter::get(); }
00167     T get() const     { return (T) sc_plist_base_iter::get(); }
00168     void set(T d)     { sc_plist_base_iter::set((void*) d); }
00169 };
00170 
00171 } // namespace sc_core
00172 
00173 #endif

Generated on Wed Apr 25 13:53:28 2007 for SystemC by  doxygen 1.5.1