32 #include <boost/regex.hpp>
34 #include "../WKernel.h"
35 #include "../WModuleCombiner.h"
36 #include "../WModuleFactory.h"
37 #include "../WModuleConnector.h"
38 #include "../WModule.h"
39 #include "../WDataModule.h"
40 #include "../WModuleInputConnector.h"
41 #include "../WModuleOutputConnector.h"
42 #include "../exceptions/WModuleConnectorNotFound.h"
44 #include "../../common/exceptions/WFileNotFound.h"
45 #include "../../common/WStringUtils.h"
46 #include "../../common/WProperties.h"
47 #include "../../common/WPropertyBase.h"
48 #include "../../common/WPropertyVariable.h"
49 #include "../../common/WPropertyTypes.h"
50 #include "../../common/WLogger.h"
51 #include "../../common/math/linearAlgebra/WLinearAlgebra.h"
53 #include "WModuleProjectFileCombiner.h"
75 static const boost::regex modRe(
"^ *MODULE:([0-9]*):(.*)$" );
76 static const boost::regex dataRe(
"^ *DATA:([0-9]*):\"?([^\"]*)\"?$" );
77 static const boost::regex conRe(
"^ *CONNECTION:\\(([0-9]*),(.*)\\)->\\(([0-9]*),(.*)\\)$" );
78 static const boost::regex propRe(
"^ *PROPERTY:\\(([0-9]*),(.*)\\)=(.*)$" );
80 boost::smatch matches;
81 if( boost::regex_match( line, matches, modRe ) )
87 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Module \"" << matches[2] <<
"\" with ID " << matches[1];
95 addError(
"There is no prototype available for module \"" + matches[2] +
"\". Skipping." );
97 else if( proto->getType() == MODULE_DATA )
99 addError(
"Data modules are not allowed to be specified in a \"MODULE\" Statement. Use the \"DATA\" statement instead. Skipping." );
104 m_modules.insert(
ModuleID( string_utils::fromString< unsigned int >( matches[1] ), module ) );
107 else if( boost::regex_match( line, matches, dataRe ) )
112 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Data \"" << matches[2] <<
"\" with ID " << matches[1];
118 addError(
"There is no prototype available for module \"Data Module\". This should not happen!. Skipping." );
122 std::string parameter = std::string( matches[2] );
124 if( parameter.empty() )
126 addError(
"Data modules need an additional filename parameter. Skipping." );
130 boost::shared_static_cast<
WDataModule >( module )->setFilename( parameter );
131 m_modules.insert(
ModuleID( string_utils::fromString< unsigned int >( matches[1] ), module ) );
135 else if( boost::regex_match( line, matches, conRe ) )
141 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Connection between \"" << matches[2] <<
"\" of module "
142 << matches[1] <<
" and \"" << matches[4] <<
"\" of module " << matches[3] <<
".";
146 Connector( string_utils::fromString< unsigned int >( matches[3] ), matches[4] ) ) );
148 else if( boost::regex_match( line, matches, propRe ) )
155 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Property \"" << matches[2] <<
"\" of module " << matches[1]
156 <<
" set to " << matches[3];
171 for( std::map<
unsigned int, boost::shared_ptr< WModule > >::const_iterator iter =
m_modules.begin(); iter !=
m_modules.end(); ++iter )
178 for( std::map<
unsigned int, boost::shared_ptr< WModule > >::iterator iter =
m_modules.begin(); iter !=
m_modules.end(); ++iter )
180 ( *iter ).second->isReadyOrCrashed().wait();
183 if( ( *iter ).second->isCrashed()() )
185 addError(
"In the module with ID " + ( *iter ).first +
186 std::string(
" a problem occurred. Connections and properties relating to this module will fail." ) );
195 if( !
m_modules.count( ( *iter ).first.first ) )
198 ( *iter ).first.second + std::string(
"\" for. Skipping." ) );
201 boost::shared_ptr< WModule > m =
m_modules[ ( *iter ).first.first ];
204 boost::shared_ptr< WPropertyBase > prop = m->getProperties()->findProperty( ( *iter ).first.second );
207 addError(
"The module \"" + m->getName() + std::string(
"\" has no property named \"" ) + ( *iter ).first.second +
208 std::string(
"\". Skipping." ) );
213 if( prop->getPurpose() != PV_PURPOSE_INFORMATION )
216 bool result = prop->setAsString( ( *iter ).second );
219 addError(
"Failed to set property " + ( *iter ).first.second +
" in module \"" + m->getName() +
"\"." );
224 addError(
"The module \"" + m->getName() +
"\" has a property named \"" +
225 ( *iter ).first.second +
"\" which is an INFORMATION property. Skipping." );
239 boost::shared_ptr< WModule > m1;
244 c2.second +
"). Skipping." );
249 boost::shared_ptr< WModule > m2;
254 "," + c2.second +
"). Skipping." );
263 boost::shared_ptr< WModuleOutputConnector > con1;
266 con1 = m1->getOutputConnector( c1.second );
270 addError(
"There is no output connector \"" + c1.second +
"\" in module \"" + m1->getName() +
"\"" );
273 boost::shared_ptr< WModuleInputConnector > con2;
276 con2 = m2->getInputConnector( c2.second );
280 addError(
"There is no input connector \"" + c2.second +
"\" in module \"" + m2->getName() +
"\"" );
287 con1->connect( con2 );
293 ") could not be created. Incompatible connectors?. Skipping." );
310 std::string prefix,
unsigned int module )
315 output << indent <<
"// Property Group: " << props->getName() << std::endl;
321 if( ( *iter )->getPurpose () == PV_PURPOSE_INFORMATION )
325 if( ( *iter )->getType() != PV_GROUP )
327 output << indent +
" " <<
"PROPERTY:(" << module <<
"," << prefix + ( *iter )->getName() <<
")="
328 << ( *iter )->getAsString() << std::endl;
335 printProperties( output, ( *iter )->toPropGroup(), indent +
" ", ( *iter )->getName() +
"/", module );
339 printProperties( output, ( *iter )->toPropGroup(), indent +
" ", prefix + ( *iter )->getName() +
"/", module );
344 output << indent <<
"// Property Group END: " << props->getName() << std::endl;
352 std::map< boost::shared_ptr< WModule >,
unsigned int > moduleToIDMap;
354 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
355 "// Modules and Properties" << std::endl <<
356 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
364 moduleToIDMap[ ( *iter ) ] = i;
367 if( ( *iter )->getType() == MODULE_DATA )
369 output <<
"DATA:" << i <<
":" << boost::shared_static_cast<
WDataModule >( ( *iter ) )->getFilename().string() << std::endl;
373 output <<
"MODULE:" << i <<
":" << ( *iter )->
getName() << std::endl;
385 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
386 "// Connections" << std::endl <<
387 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
396 for( WModule::OutputConnectorList::const_iterator citer = outs.begin(); citer != outs.end(); ++citer )
399 boost::unique_lock<boost::shared_mutex> lock( ( *citer )->m_connectionListLock );
400 for( std::set<boost::shared_ptr<WModuleConnector> >::const_iterator iciter = ( *citer )->m_connected.begin();
401 iciter != ( *citer )->m_connected.end(); ++iciter )
404 boost::shared_ptr< WModule > theOtherModule = ( *iciter )->m_module.lock();
405 output <<
"CONNECTION:(" << moduleToIDMap[ ( *iter ) ] <<
"," << ( *citer )->getName() <<
")->(" <<
406 moduleToIDMap[ theOtherModule ] <<
"," << ( *iciter )->getName() <<
")" << std::endl;