pair.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___pair_hh___included
00029 #define lestes__std___pair_hh___included
00030 
00031 #include <lestes/common.hh>
00032 #include <lestes/std/collection_refl.hh>
00033 #include <lestes/std/list.hh>
00034 #include <utility>
00035 
00036 /*! \file
00037   \brief Collectible ::std::pair
00038   \author rudo
00039 
00040   Encapsulation for STL pair class to be compatible with
00041   our garbage collector. Includes namely marking routine
00042   and factory method.
00043 
00044   make_pair as known from STL is banned, use the create method.
00045  */
00046 
00047 package(lestes);
00048 package(std);
00049 
00050 template< typename T1, typename T2 >
00051 class pair : public object, public ::std::pair<T1,T2> {
00052 public:
00053         static ptr< pair<T1,T2> > create()
00054         {
00055                 return new pair();
00056         }
00057         static ptr< pair<T1,T2> > create( const T1 &a, const T2 &b )
00058         {
00059                 return new pair( a, b );
00060         }
00061         static ptr< pair<T1,T2> > create( const ptr< pair<T1,T2> > &p )
00062         {
00063                 return new pair(*p);
00064         }
00065         static ptr< pair<T1,T2> > create( const ::std::pair<T1,T2> &stdp )
00066         {
00067                 return create( stdp.first, stdp.second );
00068         }
00069         virtual ptr<reflection_list> reflection_get() const
00070         {
00071                 if (!collection_refl::pair_simple_simple)
00072                         collection_refl::pair_simple_simple_init( object::reflection_get() );
00073                 return collection_refl::pair_simple_simple;
00074         }
00075         virtual ptr<field_list_list> field_values_get() const
00076         {
00077                 ptr<field_list_list> result = object::field_values_get();
00078                 result->push_back( value_list::create() );
00079                 result->back()->push_back( objectize<T1>::create(this->first) );
00080                 result->push_back( value_list::create() );
00081                 result->back()->push_back( objectize<T2>::create(this->second) );
00082                 return result;
00083         }
00084 protected:
00085         pair() : object(), ::std::pair<T1,T2>()
00086         {}
00087         pair( const T1 &a, const T2 &b ) : object(), ::std::pair<T1,T2>( a, b )
00088         {}
00089         pair( const pair &p ) : object(), ::std::pair<T1,T2>(p)
00090         {}
00091 };
00092 
00093 
00094 template< typename T1, typename T2 >
00095 class pair< srp<T1>, T2 > : public object, public ::std::pair< srp<T1>, T2 > {
00096 public:
00097         static ptr< pair< srp<T1>, T2 > > create()
00098         {
00099                 return new pair();
00100         }
00101         static ptr< pair< srp<T1>, T2 > > create( const ptr<T1> &a, const T2 &b )
00102         {
00103                 return new pair( a, b );
00104         }
00105         static ptr< pair< srp<T1>, T2 > > create( const ptr< pair< srp<T1>, T2 > > &p )
00106         {
00107                 return new pair(*p);
00108         }
00109         static ptr< pair< srp<T1>, T2 > > create( const ::std::pair< srp<T1>, T2 > &stdp )
00110         {
00111                 return create( stdp.first, stdp.second );
00112         }
00113         virtual ptr<reflection_list> reflection_get() const
00114         {
00115                 if (!collection_refl::pair_srp_simple)
00116                         collection_refl::pair_srp_simple_init( object::reflection_get() );
00117                 return collection_refl::pair_srp_simple;
00118         }
00119         virtual ptr<field_list_list> field_values_get() const
00120         {
00121                 ptr<field_list_list> result = object::field_values_get();
00122                 result->push_back( value_list::create() );
00123                 result->back()->push_back( this->first );
00124                 result->push_back( value_list::create() );
00125                 result->back()->push_back( objectize<T2>::create(this->second) );
00126                 return result;
00127         }
00128 protected:
00129         pair() : object(), ::std::pair< srp<T1>, T2 >()
00130         {}
00131         pair( const srp<T1> &a, const T2 &b ) : object(), ::std::pair< srp<T1>, T2 >( a, b )
00132         {}
00133         pair( const pair &p ) : object(), ::std::pair< srp<T1>, T2 >(p)
00134         {}
00135         void gc_mark()
00136         {
00137                 this->first.gc_mark();
00138         }
00139 };
00140 
00141 
00142 template< typename T1, typename T2 >
00143 class pair< T1, srp<T2> > : public object, public ::std::pair< T1, srp<T2> > {
00144 public:
00145         static ptr< pair< T1, srp<T2> > > create()
00146         {
00147                 return new pair< T1, srp<T2> >();
00148         }
00149         static ptr< pair< T1, srp<T2> > > create( const T1 &a, const ptr<T2> &b )
00150         {
00151                 return new pair< T1, srp<T2> >( a, b );
00152         }
00153         static ptr< pair< T1, srp<T2> > > create( const ptr< pair< T1, srp<T2> > > &p )
00154         {
00155                 return new pair< T1, srp<T2> >(*p);
00156         }
00157         static ptr< pair< T1, srp<T2> > > create( const ::std::pair< T1, srp<T2> > &stdp )
00158         {
00159                 return create( stdp.first, stdp.second );
00160         }
00161         virtual ptr<reflection_list> reflection_get() const
00162         {
00163                 if (!collection_refl::pair_simple_srp)
00164                         collection_refl::pair_simple_srp_init( object::reflection_get() );
00165                 return collection_refl::pair_simple_srp;
00166         }
00167         virtual ptr<field_list_list> field_values_get() const
00168         {
00169                 ptr<field_list_list> result = object::field_values_get();
00170                 result->push_back( value_list::create() );
00171                 result->back()->push_back( objectize<T1>::create(this->first) );
00172                 result->push_back( value_list::create() );
00173                 result->back()->push_back( this->second );
00174                 return result;
00175         }
00176 protected:
00177         pair< T1, srp<T2> >()
00178                 : object(), ::std::pair< T1, srp<T2> >()
00179         {}
00180         pair< T1, srp<T2> >( const T1 &a, const srp<T2> &b )
00181                 : object(), ::std::pair< T1, srp<T2> >( a, b )
00182         {}
00183         pair< T1, srp<T2> >( const pair< T1, srp<T2> > &p )
00184                 : object(), ::std::pair< T1, srp<T2> >(p)
00185         {}
00186         void gc_mark()
00187         {
00188                 this->second.gc_mark();
00189         }
00190 };
00191 
00192 
00193 template< typename T1, typename T2 >
00194 class pair< srp<T1>, srp<T2> > : public object, public ::std::pair< srp<T1>, srp<T2> > {
00195 public:
00196         static ptr< pair< srp<T1>, srp<T2> > > create()
00197         {
00198                 return new pair();
00199         }
00200         static ptr< pair< srp<T1>, srp<T2> > > create( const ptr<T1> &a, const ptr<T2> &b )
00201         {
00202                 return new pair( a, b );
00203         }
00204         static ptr< pair< srp<T1>, srp<T2> > > create( const ptr< pair< srp<T1>, srp<T2> > > &p )
00205         {
00206                 return new pair(*p);
00207         }
00208         static ptr< pair< srp<T1>, srp<T2> > > create( const ::std::pair< srp<T1>, srp<T2> > &stdp )
00209         {
00210                 return create( stdp.first, stdp.second );
00211         }
00212         virtual ptr<reflection_list> reflection_get() const
00213         {
00214                 if (!collection_refl::pair_srp_srp)
00215                         collection_refl::pair_srp_srp_init( object::reflection_get() );
00216                 return collection_refl::pair_srp_srp;
00217         }
00218         virtual ptr<field_list_list> field_values_get() const
00219         {
00220                 ptr<field_list_list> result = object::field_values_get();
00221                 result->push_back( value_list::create() );
00222                 result->back()->push_back( this->first );
00223                 result->push_back( value_list::create() );
00224                 result->back()->push_back( this->second );
00225                 return result;
00226         }
00227 protected:
00228         pair() : object(), ::std::pair< srp<T1>, srp<T2> >()
00229         {}
00230         pair( const srp<T1> &a, const srp<T2> &b ) : object(), ::std::pair< srp<T1>, srp<T2> >( a, b )
00231         {}
00232         pair( const pair &p ) : object(), ::std::pair< srp<T1>, srp<T2> >(p)
00233         {}
00234         void gc_mark()
00235         {
00236                 this->first.gc_mark();
00237                 this->second.gc_mark();
00238         }
00239 };
00240 
00241 end_package(std);
00242 end_package(lestes);
00243 
00244 #endif  // lestes__std___pair_hh___included
00245 /* vim: set ft=lestes : */

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