f56d3ce76d7cdfd0c7eade25b35ae6ebdf0a40a1
[ardour.git] / libs / ardour / ardour / element_import_handler.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_element_import_handler_h__
22 #define __ardour_element_import_handler_h__
23
24 #include <string>
25 #include <list>
26 #include <set>
27
28 #include <boost/shared_ptr.hpp>
29
30 using std::string;
31 class XMLTree;
32
33 namespace ARDOUR {
34
35 class Session;
36 class ElementImporter;
37
38 /// Virtual interface class for element import handlers 
39 class ElementImportHandler
40 {
41   public:
42         typedef boost::shared_ptr<ElementImporter> ElementPtr;
43         typedef std::list<ElementPtr> ElementList;
44
45         /** ElementImportHandler constructor
46          * The constructor should find everything from the XML Tree it can handle
47          * and create respective Elements stored in elements.
48          *
49          * @param source XML tree to be parsed
50          * @see elements
51          */
52         ElementImportHandler (XMLTree const & source, ARDOUR::Session & session) :
53           source (source), session (session) { }
54         
55         virtual ~ElementImportHandler ();
56         
57         /** Gets a textual representation of the element type
58          * @return textual representation of element type
59          */
60         virtual string get_info () const = 0;
61         
62         /// Elements this handler handles
63         ElementList elements;
64         
65         /* For checking duplicates names against queued elements */
66         
67         /** Checks whether or not an element with some name is queued or not
68          * @param name name to check
69          * @return true if name is not used
70          */
71         bool check_name (const string & name) const;
72         
73         /// Adds name to the list of used names
74         void add_name (string name);
75         
76         /// Removes name from the list of used names
77         void remove_name (const string & name);
78         
79         /// Checks wheter or not all elements can be imported cleanly
80         static bool dirty () { return _dirty; }
81         
82         /// Sets handler dirty
83         static void set_dirty () { _dirty = true; }
84         
85         /// Checks wheter or not all elements were imported cleanly
86         static bool errors () { return _errors; }
87         
88         /// Sets handler dirty
89         static void set_errors () { _errors = true; }
90
91   protected:
92         /// Source session XML tree
93         XMLTree const &   source;
94         
95         /// Destination session
96         ARDOUR::Session & session;
97         
98         /// Session XML readability
99         static bool _dirty;
100         
101         /// Errors post initialization
102         static bool _errors;
103         
104   private:
105         /// Set of names for duplicate checking
106         std::set<string> names;
107 };
108
109 } // namespace ARDOUR
110
111 #endif