pointer_helpers.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___pointer_helpers_hh___included
00029 #define lestes___pointer_helpers_hh___included
00030 
00031 /*! \file
00032   \brief Helper templates for smart pointers.
00033   
00034   Definition of helper templates to operate uniformly with
00035   smart pointer and simple types. Useful when the actual type
00036   is not known, e.g. comes from a template parameter
00037   \author pt
00038 */
00039 #include <lestes/common.hh>
00040 
00041 package(lestes);
00042 
00043 /*!
00044   Converts type to ptr or srp, if of pointer type,
00045   otherwise does no conversion for simple types.
00046 */
00047 template <typename T>
00048 struct convert {
00049         //! The same type as the parameter.
00050         typedef T to_ptr;
00051         //! The same type as the parameter.
00052         typedef T to_srp;
00053 };
00054 
00055 /*!
00056   Converts type to ptr or srp, if of pointer type,
00057   otherwise ddoes no conversion.
00058   Specialization for ptr<T>.
00059   \param T the type of the pointee.
00060 */
00061 template <typename T>
00062 struct convert< ptr<T> > {
00063         //! The same ptr type.
00064         typedef ptr<T> to_ptr;
00065         //! The corresponding srp type for the ptr.
00066         typedef srp<T> to_srp;
00067 };
00068 
00069 /*!
00070   Converts type to ptr or srp, if of pointer type.
00071   otherwise does no conversion.
00072   Specialization for srp<T>.
00073   \param T the type of the pointee.
00074 */
00075 template <typename T>
00076 struct convert< srp<T> > {
00077         //! The corresponding srp type for the ptr.
00078         typedef ptr<T> to_ptr;
00079         //! The same srp type.
00080         typedef srp<T> to_srp;
00081 };
00082 
00083 /*!
00084   Fallback marking method, for simple types does no operation.
00085   Used in gc_mark methods of templated collectible classes.
00086   \param T The simple type of the field.
00087 */
00088 template <typename T>
00089 inline void gc_mark_srp(T &) {
00090 } 
00091 
00092 /*!
00093   Marks the object of srp type.
00094   Used in gc_mark methods of templated collectible classes.
00095   \param T The type of the pointee of the field.
00096   \param x The field to mark.
00097 */
00098 template <typename T>
00099 inline void gc_mark_srp(srp<T> &x) {
00100         x.gc_mark();
00101 } 
00102 
00103 
00104 end_package(lestes);
00105 
00106 #endif
00107 /* vim: set ft=lestes : */

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