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