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