vector.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___vector_hh___included
00029 #define lestes__std___vector_hh___included
00030 
00031 #include <lestes/common.hh>
00032 #include <lestes/std/collection_refl.hh>
00033 #include <lestes/std/list.hh>
00034 #include <lestes/std/objectize.hh>
00035 #include <vector>
00036 #include <iterator>
00037 #include <algorithm>
00038 
00039 /*! \file
00040   \brief Collectible ::std::vector
00041   \author egg
00042 
00043   Encapsulation for STL vector class to be compatible with
00044   our garbage collector. Includes namely marking routine
00045   and factory method.
00046  */
00047 
00048 package(lestes);
00049 package(std);
00050 
00051 template< typename T >
00052 class vector : public object, public ::std::vector<T> {
00053 public:
00054         //! Factory method, creates an empty vector.
00055         static ptr< vector<T> > create();
00056 #if 0
00057         //! Factory method, creates a vector from a range
00058         template<typename InputIterator>
00059         static ptr< vector < T > > create(InputIterator first, InputIterator last);
00060 #endif
00061         //! Factory method creates a copy of given vector.
00062         static ptr< vector<T> > create( ptr< vector<T> > );
00063         virtual ptr<reflection_list> reflection_get() const;
00064         virtual ptr<field_list_list> field_values_get() const;
00065 protected:
00066         //! Constructor for an empty vector.
00067         vector();
00068         //! Imitation of copy-constructor, *takes a pointer*
00069         vector( ptr< vector<T> > );
00070 #if 0
00071         //! construct from range
00072         template<typename InputIterator>
00073         vector(InputIterator first, InputIterator last) : ::std::vector < T >(first,last) {}
00074 #endif
00075 };
00076 
00077 template< typename T >
00078 class vector< srp<T> > : public object, public ::std::vector< srp<T> > {
00079 public:
00080         //! Factory method, creates an empty vector.
00081         static ptr< vector< srp<T> > > create();
00082 #if 0
00083         //! Factory method, creates a vector from a range
00084         template<typename InputIterator>
00085         static ptr< vector < srp < T > > > create(InputIterator first, InputIterator last);
00086 #endif
00087         //! Factory method creates a copy of given vector.
00088         static ptr< vector< srp<T> > > create( ptr< vector< srp<T> > > );
00089         virtual ptr<reflection_list> reflection_get() const;
00090         virtual ptr<field_list_list> field_values_get() const;
00091 protected:
00092         //! Constructor for an empty vector.
00093         vector();
00094         //! Imitation of copy-constructor, *takes a pointer*
00095         vector( ptr< vector< srp<T> > > );
00096 #if 0
00097         //! construct from range
00098         template<typename InputIterator>
00099         vector(InputIterator first, InputIterator last) : ::std::vector < srp < T > >(first,last) {}
00100 #endif
00101         //! Marking routine for class ::lestes::std::vector
00102         void gc_mark(void);
00103 };
00104 
00105 template< typename T >
00106 ptr< vector<T> > vector<T>::create() {
00107         return new vector<T>();
00108 }
00109 
00110 template< typename T >
00111 ptr< vector<T> > vector<T>::create( ptr< vector<T> > from ) {
00112         return new vector<T>(from);
00113 }
00114 
00115 template< typename T >
00116 ptr<object::reflection_list> vector<T>::reflection_get() const
00117 {
00118         if (!collection_refl::vector_simple)
00119                 collection_refl::vector_simple_init( object::reflection_get() );
00120         return collection_refl::vector_simple;
00121 }
00122 
00123 template< typename T >
00124 ptr<object::field_list_list> vector<T>::field_values_get() const
00125 {
00126         ptr<field_list_list> result = object::field_values_get();
00127         result->push_back( value_list::create() );
00128         // wrap all items in objectize, insert the result onto the just created value_list
00129         transform( this->begin(), this->end(),
00130                         back_inserter( *result->back() ), unary_objectizer<T>() );
00131         return result;
00132 }
00133 
00134 template< typename T >
00135 vector<T>::vector()
00136         : object(), ::std::vector<T>()
00137 {}
00138 
00139 template< typename T >
00140 vector<T>::vector( ptr< vector<T> > from )
00141         : object(), ::std::vector<T>( *checked(from) )
00142 {}
00143 
00144 template< typename T >
00145 ptr< vector< srp<T> > > vector< srp<T> >::create() {
00146         return new vector< srp<T> >();
00147 }
00148 
00149 template< typename T >
00150 ptr< vector< srp<T> > > vector< srp<T> >::create( ptr< vector< srp<T> > > from )
00151 {
00152         return new vector< srp<T> >(from);
00153 }
00154 
00155 #if 0
00156 template<typename T>
00157 template<typename InputIterator>
00158 ptr < vector < T > > vector < T >::create(InputIterator first, InputIterator last)
00159 {
00160         return new vector < T >(first, last);
00161 }
00162 
00163 template<typename T>
00164 template<typename InputIterator>
00165 ptr < vector < srp < T > > > vector < srp < T > >::create(InputIterator first, InputIterator last)
00166 {
00167         return new vector < srp < T > >(first, last);
00168 }
00169 
00170 #endif
00171 
00172 template< typename T >
00173 ptr<object::reflection_list> vector< srp<T> >::reflection_get() const
00174 {
00175         if (!collection_refl::vector_srp)
00176                 collection_refl::vector_srp_init( object::reflection_get() );
00177         return collection_refl::vector_srp;
00178 }
00179 
00180 template< typename T >
00181 ptr<object::field_list_list> vector< srp<T> >::field_values_get() const
00182 {
00183         ptr<field_list_list> result = object::field_values_get();
00184         result->push_back( value_list::create() );
00185         result->back()->insert( result->back()->end(), this->begin(), this->end() );
00186         return result;
00187 }
00188 
00189 template< typename T >
00190 vector< srp<T> >::vector()
00191         : object(), ::std::vector< srp<T> >()
00192 { }
00193 
00194 template< typename T >
00195 vector< srp<T> >::vector( ptr< vector< srp<T> > > from )
00196         : object(), ::std::vector< srp<T> >( *checked(from) )
00197 {}
00198 
00199 template< typename T >
00200 void vector< srp<T> >::gc_mark() {
00201         // gc_mark each member
00202         for (typename vector::iterator i = this->begin(); i != this->end(); ++i)
00203                 i->gc_mark();
00204         object::gc_mark();      // inherited gc_mark
00205 }
00206 
00207 end_package(std);
00208 end_package(lestes);
00209 
00210 #endif  // lestes__std___vector_hh___included
00211 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:23:44 2007 for lestes by doxygen 1.5.1-20070107