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

Generated on Wed Jan 21 15:32:10 2009 for SystemC by  doxygen 1.5.5