objectize_macros.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___objectize_macros_hh___included
00029 #define lestes__std___objectize_macros_hh___included
00030 
00031 #include <lestes/std/objectize.hh>
00032 
00033 /*!
00034  * Specializes objectize<T> for given enum type. The dumper visitor is called
00035  * as if the value was a lint; the actual value is static_cast to lint.
00036  *
00037  * The macro must be used inside ::lestes::std and must not be used more than
00038  * once for the same type, o for a type that was passed to the other macro,
00039  * specialize_objectize_nodump().
00040  *
00041  * Usually, you would pass fully qualified name as the type argument.
00042  *
00043  * Actually, the only thing that is implemented here is the create method. It
00044  * static casts the argument and returns a pointer to objectize<lint>.
00045  */
00046 #define specialize_objectize_for_enum( type )                                   \
00047 template<>                                                                      \
00048 class objectize< type > : public objectize<lint> {                              \
00049 public:                                                                         \
00050         static ptr< objectize<lint> > create( type a_value )                    \
00051         {                                                                       \
00052                 return objectize<lint>::create( static_cast<lint>(a_value) );   \
00053         }                                                                       \
00054 private:                                                                        \
00055         /*! Hide the constructor */                                             \
00056         objectize< type >();                                                    \
00057 }
00058 
00059 /*!
00060  * Specializes objectize<T> for given type. The dumper visitor's visit_nodump()
00061  * is called in accept_dumper_visitor().
00062  *
00063  * The macro must be used inside ::lestes::std and must not be used more than
00064  * once for the same type, or for a type that was passed to the other macro,
00065  * specialize_objectize_for_enum().
00066  *
00067  * Usually, you would pass fully qualified name as the type argument.
00068  *
00069  * Note that The create method does not use its argument in any way. This, and
00070  * the fact that const reference is used, ensures that no further requirements
00071  * are placed on the given type. If reference was not used, the type would have
00072  * to publicly support copy-construction. This has a disadvantage, though: The
00073  * type argument cannot be a reference type. Other macro is provided for those.
00074  */
00075 #define specialize_objectize_nodump( type )                                     \
00076 template<>                                                                      \
00077 class objectize< type > : public object {                                       \
00078 public:                                                                         \
00079         static ptr< objectize< type > > create( const type & )                  \
00080         {                                                                       \
00081                 /* the agument is not used at all */                            \
00082                 return new objectize< type >();                                 \
00083         }                                                                       \
00084         virtual void accept_dumper_visitor( ptr<dumper_visitor> v )             \
00085         {                                                                       \
00086                 return v->visit_nodump();                                       \
00087         }                                                                       \
00088 protected:                                                                      \
00089         objectize< type >()                                                     \
00090         {}                                                                      \
00091 }
00092 
00093 /*!
00094  * Specializes objectize<T> for given _reference_ type. The only difference
00095  * when compared to specialize_objectize_nodump is that the create method takes
00096  * argument of the type itself, which makes the generated specialization
00097  * compilable for a reference type.
00098  *
00099  * See documentation for specialize_objectize_nodump macro.
00100  */
00101 #define specialize_objectize_nodump_reference( type )                           \
00102 template<>                                                                      \
00103 class objectize< type > : public object {                                       \
00104 public:                                                                         \
00105         static ptr< objectize< type > > create( const type )                    \
00106         {                                                                       \
00107                 /* the agument is not used at all */                            \
00108                 return new objectize< type >();                                 \
00109         }                                                                       \
00110         virtual void accept_dumper_visitor( ptr<dumper_visitor> v )             \
00111         {                                                                       \
00112                 return v->visit_nodump();                                       \
00113         }                                                                       \
00114 protected:                                                                      \
00115         objectize< type >()                                                     \
00116         {}                                                                      \
00117 }
00118 
00119 #endif  // lestes__std___objectize_macros_hh___included

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