conexus logo

factory.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the conexus library.                             *
00006  *                                                                         *
00007  *   The conexus library is free software; you can redistribute it and/or  *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The conexus library is distributed in the hope that it will be        *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef CONEXUSFACTORY_H
00020 #define CONEXUSFACTORY_H
00021 
00022 #include <set>
00023 #include <map>
00024 
00025 #include <sigc++/sigc++.h>
00026 
00027 #include <conexus/endpoint.h>
00028 #include <conexus/endpointserver.h>
00029 #include <conexus/pointer.h>
00030 #include <conexus/registry.h>
00031 
00040 namespace Conexus
00041 {
00042 
00046   class Factory : public sigc::trackable
00047   {
00048     public:
00049 
00050       typedef ConexusPointer<Factory> pointer;
00051 
00052       typedef Endpoint::pointer(*EndpointCreator)();
00053 
00054       typedef EndpointServer::pointer(*EndpointServerCreator)();
00055 
00056       typedef std::set<std::string> Names;
00057 
00058       typedef std::map<unsigned long,std::string> IndexNameMap;
00059 
00060       typedef std::map<std::string,unsigned long> NameIndexMap;
00061 
00062       Factory();
00063 
00064       static pointer create();
00065 
00066       ~Factory();
00067 
00068       const Names& names();
00069 
00070       const IndexNameMap& index_name_map();
00071 
00072       const NameIndexMap& name_index_map();
00073 
00074       unsigned long index ( const std::string& name );
00075 
00076       unsigned long index ( EndpointCreator cr );
00077 
00078       unsigned long index( EndpointServerCreator cr );
00079 
00080       std::string name ( unsigned long index );
00081 
00082       std::string name ( EndpointCreator cr );
00083 
00084       std::string name( EndpointServerCreator cr );
00085 
00091       unsigned long add ( const std::string& name, EndpointCreator cr, unsigned long index=0 );
00092 
00098       unsigned long add ( const std::string& name, EndpointServerCreator cr, unsigned long index=0 );
00099 
00100       bool remove ( unsigned long index );
00101 
00102       bool remove ( const std::string& name );
00103 
00104       bool remove ( EndpointCreator cr );
00105 
00106       bool remove ( EndpointServerCreator cr );
00107 
00108       Endpoint::pointer create_endpoint( unsigned long index, const std::string& instance_name=std::string() );
00109 
00110       Endpoint::pointer create_endpoint( const std::string& class_name, const std::string& instance_name=std::string() );
00111 
00112       EndpointServer::pointer create_server( unsigned long index, const std::string& instance_name=std::string() );
00113 
00114       EndpointServer::pointer create_server( const std::string& class_name, const std::string& instance_name=std::string() );
00115 
00116       Object::pointer create( unsigned long index, const std::string& instance_name=std::string() );
00117 
00118       Object::pointer create( const std::string& class_name, const std::string& instance_name=std::string() );
00119 
00120       sigc::signal<void,const std::string&> signal_added();
00121 
00122       sigc::signal<void,const std::string&> signal_removed();
00123 
00124       Registry& registry();
00125 
00126       void set_registry( Registry::pointer registry );
00127 
00128     protected:
00129 
00130       typedef std::map<unsigned long,EndpointCreator> IndexCreatorMap;
00131       typedef std::map<std::string,EndpointCreator> NameCreatorMap;
00132       typedef std::map<unsigned long,EndpointServerCreator> IndexServerCreatorMap;
00133       typedef std::map<std::string,EndpointServerCreator> NameServerCreatorMap;
00134 
00135       Names m_names;
00136       IndexCreatorMap m_index_creator;
00137       NameCreatorMap m_name_creator;
00138       IndexServerCreatorMap m_index_servercreator;
00139       NameServerCreatorMap m_name_servercreator;
00140       IndexNameMap m_index_name;
00141       NameIndexMap m_name_index;
00142       Registry::pointer m_registry;
00143 
00144       sigc::signal<void,const std::string&> m_signal_added;
00145 
00146       sigc::signal<void,const std::string&> m_signal_removed;
00147 
00148   };
00149 
00150 }
00151 
00152 #endif

Generated on Wed Jul 8 15:50:07 2009 for conexus by doxygen 1.5.8