OpenWalnut  1.4.0
WBatchLoader.h
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 WBATCHLOADER_H
00026 #define WBATCHLOADER_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <boost/enable_shared_from_this.hpp>
00032 #include <boost/shared_ptr.hpp>
00033 
00034 #include "../common/WThreadedRunner.h"
00035 #include "../common/WSharedSequenceContainer.h"
00036 
00037 #include "WDataModule.h"
00038 
00039 
00040 
00041 class WModuleContainer;
00042 
00043 /**
00044  * Class for loading many datasets. It runs in a separate thread.
00045  */
00046 class  WBatchLoader: public WThreadedRunner,
00047                                   public boost::enable_shared_from_this< WBatchLoader >
00048 {
00049 public:
00050     /**
00051      * Shared ptr abbreviation
00052      */
00053     typedef boost::shared_ptr< WBatchLoader > SPtr;
00054 
00055     /**
00056      * Const shared ptr abbreviation
00057      */
00058     typedef boost::shared_ptr< const WBatchLoader > ConstSPtr;
00059 
00060     /**
00061      * The type is used to store the list of data modules
00062      */
00063     typedef WSharedSequenceContainer< std::vector< WDataModule::SPtr > > DataModuleList;
00064 
00065     /**
00066      * Initializes the batchloader but does not start it. Use run().
00067      *
00068      * \param filenames the files to load.
00069      * \param targetContainer the container to which the data modules should be added.
00070      */
00071     WBatchLoader( std::vector< std::string > filenames, boost::shared_ptr< WModuleContainer > targetContainer );
00072 
00073     /**
00074      * Destructor.
00075      */
00076     virtual ~WBatchLoader();
00077 
00078     /**
00079      * Run thread and load the data.
00080      */
00081     virtual void run();
00082 
00083     /**
00084      * Returns a ticket to the list of data modules that have been added so far.
00085      *
00086      * \return the ticket
00087      */
00088     DataModuleList::ReadTicket getDataModuleList() const;
00089 
00090     /**
00091      * Allows suppression of colormap registration in data modules. This can be handy if you use data modules in a container to construct more
00092      * complex data sets from multiple input files.
00093      *
00094      * \note call this before run().
00095      *
00096      * \param suppress true if suppress
00097      */
00098     void setSuppressColormaps( bool suppress = true );
00099 
00100     /**
00101      * Checks whether suppression of colormaps is active.
00102      *
00103      * \return true if colormaps are suppressed.
00104      */
00105     bool getSuppressColormaps() const;
00106 
00107 protected:
00108     /**
00109      * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
00110      * has been called.
00111      */
00112     virtual void threadMain();
00113 
00114     /**
00115      * List of files to load.
00116      */
00117     std::vector< std::string > m_filenamesToLoad;
00118 
00119     /**
00120      * The container which later will contain the loaded datasets.
00121      */
00122     boost::shared_ptr< WModuleContainer > m_targetContainer;
00123 
00124     /**
00125      * The list of modules that have been added.
00126      */
00127     DataModuleList m_dataModules;
00128 
00129     /**
00130      * If true, data modules are instructed to suppress colormap registration.
00131      */
00132     bool m_suppressColormaps;
00133 
00134 private:
00135 };
00136 
00137 #endif  // WBATCHLOADER_H
00138