OpenWalnut  1.4.0
WRoiProjectFileIO.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 WROIPROJECTFILEIO_H
26 #define WROIPROJECTFILEIO_H
27 
28 #include <string>
29 #include <vector>
30 #include <map>
31 
32 #ifndef Q_MOC_RUN
33 #include "boost/tuple/tuple.hpp"
34 #endif
35 
36 #include "../common/WProjectFileIO.h"
37 
38 class WProjectFile;
39 
40 /**
41  * IO Class for writing the ROI structure to a project file.
42  */
44 {
45 public:
46  /**
47  * Default constructor.
48  */
50 
51  /**
52  * Destructor.
53  */
54  virtual ~WRoiProjectFileIO();
55 
56  /**
57  * This method parses the specified line and interprets it. It gets called line by line by WProjectFile.
58  *
59  * \param line the current line as string
60  * \param lineNumber the current line number. Useful for error/warning/debugging output.
61  *
62  * \return true if the line could be parsed.
63  */
64  virtual bool parse( std::string line, unsigned int lineNumber );
65 
66  /**
67  * Called whenever the end of the project file has been reached. This is useful if your specific parser class wants to do some post
68  * processing after parsing line by line.
69  */
70  virtual void done();
71 
72  /**
73  * Saves the state to the specified stream.
74  *
75  * \param output the stream to print the state to.
76  */
77  virtual void save( std::ostream& output ); // NOLINT
78 
79  /**
80  * Create a clone of the IO. This is especially useful for custom parsers registered at \ref WProjectFile::registerParser. Implement this
81  * function.
82  *
83  * \param project the project file using this parser instance.
84  *
85  * \return Cloned instance.
86  */
87  virtual SPtr clone( WProjectFile* project ) const;
88 
89 protected:
90 private:
91  /**
92  * Branch by ID
93  */
94  typedef unsigned int Branch;
95 
96  /**
97  * Property for branch/roi with ID. Property name and value are stored as string
98  */
99  typedef boost::tuple< std::string, std::string > Property;
100 
101  /**
102  * The properties as vector.
103  */
104  typedef std::vector< Property > Properties;
105 
106  /**
107  * All loaded branch IDs
108  */
109  std::vector< Branch > m_branches;
110 
111  /**
112  * Properties of each branch
113  */
114  std::map< Branch, Properties > m_branchProperties;
115 
116  /**
117  * ID of a ROI
118  */
119  typedef unsigned int RoiID;
120 
121  /**
122  * ROI by ID, second is parent branch ID
123  */
124  typedef boost::tuple< RoiID, Branch > Roi;
125 
126  /**
127  * All loaded rois
128  */
129  std::vector< Roi > m_rois;
130 
131  /**
132  * Properties of each branch
133  */
134  std::map< RoiID, Properties > m_roiProperties;
135 };
136 
137 #endif // WROIPROJECTFILEIO_H
138 
virtual bool parse(std::string line, unsigned int lineNumber)
This method parses the specified line and interprets it.
std::vector< Roi > m_rois
All loaded rois.
virtual void save(std::ostream &output)
Saves the state to the specified stream.
unsigned int Branch
Branch by ID.
virtual ~WRoiProjectFileIO()
Destructor.
Class loading project files.
Definition: WProjectFile.h:57
virtual void done()
Called whenever the end of the project file has been reached.
boost::tuple< std::string, std::string > Property
Property for branch/roi with ID.
boost::shared_ptr< WProjectFileIO > SPtr
Abbreviation for a shared pointer.
IO Class for writing the ROI structure to a project file.
unsigned int RoiID
ID of a ROI.
boost::tuple< RoiID, Branch > Roi
ROI by ID, second is parent branch ID.
A base class for all parts of OpenWalnut which can be serialized to a project file.
std::vector< Branch > m_branches
All loaded branch IDs.
std::map< RoiID, Properties > m_roiProperties
Properties of each branch.
std::map< Branch, Properties > m_branchProperties
Properties of each branch.
std::vector< Property > Properties
The properties as vector.
virtual SPtr clone(WProjectFile *project) const
Create a clone of the IO.
WRoiProjectFileIO()
Default constructor.