list.hh

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 #ifndef lestes__std___list_hh___included
00029 #define lestes__std___list_hh___included
00030 
00031 #include <lestes/common.hh>
00032 #include <lestes/std/collection_refl.hh>
00033 #include <lestes/std/objectize.hh>
00034 #include <list>
00035 #include <iterator>
00036 #include <algorithm>
00037 
00038 /*! \file
00039   \brief Collectible ::std::list
00040   \author egg
00041 
00042   Encapsulation for STL list class to be compatible with
00043   our garbage collector. Includes namely marking routine
00044   and factory method.
00045  */
00046 
00047 package(lestes);
00048 package(std);
00049 
00050 template< typename T >
00051 class list : public object, public ::std::list<T> {
00052 public:
00053         //! Factory method, creates an empty list.
00054         static ptr< list<T> > create();
00055 #if 0
00056         //! Factory method, creates a list from a range
00057         template<typename InputIterator>
00058         static ptr< list < T > > create(InputIterator first, InputIterator last);
00059 #endif
00060         //! Factory method creates a copy of given list.
00061         static ptr< list<T> > create( ptr< list<T> > );
00062         virtual ptr<reflection_list> reflection_get() const;
00063         virtual ptr<field_list_list> field_values_get() const;
00064 protected:
00065         //! Constructor for an empty list.
00066         list();
00067         //! Imitation of copy-constructor, *takes a pointer*
00068         list( ptr< list<T> > );
00069 #if 0
00070         //! construct from range
00071         template<typename InputIterator>
00072         list(InputIterator first, InputIterator last) : ::std::list < T >(first,last) {}
00073 #endif
00074 };
00075 
00076 template< typename T >
00077 class list< srp<T> > : public object, public ::std::list< srp<T> > {
00078 public:
00079         //! Factory method, creates an empty list.
00080         static ptr< list< srp<T> > > create();
00081 #if 0
00082         //! Factory method, creates a list from a range
00083         template<typename InputIterator>
00084         static ptr< list < srp < T > > > create(InputIterator first, InputIterator last);
00085 #endif
00086         //! Factory method creates a copy of given list.
00087         static ptr< list< srp<T> > > create( ptr< list< srp<T> > > );
00088         virtual ptr<reflection_list> reflection_get() const;
00089         virtual ptr<field_list_list> field_values_get() const;
00090 protected:
00091         //! Constructor for an empty list.
00092         list();
00093         //! Imitation of copy-constructor, *takes a pointer*
00094         list( ptr< list< srp<T> > > );
00095 #if 0
00096         //! construct from range
00097         template<typename InputIterator>
00098         list(InputIterator first, InputIterator last) : ::std::list < srp < T > >(first,last) {}
00099 #endif
00100         //! Marking routine for class ::lestes::std::list
00101         void gc_mark(void);
00102 };
00103 
00104 template< typename T >
00105 ptr< list<T> > list<T>::create() {
00106         return new list<T>();
00107 }
00108 
00109 template< typename T >
00110 ptr< list<T> > list<T>::create( ptr< list<T> > from ) {
00111         return new list<T>(from);
00112 }
00113 
00114 template< typename T >
00115 ptr<object::reflection_list> list<T>::reflection_get() const
00116 {
00117         if (!collection_refl::list_simple)
00118                 collection_refl::list_simple_init( object::reflection_get() );
00119         return collection_refl::list_simple;
00120 }
00121 
00122 template< typename T >
00123 ptr<object::field_list_list> list<T>::field_values_get() const
00124 {
00125         ptr<field_list_list> result = object::field_values_get();
00126         result->push_back( value_list::create() );
00127         // wrap all items in objectize, insert the result onto the just created value_list
00128         transform( this->begin(), this->end(),
00129                         back_inserter( *result->back() ), unary_objectizer<T>() );
00130         return result;
00131 }
00132 
00133 template< typename T >
00134 list<T>::list()
00135         : object(), ::std::list<T>()
00136 {}
00137 
00138 template< typename T >
00139 list<T>::list( ptr< list<T> > from )
00140         : object(), ::std::list<T>( *checked(from) )
00141 {}
00142 
00143 template< typename T >
00144 ptr< list< srp<T> > > list< srp<T> >::create() {
00145         return new list< srp<T> >();
00146 }
00147 
00148 template< typename T >
00149 ptr< list< srp<T> > > list< srp<T> >::create( ptr< list< srp<T> > > from )
00150 {
00151         return new list< srp<T> >(from);
00152 }
00153 
00154 #if 0
00155 template<typename T>
00156 template<typename InputIterator>
00157 ptr < list < T > > list < T >::create(InputIterator first, InputIterator last)
00158 {
00159         return new list < T >(first, last);
00160 }
00161 
00162 template<typename T>
00163 template<typename InputIterator>
00164 ptr < list < srp < T > > > list < srp < T > >::create(InputIterator first, InputIterator last)
00165 {
00166         return new list < srp < T > >(first, last);
00167 }
00168 #endif
00169 
00170 template< typename T >
00171 ptr<object::reflection_list> list< srp<T> >::reflection_get() const
00172 {
00173         if (!collection_refl::list_srp)
00174                 collection_refl::list_srp_init( object::reflection_get() );
00175         return collection_refl::list_srp;
00176 }
00177 
00178 template< typename T >
00179 ptr<object::field_list_list> list< srp<T> >::field_values_get() const
00180 {
00181         ptr<field_list_list> result = object::field_values_get();
00182         result->push_back( value_list::create() );
00183         result->back()->insert( result->back()->end(), this->begin(), this->end() );
00184         return result;
00185 }
00186 
00187 template< typename T >
00188 list< srp<T> >::list()
00189         : object(), ::std::list< srp<T> >()
00190 { }
00191 
00192 template< typename T >
00193 list< srp<T> >::list( ptr< list< srp<T> > > from )
00194         : object(), ::std::list< srp<T> >( *checked(from) )
00195 {}
00196 
00197 template< typename T >
00198 void list< srp<T> >::gc_mark() {
00199         // gc_mark each member
00200         for (typename list::iterator i = this->begin(); i != this->end(); ++i)
00201                 i->gc_mark();
00202         object::gc_mark();      // inherited gc_mark
00203 }
00204 
00205 end_package(std);
00206 end_package(lestes);
00207 
00208 #endif  // lestes__std___list_hh___included
00209 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:27:10 2007 for lestes by doxygen 1.5.1-20070107