OpenWalnut 1.2.5
WProjectFile.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 WPROJECTFILE_H
00026 #define WPROJECTFILE_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 // Use filesystem version 2 for compatibility with newer boost versions.
00032 #ifndef BOOST_FILESYSTEM_VERSION
00033     #define BOOST_FILESYSTEM_VERSION 2
00034 #endif
00035 #include <boost/filesystem.hpp>
00036 #include <boost/shared_ptr.hpp>
00037 
00038 #include "../common/WProjectFileIO.h"
00039 #include "WExportKernel.h"
00040 
00041 /**
00042  * 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
00043  * WProjectFileIO instances which then do their job.
00044  */
00045 class OWKERNEL_EXPORT WProjectFile: public WThreadedRunner,
00046                                       public boost::enable_shared_from_this< WProjectFile >
00047 {
00048 public:
00049 
00050     /**
00051      * Default constructor. It does NOT parse the file. Parsing is done by apply().
00052      *
00053      * \param project the project file to load.
00054      */
00055     explicit WProjectFile( boost::filesystem::path project );
00056 
00057     /**
00058      * Destructor.
00059      */
00060     virtual ~WProjectFile();
00061 
00062     /**
00063      * Parses the project file and applies it. It applies the project file asynchronously!
00064      */
00065     virtual void load();
00066 
00067     /**
00068      * Saves the current state to the file specified in the constructor.
00069      */
00070     virtual void save();
00071 
00072     /**
00073      * Saves the current state to the file specified in the constructor. This also supports a custom list of writers. This is useful to only
00074      * write some parts of the state.
00075      *
00076      * \param writer the list of writers to use.
00077      */
00078     virtual void save( const std::vector< boost::shared_ptr< WProjectFileIO > >& writer );
00079 
00080     /**
00081      * Returns an instance of the Camera writer.
00082      *
00083      * \return the writer able to output the camera configuration to a stream.
00084      */
00085     static boost::shared_ptr< WProjectFileIO > getCameraWriter();
00086 
00087     /**
00088      * Returns an instance of the module writer.
00089      *
00090      * \return the writer able to output the module configuration to a stream.
00091      */
00092     static boost::shared_ptr< WProjectFileIO > getModuleWriter();
00093 
00094     /**
00095      * Returns an instance of the ROI writer.
00096      *
00097      * \return the writer able to output the ROI configuration to a stream.
00098      */
00099     static boost::shared_ptr< WProjectFileIO > getROIWriter();
00100 
00101 protected:
00102 
00103     /**
00104      * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
00105      * has been called.
00106      */
00107     virtual void threadMain();
00108 
00109     /**
00110      * The project file to parse.
00111      */
00112     boost::filesystem::path m_project;
00113 
00114     /**
00115      * The parser instances. They are used to parse the file.
00116      */
00117     std::vector< boost::shared_ptr< WProjectFileIO > > m_parsers;
00118 
00119 private:
00120 };
00121 
00122 #endif  // WPROJECTFILE_H
00123 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends