~ubuntu-branches/ubuntu/wily/openwalnut/wily-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WROIPROJECTFILEIO_H
#define WROIPROJECTFILEIO_H

#include <string>
#include <vector>
#include <map>

#include "boost/tuple/tuple.hpp"

#include "../common/WProjectFileIO.h"

class WProjectFile;

/**
 * IO Class for writing the ROI structure to a project file.
 */
class  WRoiProjectFileIO: public WProjectFileIO
{
public:
    /**
     * Default constructor.
     */
    WRoiProjectFileIO();

    /**
     * Destructor.
     */
    virtual ~WRoiProjectFileIO();

    /**
     * This method parses the specified line and interprets it. It gets called line by line by WProjectFile.
     *
     * \param line the current line as string
     * \param lineNumber the current line number. Useful for error/warning/debugging output.
     *
     * \return true if the line could be parsed.
     */
    virtual bool parse( std::string line, unsigned int lineNumber );

    /**
     * Called whenever the end of the project file has been reached. This is useful if your specific parser class wants to do some post
     * processing after parsing line by line.
     */
    virtual void done();

    /**
     * Saves the state to the specified stream.
     *
     * \param output the stream to print the state to.
     */
    virtual void save( std::ostream& output );   // NOLINT

    /**
     * Create a clone of the IO. This is especially useful for custom parsers registered at \ref WProjectFile::registerParser. Implement this
     * function.
     *
     * \param project the project file using this parser instance.
     *
     * \return Cloned instance.
     */
    virtual SPtr clone( WProjectFile* project ) const;

protected:
private:
    /**
     * Branch by ID
     */
    typedef unsigned int Branch;

    /**
     * Property for branch/roi with ID. Property name and value are stored as string
     */
    typedef boost::tuple< std::string, std::string > Property;

    /**
     * The properties as vector.
     */
    typedef std::vector< Property > Properties;

    /**
     * All loaded branch IDs
     */
    std::vector< Branch > m_branches;

    /**
     * Properties of each branch
     */
    std::map< Branch, Properties > m_branchProperties;

    /**
     * ID of a ROI
     */
    typedef unsigned int RoiID;

    /**
     * ROI by ID, second is parent branch ID
     */
    typedef boost::tuple< RoiID, Branch > Roi;

    /**
     * All loaded rois
     */
    std::vector< Roi > m_rois;

    /**
     * Properties of each branch
     */
    std::map< RoiID, Properties > m_roiProperties;
};

#endif  // WROIPROJECTFILEIO_H