OpenWalnut  1.3.1
WBatchLoader.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 #include <vector>
27 
28 #include "WModule.h"
29 #include "WModuleContainer.h"
30 #include "WModuleFactory.h"
31 
32 #include "WBatchLoader.h"
33 
34 WBatchLoader::WBatchLoader( std::vector< std::string > filenames, boost::shared_ptr< WModuleContainer > targetContainer ):
37  m_filenamesToLoad( filenames ),
38  m_targetContainer( targetContainer ),
39  m_suppressColormaps( false )
40 {
41  // initialize members
42 }
43 
45 {
46  // cleanup
47 }
48 
50 {
51  // the module needs to be added here, as it else could be freed before the thread finishes ( remember: it is a shared_ptr).
52  m_targetContainer->addPendingThread( shared_from_this() );
53 
54  // actually run
56 }
57 
59 {
60  // add a new data module for each file to load
61  for( std::vector< std::string >::iterator iter = m_filenamesToLoad.begin(); iter != m_filenamesToLoad.end(); ++iter )
62  {
63  boost::shared_ptr< WModule > mod = WModuleFactory::getModuleFactory()->create(
64  WModuleFactory::getModuleFactory()->getPrototypeByName( "Data Module" )
65  );
66  WDataModule::SPtr dmod = boost::shared_static_cast< WDataModule >( mod );
68 
69  // set the filename
70  dmod->setFilename( *iter );
71 
72  m_targetContainer->add( mod );
73  // serialize loading of a couple of data sets
74  // ignore the case where isCrashed is true
75  mod->isReadyOrCrashed().wait();
76 
77  // add module to the list
78  m_dataModules.push_back( dmod );
79  }
80 
81  m_targetContainer->finishedPendingThread( shared_from_this() );
82 }
83 
85 {
87 }
88 
90 {
91  m_suppressColormaps = suppress;
92 }
93 
95 {
96  return m_suppressColormaps;
97 }
98