OpenWalnut  1.4.0
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 ):
36  boost::enable_shared_from_this< WBatchLoader >(),
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::static_pointer_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 
Class for loading many datasets.
Definition: WBatchLoader.h:46
Base for all data loader modules.
Definition: WDataModule.h:36
void push_back(const typename S::value_type &x)
Adds a new element at the end of the container.
virtual void run()
Run thread.
WBatchLoader(std::vector< std::string > filenames, boost::shared_ptr< WModuleContainer > targetContainer)
Initializes the batchloader but does not start it.
virtual ~WBatchLoader()
Destructor.
DataModuleList m_dataModules
The list of modules that have been added.
Definition: WBatchLoader.h:127
void setSuppressColormaps(bool suppress=true)
Allows suppression of colormap registration in data modules.
Base class for all classes needing to be executed in a separate thread.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
virtual void setSuppressColormaps(bool suppress=true)
Allows suppression of colormap registration in data modules.
Definition: WDataModule.cpp:43
boost::shared_ptr< WDataModule > SPtr
Convenience typedef for a boost::shared_ptr< WDataModule >.
Definition: WDataModule.h:42
DataModuleList::ReadTicket getDataModuleList() const
Returns a ticket to the list of data modules that have been added so far.
virtual void threadMain()
Function that has to be overwritten for execution.
bool m_suppressColormaps
If true, data modules are instructed to suppress colormap registration.
Definition: WBatchLoader.h:132
std::vector< std::string > m_filenamesToLoad
List of files to load.
Definition: WBatchLoader.h:117
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
bool getSuppressColormaps() const
Checks whether suppression of colormaps is active.
virtual void run()
Run thread and load the data.
boost::shared_ptr< WSharedObjectTicketRead< std::vector< WDataModule::SPtr > > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:62
boost::shared_ptr< WModuleContainer > m_targetContainer
The container which later will contain the loaded datasets.
Definition: WBatchLoader.h:122