factory.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef IDIOSKOPOSFACTORY_H
00020 #define IDIOSKOPOSFACTORY_H
00021 
00022 #include <libxml++/libxml++.h>
00023 #include <glibmm.h>
00024 #include <idioskopos/object.h>
00025 
00026 namespace Idioskopos
00027 {
00028   class Object;
00029 
00031   void xml_property_factory_init();
00032 
00034   const Glib::ustring& xml_dtd(bool as_inline=false, bool with_header=false);
00035 
00037   void register_property_factory_type( const Glib::ustring& class_name,
00038                                        const Glib::ustring& value_type,
00039                                        sigc::slot<Object::pointer> slot );
00040 
00042   void unregister_property_factory_type( const Glib::ustring& class_name,
00043                                          const Glib::ustring& value_type );
00044 
00046   void register_introspectable_factory_type( const Glib::ustring& class_name,
00047                                              sigc::slot<Object::pointer> slot );
00048 
00050   void unregister_introspectable_factory_type( const Glib::ustring& class_name );
00051 
00057   Object::pointer xml_factory_create( const Glib::ustring& xml_initialization );
00058 
00064   Object::pointer xml_factory_create( const xmlpp::Node* n );
00065 
00071   Object::pointer xml_property_factory_create( const xmlpp::Node* n );
00072 
00078   Object::pointer xml_introspectable_factory_create( const xmlpp::Node* n );
00079 
00080 }
00081 
00086 #define IDIOSKOPOS_OBJECT_AND_REGISTRAR(idioskopos_name)                                     \
00087   virtual const Glib::ustring& class_name() const {                                          \
00088     static Glib::ustring s = (#idioskopos_name);                                             \
00089     return (s);                                                                              \
00090   }                                                                                          \
00091                                                                                              \
00092   static Idioskopos::Object::pointer create_object() {                                       \
00093     return Idioskopos::Object::pointer( new idioskopos_name(Glib::ustring()) );              \
00094   }                                                                                          \
00095                                                                                              \
00096   struct idioskopos_registrar {                                                              \
00097     idioskopos_registrar() {                                                                 \
00098       static bool initialized = false;                                                       \
00099       if ( ! initialized )                                                                   \
00100         register_introspectable_factory_type(#idioskopos_name,                               \
00101                                              sigc::ptr_fun(idioskopos_name::create_object)); \
00102       initialized = true;                                                                    \
00103     }                                                                                        \
00104   };                                                                                         \
00105                                                                                              \
00106   static idioskopos_registrar idioskopos_name ## _idioskopos_registrar_static
00107 
00113 #define IDIOSKOPOS_OBJECT_NAME_AND_REGISTRAR(idioskopos_name, idioskopos_strname)            \
00114   virtual const Glib::ustring& class_name() const {                                          \
00115     static Glib::ustring s = (#idioskopos_strname);                                          \
00116     return (s);                                                                              \
00117   }                                                                                          \
00118                                                                                              \
00119   static Idioskopos::Object::pointer create_object() {                                       \
00120     return Idioskopos::Object::pointer( new idioskopos_name(Glib::ustring()) );              \
00121   }                                                                                          \
00122                                                                                              \
00123   struct idioskopos_registrar {                                                              \
00124     idioskopos_registrar() {                                                                 \
00125       static bool initialized = false;                                                       \
00126       if ( ! initialized )                                                                   \
00127         register_introspectable_factory_type(#idioskopos_strname,                            \
00128                                              sigc::ptr_fun(idioskopos_name::create_object)); \
00129       initialized = true;                                                                    \
00130     }                                                                                        \
00131   };                                                                                         \
00132                                                                                              \
00133   static idioskopos_registrar idioskopos_name ## _idioskopos_registrar_static
00134 
00140 #define IDIOSKOPOS_OBJECT_NAME_SLOT_AND_REGISTRAR(idioskopos_name, idioskopos_strname, idioskopos_create_slot) \
00141   virtual const Glib::ustring& class_name() const {                                                            \
00142     static Glib::ustring s = (#idioskopos_strname);                                                            \
00143     return (s);                                                                                                \
00144   }                                                                                                            \
00145                                                                                                                \
00146   struct idioskopos_registrar {                                                                                \
00147     idioskopos_registrar() {                                                                                   \
00148       static bool initialized = false;                                                                         \
00149       if ( ! initialized )                                                                                     \
00150         register_introspectable_factory_type(#idioskopos_strname, idioskopos_create_slot);                     \
00151       initialized = true;                                                                                      \
00152 }                                                                                                              \
00153 };                                                                                                             \
00154                                                                                                                \
00155   static idioskopos_registrar idioskopos_name ## _idioskopos_registrar_static
00156 
00157 #define IDIOSKOPOS_REGISTRAR(idioskopos_name)                                             \
00158   idioskopos_name::idioskopos_registrar idioskopos_name ## _idioskopos_registrar_static
00159 
00160 
00161 #endif

Generated on Thu Jan 11 00:26:41 2007 by  doxygen 1.5.1