OpenWalnut  1.5.0dev
WMTemplateDataLoader.h
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 #ifndef WMTEMPLATEDATALOADER_H
26 #define WMTEMPLATEDATALOADER_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include "core/dataHandler/WDataSetScalar.h"
33 #include "core/kernel/WDataModule.h"
34 #include "core/kernel/WModuleOutputData.h"
35 
36 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37 // If you want to learn how to program a module, refer to WMTemplate.cpp. It is an extensive tutorial on all the details.
38 // In this tutorial, we assume you already know how to write modules. For other examples, refer to the README file.
39 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40 
41 /**
42  * \class WMTemplateDataLoader
43  *
44  * A module that explains the data loader module interface in OpenWalnut. The first important point here: derive from WDataModule.
45  *
46  * Now, please read the C++ code.
47  *
48  * \ingroup modules
49  */
51 {
52 public:
53  /**
54  * Constuctor.
55  */
57 
58  /**
59  * Destructor.
60  */
61  virtual ~WMTemplateDataLoader();
62 
63  /**
64  * Gives back the name of this module.
65  * \return the module's name.
66  */
67  virtual const std::string getName() const;
68 
69  /**
70  * Gives back a description of this module.
71  * \return description to module.
72  */
73  virtual const std::string getDescription() const;
74 
75  /**
76  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
77  * should never be initialized or modified in some other way. A simple new instance is required.
78  *
79  * \return the prototype used to create every module in OpenWalnut.
80  */
81  virtual std::shared_ptr< WModule > factory() const;
82 
83  /**
84  * Define a list of file filters we support.
85  *
86  * \return the list of filters
87  */
88  virtual std::vector< WDataModuleInputFilter::ConstSPtr > getInputFilter() const;
89 
90 protected:
91  /**
92  * Entry point after loading the module. Runs in separate thread.
93  */
94  virtual void moduleMain();
95 
96  /**
97  * Initialize the connectors this module is using.
98  */
99  virtual void connectors();
100 
101  /**
102  * Initialize the properties for this module.
103  */
104  virtual void properties();
105 
106  /**
107  * This contains the code to load the data.
108  */
109  virtual void load();
110 
111  /**
112  * Handle a newly set input. Implement this method to load the newly set input. You can get the input using the \ref getInput and \ref getInputAs
113  * methods. Please remember that it is possible to get a NULL pointer here.
114  * This happens when the user explicitly sets no input. In this case, you should clean up and reset your output connectors.
115  *
116  * \note it is very important to NOT load the data inside of this method. It is usually called in the GUI thread. This would block the whole GUI.
117  * Instead, use this method for firing a condition, which then wakes your module thread.
118  */
119  virtual void handleInputChange();
120 
121 private:
122  /**
123  * The output connector for the data.
124  */
125  std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output;
126 
127  /**
128  * A condition used to notify about changes in several properties.
129  */
130  std::shared_ptr< WCondition > m_propCondition;
131 
132  /**
133  * True if the load function needs to be called. Usually set by handleInputChange or the reload trigger
134  */
135  bool m_reload;
136 };
137 
138 #endif // WMTEMPLATEDATALOADER_H
Base for all data loader modules.
Definition: WDataModule.h:47
A module that explains the data loader module interface in OpenWalnut.
virtual void handleInputChange()
Handle a newly set input.
virtual void connectors()
Initialize the connectors this module is using.
virtual ~WMTemplateDataLoader()
Destructor.
virtual void load()
This contains the code to load the data.
virtual std::vector< WDataModuleInputFilter::ConstSPtr > getInputFilter() const
Define a list of file filters we support.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual void properties()
Initialize the properties for this module.
bool m_reload
True if the load function needs to be called.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
The output connector for the data.
virtual const std::string getName() const
Gives back the name of this module.
virtual const std::string getDescription() const
Gives back a description of this module.