Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
factory.hh
Go to the documentation of this file.
00001 /* Rapicorn
00002  * Copyright (C) 2002-2006 Tim Janik
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library 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 GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * A copy of the GNU Lesser General Public License should ship along
00015  * with this library; if not, see http://www.gnu.org/copyleft/.
00016  */
00017 #ifndef __RAPICORN_FACTORY_HH__
00018 #define __RAPICORN_FACTORY_HH__
00019 
00020 #include <ui/item.hh>
00021 #include <list>
00022 
00023 namespace Rapicorn {
00024 
00025 namespace Factory {
00026 
00027 /* --- Factory API --- */
00028 typedef map<String,String>       VariableMap;
00029 typedef std::vector<String>      ArgumentList;  /* elements: key=utf8string */
00030 int /*-errno*/  parse_file       (const String           &i18n_domain,
00031                                   const String           &file_name,
00032                                   const String           &domain = "",
00033                                   vector<String>         *definitions = NULL);
00034 int /*-errno*/ parse_string      (const String           &xml_string,
00035                                   const String           &i18n_domain,
00036                                   const String           &domain = "",
00037                                   vector<String>         *definitions = NULL);
00038 ItemImpl&       create_item      (const String           &item_identifier,
00039                                   const ArgumentList     &arguments = ArgumentList(),
00040                                   const ArgumentList     &env_variables = ArgumentList());
00041 ContainerImpl&  create_container (const String           &container_identifier,
00042                                   const ArgumentList     &arguments = ArgumentList(),
00043                                   const ArgumentList     &env_variables = ArgumentList());
00044 Wind0wIface&    create_wind0w    (const String           &wind0w_identifier,
00045                                   const ArgumentList     &arguments = ArgumentList(),
00046                                   const ArgumentList     &env_variables = ArgumentList());
00047 
00048 String     factory_context_name    (FactoryContext *fc);
00049 StringList factory_context_tags    (FactoryContext *fc);
00050 bool       item_definition_is_window (const String   &item_identifier);
00051 
00052 /* --- item type registration --- */
00053 struct ItemTypeFactory : protected Deletable, protected NonCopyable {
00054   const String  qualified_type;
00055 protected:
00056   static void   register_item_factory   (const ItemTypeFactory  *itfactory);
00057   static void   sanity_check_identifier (const char             *namespaced_ident);
00058 public:
00059   explicit      ItemTypeFactory         (const char             *namespaced_ident,
00060                                          bool _isevh, bool _iscontainer, bool);
00061   virtual ItemImpl* create_item             (FactoryContext         *fc) const = 0;
00062   inline String type_name               () const { return qualified_type; }
00063   static void   initialize_factories    ();
00064   const bool iseventhandler, iscontainer;
00065 };
00066 
00067 } // Factory
00068 
00069 // namespace Rapicorn
00070 
00071 /* --- item factory template --- */
00072 template<class Type>
00073 class ItemFactory : Factory::ItemTypeFactory {
00074   virtual ItemImpl*
00075   create_item (FactoryContext *fc) const
00076   {
00077     ItemImpl *item = new Type();
00078     item->factory_context (fc);
00079     return item;
00080   }
00081 public:
00082   explicit ItemFactory (const char *namespaced_ident) :
00083     ItemTypeFactory (namespaced_ident,
00084                      TraitConvertible<EventHandler,Type>::TRUTH,
00085                      TraitConvertible<ContainerImpl,Type>::TRUTH,
00086                      TraitConvertible<int,Type>::TRUTH)
00087   {
00088     sanity_check_identifier (namespaced_ident);
00089     register_item_factory (this);
00090   }
00091 };
00092 
00093 } // Rapicorn
00094 
00095 #endif /* __RAPICORN_FACTORY_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines