OpenWalnut 1.3.1
WModuleProjectFileCombiner.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 WMODULEPROJECTFILECOMBINER_H
00026 #define WMODULEPROJECTFILECOMBINER_H
00027 
00028 #include <ostream>
00029 #include <list>
00030 #include <map>
00031 #include <string>
00032 #include <utility>
00033 
00034 #include <boost/shared_ptr.hpp>
00035 
00036 #include "../../common/WProjectFileIO.h"
00037 
00038 #include "../WModuleCombiner.h"
00039 
00040 
00041 
00042 /**
00043  * This class is able to parse project files and create the appropriate module graph inside a specified container. It is also derived from
00044  * WProjectFileIO to allow WProjectFile to fill this combiner.
00045  */
00046 class  WModuleProjectFileCombiner: public WModuleCombiner,
00047                                    public WProjectFileIO
00048 {
00049 public:
00050     /**
00051      * Creates an empty combiner.
00052      *
00053      * \param target the target container where to add the modules to.
00054      */
00055     explicit WModuleProjectFileCombiner( boost::shared_ptr< WModuleContainer > target );
00056 
00057     /**
00058      * Creates an empty combiner. This constructor automatically uses the kernel's root container as target container.
00059      */
00060     WModuleProjectFileCombiner();
00061 
00062     /**
00063      * Destructor.
00064      */
00065     virtual ~WModuleProjectFileCombiner();
00066 
00067     /**
00068      * Apply the internal module structure to the target container. Be aware, that this operation might take some time, as modules can be
00069      * connected only if they are "ready", which, at least with WDataModule modules, might take some time. It applies the loaded project file.
00070      *
00071      * \note the loader for project files is very tolerant. It does not abort. It tries to load as much as possible. The only exception that gets
00072      * thrown whenever the file could not be opened.
00073      *
00074      * \throw WFileNotFound whenever the project file could not be opened.
00075      */
00076     virtual void apply();
00077 
00078     /**
00079      * This method parses the specified line and interprets it to fill the internal module graph structure.
00080      *
00081      * \param line the current line as string
00082      * \param lineNumber the current line number. Useful for error/warning/debugging output.
00083      *
00084      * \return true if the line could be parsed.
00085      */
00086     virtual bool parse( std::string line, unsigned int lineNumber );
00087 
00088     /**
00089      * Called whenever the end of the project file has been reached. This is useful if your specific parser class wants to do some post
00090      * processing after parsing line by line.
00091      */
00092     virtual void done();
00093 
00094     /**
00095      * Saves the state to the specified stream.
00096      *
00097      * \param output the stream to print the state to.
00098      */
00099     virtual void save( std::ostream& output );   // NOLINT
00100 
00101 protected:
00102     /**
00103      * The module ID type. A pair of ID and pointer to module.
00104      */
00105     typedef std::pair< unsigned int, boost::shared_ptr< WModule > > ModuleID;
00106 
00107     /**
00108      * All Modules.
00109      */
00110     std::map< unsigned int, boost::shared_ptr< WModule > > m_modules;
00111 
00112     /**
00113      * A connector is described by ID and name.
00114      */
00115     typedef std::pair< unsigned int, std::string > Connector;
00116 
00117     /**
00118      * A connection is a pair of connectors.
00119      */
00120     typedef std::pair< Connector, Connector > Connection;
00121 
00122     /**
00123      * All connections.
00124      */
00125     std::list< Connection > m_connections;
00126 
00127     /**
00128      * A property is a pair of ID and name.
00129      */
00130     typedef std::pair< unsigned int, std::string > Property;
00131 
00132     /**
00133      * A property value is a property and the new value as string.
00134      */
00135     typedef std::pair< Property, std::string > PropertyValue;
00136 
00137     /**
00138      * All properties.
00139      */
00140     std::list< PropertyValue > m_properties;
00141 
00142     /**
00143      * Recursively prints the properties and nested properties.
00144      *
00145      * \param output    the output stream to print to
00146      * \param props     the properties to recursively print
00147      * \param indent    the indentation level
00148      * \param prefix    the prefix (name prefix of property)
00149      * \param module    the module ID to use
00150      */
00151     void printProperties( std::ostream& output, boost::shared_ptr< WProperties > props, std::string indent, //NOLINT ( non-const ref )
00152                           std::string prefix, unsigned int module );
00153 
00154 private:
00155 };
00156 
00157 #endif  // WMODULEPROJECTFILECOMBINER_H
00158