OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WProjectFile.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 WPROJECTFILE_H
26 #define WPROJECTFILE_H
27 
28 #include <string>
29 #include <vector>
30 
31 // Use filesystem version 2 for compatibility with newer boost versions.
32 #ifndef BOOST_FILESYSTEM_VERSION
33  #define BOOST_FILESYSTEM_VERSION 2
34 #endif
35 #include <boost/filesystem.hpp>
36 #include <boost/shared_ptr.hpp>
37 
38 #include "../common/WProjectFileIO.h"
39 #include "WExportKernel.h"
40 
41 /**
42  * Class loading project files. This class opens an file and reads it line by line. It delegates the actual parsing to each of the known
43  * WProjectFileIO instances which then do their job.
44  */
45 class OWKERNEL_EXPORT WProjectFile: public WThreadedRunner,
46  public boost::enable_shared_from_this< WProjectFile >
47 {
48 public:
49 
50  /**
51  * Default constructor. It does NOT parse the file. Parsing is done by apply().
52  *
53  * \param project the project file to load.
54  */
55  explicit WProjectFile( boost::filesystem::path project );
56 
57  /**
58  * Destructor.
59  */
60  virtual ~WProjectFile();
61 
62  /**
63  * Parses the project file and applies it. It applies the project file asynchronously!
64  */
65  virtual void load();
66 
67  /**
68  * Saves the current state to the file specified in the constructor.
69  */
70  virtual void save();
71 
72  /**
73  * Saves the current state to the file specified in the constructor. This also supports a custom list of writers. This is useful to only
74  * write some parts of the state.
75  *
76  * \param writer the list of writers to use.
77  */
78  virtual void save( const std::vector< boost::shared_ptr< WProjectFileIO > >& writer );
79 
80  /**
81  * Returns an instance of the Camera writer.
82  *
83  * \return the writer able to output the camera configuration to a stream.
84  */
85  static boost::shared_ptr< WProjectFileIO > getCameraWriter();
86 
87  /**
88  * Returns an instance of the module writer.
89  *
90  * \return the writer able to output the module configuration to a stream.
91  */
92  static boost::shared_ptr< WProjectFileIO > getModuleWriter();
93 
94  /**
95  * Returns an instance of the ROI writer.
96  *
97  * \return the writer able to output the ROI configuration to a stream.
98  */
99  static boost::shared_ptr< WProjectFileIO > getROIWriter();
100 
101 protected:
102 
103  /**
104  * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
105  * has been called.
106  */
107  virtual void threadMain();
108 
109  /**
110  * The project file to parse.
111  */
112  boost::filesystem::path m_project;
113 
114  /**
115  * The parser instances. They are used to parse the file.
116  */
117  std::vector< boost::shared_ptr< WProjectFileIO > > m_parsers;
118 
119 private:
120 };
121 
122 #endif // WPROJECTFILE_H
123