map.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___map_hh___included
00029 #define lestes__std___map_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/pair.hh>
00035 #include <map>
00036 
00037 /*! \file
00038   \brief Collectible ::std::map
00039   \author pt
00040   \author Rudo
00041 
00042   Encapsulation for STL map class to be compatible with
00043   our garbage collector. Includes namely marking routine,
00044   factory method, and dump support.
00045  */
00046 
00047 package(lestes);
00048 package(std);
00049 
00050 //! Unary function object, wraps ::std::pair into ::lestes::std::pair; used in map::field_values_get()
00051 template< typename T1, typename T2 >
00052 class unary_pair_wrapper {
00053 public:
00054         ptr< pair<T1,T2> > operator() (const ::std::pair<T1,T2> &p)
00055         {
00056                 return pair<T1,T2>::create(p);
00057         }
00058 };
00059 
00060 template <typename Key, typename Data, typename Compare = ::std::less<Key> >
00061 class map : public object, public ::std::map<Key, Data, Compare>
00062 {
00063 public:
00064         static ptr< map<Key,Data,Compare> > create()
00065         {
00066                 return new map();
00067         }
00068         static ptr< map<Key,Data,Compare> > create( ptr< map<Key,Data,Compare> > from )
00069         {
00070                 return new map(from);
00071         }
00072         virtual ptr<reflection_list> reflection_get() const
00073         {
00074                 if (!collection_refl::map_simple_simple)
00075                         collection_refl::map_simple_simple_init( object::reflection_get() );
00076                 return collection_refl::map_simple_simple;
00077         }
00078         virtual ptr<field_list_list> field_values_get() const
00079         {
00080                 ptr<field_list_list> result = object::field_values_get();
00081                 result->push_back( value_list::create() );
00082                 // wrap all the pairs in lestes pairs, this is unavoidable
00083                 transform( this->begin(), this->end(), back_inserter( *result->back() ),
00084                                 unary_pair_wrapper<Key,Data>() );
00085                 return result;
00086         }
00087 protected:
00088         map() : object(), ::std::map<Key,Data,Compare>()
00089         {}
00090         map( ptr< map<Key,Data,Compare> > from )
00091                 : object(), ::std::map<Key,Data,Compare>( *checked(from) )
00092         {}
00093 };
00094 
00095 
00096 template <typename Key, typename Data >
00097 class map< srp<Key>, srp<Data>, ::std::less< ::lestes::std::srp<Key> > > :
00098         public object, public ::std::map< srp<Key>, srp<Data>, ::std::less< ::lestes::std::srp<Key> > >
00099 {
00100 public:
00101         static ptr< map< srp<Key>, srp<Data>, ::std::less< srp<Key> > > > create()
00102         {
00103                 return new map();
00104         }
00105         static ptr< map< srp<Key>, srp<Data>, ::std::less< srp<Key> > > > create( ptr< map< srp<Key>, srp<Data>, ::std::less< srp<Key> > > > from )
00106         {
00107                 return new map(from);
00108         }
00109         virtual ptr<reflection_list> reflection_get() const
00110         {
00111                 if (!collection_refl::map_srp_srp)
00112                         collection_refl::map_srp_srp_init( object::reflection_get() );
00113                 return collection_refl::map_srp_srp;
00114         }
00115         virtual ptr<field_list_list> field_values_get() const
00116         {
00117                 ptr<field_list_list> result = object::field_values_get();
00118                 result->push_back( value_list::create() );
00119                 // wrap all the pairs in lestes pairs, this is unavoidable
00120                 transform( this->begin(), this->end(), back_inserter( *result->back() ),
00121                                 unary_pair_wrapper< srp<Key>, srp<Data> >() );
00122                 return result;
00123         }
00124 protected:
00125         map() : object(), ::std::map< srp<Key>, srp<Data>, ::std::less< srp<Key> > >()
00126         {}
00127         map( ptr< map< srp<Key>, srp<Data>, ::std::less< srp<Key> > > > from )
00128                 : object(), ::std::map< srp<Key>, srp<Data>, ::std::less< srp<Key> > >( *checked(from) )
00129         {}
00130         void gc_mark()
00131         {
00132                 object::gc_mark();
00133                 for (typename map::iterator i = this->begin(); i != this->end(); ++i) {
00134                         i->first.gc_mark();
00135                         i->second.gc_mark();
00136                 }
00137         }
00138 };
00139 
00140 template <typename Key, typename Data, typename Compare >
00141 class map< srp<Key>, srp<Data>, Compare > : public object, public ::std::map< srp<Key>, srp<Data>, Compare >
00142 {
00143 public:
00144         static ptr< map< srp<Key>, srp<Data>, Compare > > create()
00145         {
00146                 return new map();
00147         }
00148         static ptr< map< srp<Key>, srp<Data>, Compare > > create( ptr< map< srp<Key>, srp<Data>, Compare > > from )
00149         {
00150                 return new map(from);
00151         }
00152         virtual ptr<reflection_list> reflection_get() const
00153         {
00154                 if (!collection_refl::map_srp_srp)
00155                         collection_refl::map_srp_srp_init( object::reflection_get() );
00156                 return collection_refl::map_srp_srp;
00157         }
00158         virtual ptr<field_list_list> field_values_get() const
00159         {
00160                 ptr<field_list_list> result = object::field_values_get();
00161                 result->push_back( value_list::create() );
00162                 // wrap all the pairs in lestes pairs, this is unavoidable
00163                 transform( this->begin(), this->end(), back_inserter( *result->back() ),
00164                                 unary_pair_wrapper< srp<Key>, srp<Data> >() );
00165                 return result;
00166         }
00167 protected:
00168         map() : object(), ::std::map< srp<Key>, srp<Data>, Compare >()
00169         {}
00170         map( ptr< map< srp<Key>, srp<Data>, Compare > > from )
00171                 : object(), ::std::map< srp<Key>, srp<Data>, Compare >( *checked(from) )
00172         {}
00173         void gc_mark()
00174         {
00175                 map::gc_mark();
00176                 object::gc_mark();
00177                 for (typename map::iterator i = this->begin(); i != this->end(); ++i) {
00178                         i->first.gc_mark();
00179                         i->second.gc_mark();
00180                 }
00181         }
00182 };
00183 
00184 
00185 template <typename Key, typename Data >
00186 class map< srp<Key>, Data, ::std::less< ::lestes::std::srp<Key> > > :
00187         public object, public ::std::map< srp<Key>, Data, ::std::less< ::lestes::std::srp<Key> > >
00188 {
00189 public:
00190         static ptr< map< srp<Key>, Data, ::std::less< srp<Key> > > > create()
00191         {
00192                 return new map();
00193         }
00194         static ptr< map< srp<Key>, Data, ::std::less< srp<Key> > > > create( ptr< map< srp<Key>, Data, ::std::less< srp<Key> > > > from )
00195         {
00196                 return new map(from);
00197         }
00198         virtual ptr<reflection_list> reflection_get() const
00199         {
00200                 if (!collection_refl::map_srp_simple)
00201                         collection_refl::map_srp_simple_init( object::reflection_get() );
00202                 return collection_refl::map_srp_simple;
00203         }
00204         virtual ptr<field_list_list> field_values_get() const
00205         {
00206                 ptr<field_list_list> result = object::field_values_get();
00207                 result->push_back( value_list::create() );
00208                 // wrap all the pairs in lestes pairs, this is unavoidable
00209                 transform( this->begin(), this->end(), back_inserter( *result->back() ),
00210                                 unary_pair_wrapper< srp<Key>, Data >() );
00211                 return result;
00212         }
00213 protected:
00214         map() : object(), ::std::map< srp<Key>, Data, ::std::less< srp<Key> > >()
00215         {}
00216         map( ptr< map< srp<Key>, Data, ::std::less< srp<Key> > > > from )
00217                 : object(), ::std::map< srp<Key>, Data, ::std::less< srp<Key> > >( *checked(from) )
00218         {}
00219         void gc_mark()
00220         {
00221                 object::gc_mark();
00222                 for (typename map::iterator i = this->begin(); i != this->end(); ++i)
00223                         i->first.gc_mark();
00224         }
00225 };
00226 
00227 template <typename Key, typename Data, typename Compare >
00228 class map< srp<Key>, Data, Compare > : public object, public ::std::map< srp<Key>, Data, Compare>
00229 {
00230 public:
00231         static ptr< map< srp<Key>, Data, Compare > > create()
00232         {
00233                 return new map();
00234         }
00235         static ptr< map< srp<Key>, Data, Compare > > create( ptr< map< srp<Key>, Data, Compare > > from )
00236         {
00237                 return new map(from);
00238         }
00239         virtual ptr<reflection_list> reflection_get() const
00240         {
00241                 if (!collection_refl::map_srp_simple)
00242                         collection_refl::map_srp_simple_init( object::reflection_get() );
00243                 return collection_refl::map_srp_simple;
00244         }
00245         virtual ptr<field_list_list> field_values_get() const
00246         {
00247                 ptr<field_list_list> result = object::field_values_get();
00248                 result->push_back( value_list::create() );
00249                 // wrap all the pairs in lestes pairs, this is unavoidable
00250                 transform( this->begin(), this->end(), back_inserter( *result->back() ),
00251                                 unary_pair_wrapper< srp<Key>, Data >() );
00252                 return result;
00253         }
00254 protected:
00255         map() : object(), ::std::map< srp<Key>, Data, Compare >()
00256         {}
00257         map( ptr< map< srp<Key>, Data, Compare > > from )
00258                 : object(), ::std::map< srp<Key>, Data, Compare >( *checked(from) )
00259         {}
00260         void gc_mark()
00261         {
00262                 object::gc_mark();
00263                 for (typename map::iterator i = this->begin(); i != this->end(); ++i)
00264                         i->first.gc_mark();
00265         }
00266 };
00267 
00268 
00269 template <typename Key, typename Data>
00270 class map< Key, srp<Data>, ::std::less<Key> > : public object, public ::std::map<Key, srp<Data>, ::std::less<Key> >
00271 {
00272 public:
00273         static ptr< map< Key, srp<Data>, ::std::less<Key> > > create()
00274         {
00275                 return new map();
00276         }
00277         static ptr< map< Key, srp<Data>, ::std::less<Key> > > create( ptr< map< Key, srp<Data>, ::std::less<Key> > > from )
00278         {
00279                 return new map(from);
00280         }
00281         virtual ptr<reflection_list> reflection_get() const
00282         {
00283                 if (!collection_refl::map_simple_srp)
00284                         collection_refl::map_simple_srp_init( object::reflection_get() );
00285                 return collection_refl::map_simple_srp;
00286         }
00287         virtual ptr<field_list_list> field_values_get() const
00288         {
00289                 ptr<field_list_list> result = object::field_values_get();
00290                 result->push_back( value_list::create() );
00291                 // wrap all the pairs in lestes pairs, this is unavoidable
00292                 transform( this->begin(), this->end(), back_inserter( *result->back() ),
00293                                 unary_pair_wrapper< Key, srp<Data> >() );
00294                 return result;
00295         }
00296 protected:
00297         map() : object(), ::std::map< Key, srp<Data>, ::std::less<Key> >()
00298         {}
00299         map( ptr< map< Key, srp<Data>, ::std::less<Key> > > from )
00300                 : object(), ::std::map< Key, srp<Data>, ::std::less<Key> >( *checked(from) )
00301         {}
00302         void gc_mark()
00303         {
00304                 object::gc_mark();
00305                 for (typename map::iterator i = this->begin(); i != this->end(); ++i)
00306                         i->second.gc_mark();
00307         }
00308 };
00309 
00310 template <typename Key, typename Data, typename Compare>
00311 class map< Key, srp<Data>, Compare > : public object, public ::std::map<Key, srp<Data>, Compare >
00312 {
00313 public:
00314         static ptr< map< Key, srp<Data>, Compare > > create()
00315         {
00316                 return new map();
00317         }
00318         static ptr< map< Key, srp<Data>, Compare > > create( ptr< map< Key, srp<Data>, Compare > > from )
00319         {
00320                 return new map(from);
00321         }
00322         virtual ptr<reflection_list> reflection_get() const
00323         {
00324                 if (!collection_refl::map_simple_srp)
00325                         collection_refl::map_simple_srp_init( object::reflection_get() );
00326                 return collection_refl::map_simple_srp;
00327         }
00328         virtual ptr<field_list_list> field_values_get() const
00329         {
00330                 ptr<field_list_list> result = object::field_values_get();
00331                 result->push_back( value_list::create() );
00332                 // wrap all the pairs in lestes pairs, this is unavoidable
00333                 transform( this->begin(), this->end(), back_inserter( *result->back() ),
00334                                 unary_pair_wrapper< Key, srp<Data> >() );
00335                 return result;
00336         }
00337 protected:
00338         map() : object(), ::std::map< Key, srp<Data>, Compare >()
00339         {}
00340         map( ptr< map< Key, srp<Data>, Compare > > from )
00341                 : object(), ::std::map< Key, srp<Data>, Compare >( *checked(from) )
00342         {}
00343         void gc_mark()
00344         {
00345                 object::gc_mark();
00346                 for (typename map::iterator i = this->begin(); i != this->end(); ++i)
00347                         i->second.gc_mark();
00348         }
00349 };
00350 
00351 end_package(std);
00352 end_package(lestes);
00353 
00354 #endif  // lestes__std___map_hh___included
00355 /* vim: set ft=lestes : */

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