Common/Util/TypeStripper.h

Go to the documentation of this file.
00001 //-------------------------------------------------------------------
00004 //  Copyright (c) 2004 Evan Sherbrooke and Michael Lauer
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019 //
00020 //-------------------------------------------------------------------
00021 
00022 #pragma once
00023 #ifndef VOLUMILL_TYPESTRIPPER_H
00024 #define VOLUMILL_TYPESTRIPPER_H
00025 
00026 #include <boost/ref.hpp>
00027 #include <boost/type_traits.hpp>
00028 #include <boost/shared_ptr.hpp>
00029 
00030 namespace util
00031 {
00032 
00033 template <class T>
00034 struct TypeStripper
00035 {
00036    typedef T type;
00037    typedef typename boost::remove_reference<type>::type      base_type;
00038    typedef typename boost::add_reference<type>::type         ref_type;
00039    typedef typename boost::add_reference<
00040       typename boost::add_const<type>::type >::type               cref_type;
00041    typedef typename boost::add_reference<base_type>::type         ref_base_type;
00042    typedef typename boost::add_reference<const base_type>::type   cref_base_type;
00043 
00044    static
00045       ref_base_type strip(ref_base_type t)     { return t; }
00046    static
00047       cref_base_type cstrip(cref_base_type t)     { return t; }
00048 
00049 };
00050 
00051 template <class T>
00052 struct TypeStripper<boost::shared_ptr<T> >
00053 {
00054    typedef boost::shared_ptr<T>                    type;
00055    typedef T                                       wrapped_type;
00056    typedef TypeStripper<wrapped_type>                 wrapped_type_utils;
00057    typedef typename wrapped_type_utils::base_type  base_type;
00058    typedef type &       ref_type;
00059    typedef const type & cref_type;
00060    typedef typename boost::add_reference<base_type>::type         ref_base_type;
00061    typedef typename boost::add_reference<const base_type>::type   cref_base_type;
00062 
00063    static
00064       ref_base_type strip(cref_type t)  { return wrapped_type_utils::strip(*t); }
00065    static
00066       cref_base_type cstrip(cref_type t)  { return wrapped_type_utils::cstrip(*t); }
00067 };
00068 
00069 template <class T>
00070 struct TypeStripper<boost::reference_wrapper<T> >
00071 {
00072    typedef boost::reference_wrapper<T> type;
00073    typedef T                                       wrapped_type;
00074    typedef TypeStripper<wrapped_type>                 wrapped_type_utils;
00075    typedef typename wrapped_type_utils::base_type  base_type;
00076    typedef type &       ref_type;
00077    typedef const type & cref_type;
00078    typedef typename boost::add_reference<base_type>::type         ref_base_type;
00079    typedef typename boost::add_reference<const base_type>::type   cref_base_type;
00080 
00081    static
00082       ref_base_type strip(cref_type t)  { return wrapped_type_utils::strip(t); }
00083    static
00084       cref_base_type cstrip(cref_type t)  { return wrapped_type_utils::cstrip(t); }
00085 
00086 };
00087 
00088 template <class T>
00089 struct TypeStripper<T *>
00090 {
00091    typedef T *                                     type;
00092    typedef T                                       wrapped_type;
00093    typedef TypeStripper<wrapped_type>                 wrapped_type_utils;
00094    typedef typename wrapped_type_utils::base_type  base_type;
00095    typedef type &       ref_type;
00096    typedef const type & cref_type;
00097    typedef typename boost::add_reference<base_type>::type         ref_base_type;
00098    typedef typename boost::add_reference<const base_type>::type   cref_base_type;
00099 
00100    static
00101       ref_base_type strip(cref_type t)  { return wrapped_type_utils::strip(*t); }
00102    static
00103       cref_base_type cstrip(cref_type t)  { return wrapped_type_utils::cstrip(*t); }
00104 };
00105 
00106 }
00107 #endif

Generated on Tue Jan 29 21:37:57 2008 for VoluMill Universal Client by  doxygen 1.4.6