OpenWalnut  1.3.1
WModuleProjectFileCombiner.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 WMODULEPROJECTFILECOMBINER_H
26 #define WMODULEPROJECTFILECOMBINER_H
27 
28 #include <ostream>
29 #include <list>
30 #include <map>
31 #include <string>
32 #include <utility>
33 
34 #include <boost/shared_ptr.hpp>
35 
36 #include "../../common/WProjectFileIO.h"
37 
38 #include "../WModuleCombiner.h"
39 
40 
41 
42 /**
43  * This class is able to parse project files and create the appropriate module graph inside a specified container. It is also derived from
44  * WProjectFileIO to allow WProjectFile to fill this combiner.
45  */
47  public WProjectFileIO
48 {
49 public:
50  /**
51  * Creates an empty combiner.
52  *
53  * \param target the target container where to add the modules to.
54  */
55  explicit WModuleProjectFileCombiner( boost::shared_ptr< WModuleContainer > target );
56 
57  /**
58  * Creates an empty combiner. This constructor automatically uses the kernel's root container as target container.
59  */
61 
62  /**
63  * Destructor.
64  */
66 
67  /**
68  * Apply the internal module structure to the target container. Be aware, that this operation might take some time, as modules can be
69  * connected only if they are "ready", which, at least with WDataModule modules, might take some time. It applies the loaded project file.
70  *
71  * \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
72  * thrown whenever the file could not be opened.
73  *
74  * \throw WFileNotFound whenever the project file could not be opened.
75  */
76  virtual void apply();
77 
78  /**
79  * This method parses the specified line and interprets it to fill the internal module graph structure.
80  *
81  * \param line the current line as string
82  * \param lineNumber the current line number. Useful for error/warning/debugging output.
83  *
84  * \return true if the line could be parsed.
85  */
86  virtual bool parse( std::string line, unsigned int lineNumber );
87 
88  /**
89  * Called whenever the end of the project file has been reached. This is useful if your specific parser class wants to do some post
90  * processing after parsing line by line.
91  */
92  virtual void done();
93 
94  /**
95  * Saves the state to the specified stream.
96  *
97  * \param output the stream to print the state to.
98  */
99  virtual void save( std::ostream& output ); // NOLINT
100 
101 protected:
102  /**
103  * The module ID type. A pair of ID and pointer to module.
104  */
105  typedef std::pair< unsigned int, boost::shared_ptr< WModule > > ModuleID;
106 
107  /**
108  * All Modules.
109  */
110  std::map< unsigned int, boost::shared_ptr< WModule > > m_modules;
111 
112  /**
113  * A connector is described by ID and name.
114  */
115  typedef std::pair< unsigned int, std::string > Connector;
116 
117  /**
118  * A connection is a pair of connectors.
119  */
120  typedef std::pair< Connector, Connector > Connection;
121 
122  /**
123  * All connections.
124  */
125  std::list< Connection > m_connections;
126 
127  /**
128  * A property is a pair of ID and name.
129  */
130  typedef std::pair< unsigned int, std::string > Property;
131 
132  /**
133  * A property value is a property and the new value as string.
134  */
135  typedef std::pair< Property, std::string > PropertyValue;
136 
137  /**
138  * All properties.
139  */
140  std::list< PropertyValue > m_properties;
141 
142  /**
143  * Recursively prints the properties and nested properties.
144  *
145  * \param output the output stream to print to
146  * \param props the properties to recursively print
147  * \param indent the indentation level
148  * \param prefix the prefix (name prefix of property)
149  * \param module the module ID to use
150  */
151  void printProperties( std::ostream& output, boost::shared_ptr< WProperties > props, std::string indent, //NOLINT ( non-const ref )
152  std::string prefix, unsigned int module );
153 
154 private:
155 };
156 
157 #endif // WMODULEPROJECTFILECOMBINER_H
158