OpenWalnut
1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut 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 Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WAPPLYCOMBINER_H 00026 #define WAPPLYCOMBINER_H 00027 00028 #include <list> 00029 #include <map> 00030 #include <string> 00031 #include <utility> 00032 00033 #include <boost/shared_ptr.hpp> 00034 00035 #include "../WModule.h" 00036 #include "../WModuleCombinerTypes.h" 00037 #include "WModuleOneToOneCombiner.h" 00038 00039 #include "../WModuleInputConnector.h" 00040 #include "../WModuleOutputConnector.h" 00041 00042 #include "../WExportKernel.h" 00043 /** 00044 * Base class for all combiners which apply one connection between two connectors of two modules. 00045 */ 00046 class OWKERNEL_EXPORT WApplyCombiner: public WModuleOneToOneCombiner 00047 { 00048 public: 00049 00050 /** 00051 * Creates a combiner which sets up the specified modules and prototype combination. Specifying a NULL pointer to the srcModule parameter 00052 * causes the combiner to only add the target module without any connections. This is especially useful for modules which do not provide any 00053 * input which must be connected. It is possible to specify prototypes here. The will get created upon apply. 00054 * 00055 * 00056 * \param target the target container 00057 * \param srcModule the module whose output should be connected with the prototypes input 00058 * \param srcConnector the output connector of the module 00059 * \param targetModule the module/prototype to use for connecting the module with 00060 * \param targetConnector the input connector of the prototype to connect with srcConnector. 00061 */ 00062 WApplyCombiner( boost::shared_ptr< WModuleContainer > target, 00063 boost::shared_ptr< WModule > srcModule, std::string srcConnector, 00064 boost::shared_ptr< WModule > targetModule, std::string targetConnector ); 00065 00066 /** 00067 * Creates a combiner which sets up the specified modules and prototype combination. This constructor automatically uses the kernel's root 00068 * container as target container. Specifying a NULL pointer to the srcModule parameter 00069 * causes the combiner to only add the target module without any connections. This is especially useful for modules which do not provide any 00070 * input which must be connected. It is possible to specify prototypes here. The will get created upon apply. 00071 * 00072 * \param srcModule the module whose output should be connected with the prototypes input 00073 * \param srcConnector the output connector of the module 00074 * \param targetModule the module/prototype to use for connecting the module with 00075 * \param targetConnector the input connector of the prototype to connect with srcConnector. 00076 */ 00077 WApplyCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector, 00078 boost::shared_ptr< WModule > targetModule, std::string targetConnector ); 00079 00080 /** 00081 * Destructor. 00082 */ 00083 virtual ~WApplyCombiner(); 00084 00085 /** 00086 * Apply the internal module structure to the target container. Be aware, that this operation might take some time, as modules can be 00087 * connected only if they are "ready", which, at least with WMData modules, might take some time. It applies the loaded project file. 00088 */ 00089 virtual void apply(); 00090 00091 /** 00092 * This method creates a list of possible combiners for connections between the specified modules. Both modules can be prototypes. 00093 * 00094 * \param module1 the first module 00095 * \param module2 the second module 00096 * 00097 * \return the list of combiner for one-to-one connections 00098 */ 00099 template < typename T > 00100 static WCombinerTypes::WOneToOneCombiners createCombinerList( boost::shared_ptr< WModule > module1, boost::shared_ptr< WModule > module2 ) 00101 { 00102 // this list contains all connections for the current module with the other one 00103 WCombinerTypes::WOneToOneCombiners lComp; 00104 00105 // get offered outputs 00106 WModule::OutputConnectorList cons = module1->getOutputConnectors(); 00107 00108 // get connectors of this prototype 00109 WModule::InputConnectorList pcons = module2->getInputConnectors(); 00110 00111 // ensure we have 1 connector 00112 if( ( pcons.size() == 0 ) || ( cons.size() == 0 ) ) 00113 { 00114 return lComp; 00115 } 00116 00117 // iterate connector list, first find all matches of the output connectors with all inputs 00118 for( WModule::OutputConnectorList::const_iterator outIter = cons.begin(); outIter != cons.end(); ++outIter ) 00119 { 00120 // now go through each input iterator of the current prototype 00121 for( WModule::InputConnectorList::const_iterator inIter = pcons.begin(); inIter != pcons.end(); ++inIter ) 00122 { 00123 // compatible? 00124 if( ( *outIter )->connectable( *inIter ) && ( *inIter )->connectable( *outIter ) ) 00125 { 00126 // create a apply-prototype combiner 00127 lComp.push_back( boost::shared_ptr< WApplyCombiner >( 00128 new T( module1, ( *outIter )->getName(), module2, ( *inIter )->getName() ) ) 00129 ); 00130 00131 // wlog::debug( "ModuleFactory" ) << ( *outIter )->getCanonicalName() << " -> " << ( *inIter )->getCanonicalName(); 00132 } 00133 } 00134 } 00135 00136 return lComp; 00137 } 00138 00139 protected: 00140 00141 private: 00142 }; 00143 00144 #endif // WAPPLYCOMBINER_H 00145