set.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___set_hh___included
00029 #define lestes__std___set_hh___included
00030 
00031 #include <lestes/common.hh>
00032 #include <lestes/std/collection_refl.hh>
00033 #include <lestes/std/list.hh>
00034 #include <set>
00035 
00036 /*! \file
00037   \brief Collectible ::std::set
00038   \author rudo
00039 
00040   Encapsulation for STL set class to be compatible with
00041   our garbage collector. Includes namely marking routine
00042   and factory method.
00043  */
00044 
00045 package(lestes);
00046 package(std);
00047 
00048 
00049 template <typename Key, typename Compare = ::std::less<Key> >
00050 class set : public object, public ::std::set<Key, Compare>
00051 {
00052 public:
00053         static ptr< set<Key,Compare> > create()
00054         {
00055                 return new set();
00056         }
00057         static ptr< set<Key,Compare> > create( ptr< set<Key,Compare> > from )
00058         {
00059                 return new set(from);
00060         }
00061         virtual ptr<reflection_list> reflection_get() const
00062         {
00063                 if (!collection_refl::set_simple)
00064                         collection_refl::set_simple_init( object::reflection_get() );
00065                 return collection_refl::set_simple;
00066         }
00067         virtual ptr<field_list_list> field_values_get() const
00068         {
00069                 ptr<field_list_list> result = object::field_values_get();
00070                 result->push_back( value_list::create() );
00071                 // wrap all items in objectize, insert the result onto the just created value_list
00072                 transform( this->begin(), this->end(),
00073                                 back_inserter( *result->back() ), unary_objectizer<Key>() );
00074                 return result;
00075         }
00076 protected:
00077         set() : object(), ::std::set<Key,Compare>()
00078         {}
00079         set( ptr< set<Key,Compare> > from ) : object(), ::std::set<Key,Compare>( *checked(from) )
00080         {}
00081 };
00082 
00083 
00084 template <typename Key>
00085 class set< srp<Key>, ::std::less< srp<Key> > > :
00086         public object, public ::std::set< srp<Key>, ::std::less< srp<Key> > >
00087 {
00088 public:
00089         static ptr< set< srp<Key>, ::std::less< srp<Key> > > > create()
00090         {
00091                 return new set();
00092         }
00093         static ptr< set< srp<Key> > > create( ptr< set< srp<Key> > > from )
00094         {
00095                 return new set(from);
00096         }
00097         virtual ptr<reflection_list> reflection_get() const
00098         {
00099                 if (!collection_refl::set_srp)
00100                         collection_refl::set_srp_init( object::reflection_get() );
00101                 return collection_refl::set_srp;
00102         }
00103         virtual ptr<field_list_list> field_values_get() const
00104         {
00105                 ptr<field_list_list> result = object::field_values_get();
00106                 result->push_back( value_list::create() );
00107                 result->back()->insert( result->back()->end(), this->begin(), this->end() );
00108                 return result;
00109         }
00110 protected:
00111         set() : object(), ::std::set< srp<Key>, ::std::less< srp<Key> > >()
00112         {}
00113         set( ptr< set< srp<Key> > > from )
00114                 : object(), ::std::set< srp<Key>, ::std::less< srp<Key> > >( *checked(from) )
00115         {}
00116         void gc_mark()
00117         {
00118                 object::gc_mark();
00119                 for (typename set::iterator i = this->begin(); i != this->end(); ++i)
00120                         i->gc_mark();
00121         }
00122 };
00123 
00124 template <typename Key, typename Compare>
00125 class set< srp<Key>, Compare > :
00126         public object, public ::std::set< srp<Key>, Compare >
00127 {
00128 public:
00129         static ptr< set< srp<Key>, Compare > > create()
00130         {
00131                 return new set();
00132         }
00133         static ptr< set< srp<Key>, Compare > > create( ptr< set< srp<Key>, Compare > > from )
00134         {
00135                 return new set(from);
00136         }
00137         virtual ptr<reflection_list> reflection_get() const
00138         {
00139                 if (!collection_refl::set_srp)
00140                         collection_refl::set_srp_init( object::reflection_get() );
00141                 return collection_refl::set_srp;
00142         }
00143         virtual ptr<field_list_list> field_values_get() const
00144         {
00145                 ptr<field_list_list> result = object::field_values_get();
00146                 result->push_back( value_list::create() );
00147                 result->back()->insert( result->back()->end(), this->begin(), this->end() );
00148                 return result;
00149         }
00150 protected:
00151         set() : object(), ::std::set< srp<Key>, Compare >()
00152         {}
00153         set( ptr< set< srp<Key>, Compare > > from )
00154                 : object(), ::std::set< srp<Key>, Compare >( *checked(from) )
00155         {}
00156         void gc_mark()
00157         {
00158                 object::gc_mark();
00159                 for (typename set::iterator i = this->begin(); i != this->end(); ++i)
00160                         i->gc_mark();
00161         }
00162 };
00163 
00164 
00165 end_package(std);
00166 end_package(lestes);
00167 
00168 #endif  // lestes__std___set_hh___included
00169 /* vim: set ft=lestes : */

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