objectize.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_hh___included
00029 #define lestes__std___objectize_hh___included
00030 
00031 /*! \file
00032   Support for dumping: objectize<>.
00033   \author rudo
00034 */
00035 #include <lestes/common.hh>
00036 #include <lestes/std/ucn_string.hh>
00037 #include <lestes/std/dumper_visitor.hh>
00038 
00039 package(lestes);
00040 package(std);
00041 
00042 /*!
00043  * Wraps simple types so that a ptr<> can exist to them.
00044  *
00045  * Thie wrappe is needed for the dumper to be simple :-)
00046  *
00047  * For all the lestes collections to work, specialization for T must have a
00048  * static create method that takes a value of type T (or a reference to T).
00049  */
00050 template< typename T >
00051 class objectize : public object {
00052 private:
00053         //! this one is never meant to be instantiated, only the specializations are
00054         objectize();
00055 };
00056 
00057 //! Unary function object, wraps T in objectize<T>; used to transform collections of simple type
00058 template< typename T >
00059 class unary_objectizer {
00060 public:
00061         ptr<object> operator() (const T &a)
00062         {
00063                 return objectize<T>::create(a);
00064         }
00065 };
00066 
00067 template<>
00068 class objectize<lint> : public object {
00069 private:
00070         const lint value;
00071 protected:
00072         objectize(lint a_value) : value(a_value)
00073         {}
00074 public:
00075         static ptr< objectize<lint> > create(lint a_value)
00076         {
00077                 return new objectize<lint>(a_value);
00078         }
00079         virtual void accept_dumper_visitor( ptr<dumper_visitor> v )
00080         {
00081                 return v->visit_lint(value);
00082         }
00083 };
00084 
00085 template<>
00086 class objectize<ulint> : public object {
00087 private:
00088         const ulint value;
00089 protected:
00090         objectize(ulint a_value) : value(a_value)
00091         {}
00092 public:
00093         static ptr< objectize<ulint> > create(ulint a_value)
00094         {
00095                 return new objectize<ulint>(a_value);
00096         }
00097         virtual void accept_dumper_visitor( ptr<dumper_visitor> v )
00098         {
00099                 return v->visit_ulint(value);
00100         }
00101 };
00102 
00103 template<>
00104 class objectize<bool> : public object {
00105 private:
00106         const bool value;
00107 protected:
00108         objectize(bool a_value) : value(a_value)
00109         {}
00110 public:
00111         static ptr< objectize<bool> > create(bool a_value)
00112         {
00113                 return new objectize<bool>(a_value);
00114         }
00115         virtual void accept_dumper_visitor( ptr<dumper_visitor> v )
00116         {
00117                 return v->visit_bool(value);
00118         }
00119 };
00120 
00121 template<>
00122 class objectize<lstring> : public object {
00123 private:
00124         const lstring value;
00125 protected:
00126         objectize(const lstring &a_value) : value(a_value)
00127         {}
00128 public:
00129         static ptr< objectize<lstring> > create(const lstring &a_value)
00130         {
00131                 return new objectize<lstring>(a_value);
00132         }
00133         virtual void accept_dumper_visitor( ptr<dumper_visitor> v )
00134         {
00135                 return v->visit_lstring(value);
00136         }
00137 };
00138 
00139 template<>
00140 class objectize<ucn_string> : public object {
00141 private:
00142         const ucn_string value;
00143 protected:
00144         objectize(const ucn_string &a_value) : value(a_value)
00145         {}
00146 public:
00147         static ptr< objectize<ucn_string> > create(const ucn_string &a_value)
00148         {
00149                 return new objectize<ucn_string>(a_value);
00150         }
00151         virtual void accept_dumper_visitor( ptr<dumper_visitor> v )
00152         {
00153                 return v->visit_ucn_string(value);
00154         }
00155 };
00156 
00157 end_package(std);
00158 end_package(lestes);
00159 
00160 #endif  // lestes__std___objectize_hh___included

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