Define CanvasParser::show_canvas_map() when _DEBUG is defined.
[synfig.git] / synfig-core / trunk / src / synfig / loadcanvas.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file loadcanvas.h
3 **      \brief writeme
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_LOADCANVAS_H
27 #define __SYNFIG_LOADCANVAS_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include "string.h"
32 #include "canvas.h"
33 #include "valuenode.h"
34 #include "vector.h"
35 #include "value.h"
36 #include "valuenode_subtract.h"
37 #include "valuenode_animated.h"
38 #include "valuenode_composite.h"
39 #include "valuenode_dynamiclist.h"
40 #include "keyframe.h"
41 #include "guid.h"
42
43 /* === M A C R O S ========================================================= */
44
45 /* === T Y P E D E F S ===================================================== */
46
47 /* === C L A S S E S & S T R U C T S ======================================= */
48
49 namespace xmlpp { class Node; class Element; };
50
51 namespace synfig {
52
53 /*!     \class CanvasParser
54 **      \todo writeme
55 */
56 class CanvasParser
57 {
58         /*
59  --     ** -- D A T A -------------------------------------------------------------
60         */
61
62 private:
63
64         int max_warnings_;
65
66     int total_warnings_;
67
68     int total_errors_;
69
70         bool allow_errors_;
71
72         String filename;
73
74         String path;
75
76         String errors_text;
77         String warnings_text;
78
79         GUID guid_;
80
81         /*
82  --     ** -- C O N S T R U C T O R S ---------------------------------------------
83         */
84
85 public:
86
87         CanvasParser():
88                 max_warnings_   (1000),
89                 total_warnings_ (0),
90                 total_errors_   (0),
91                 allow_errors_   (false)
92         { }
93
94         /*
95  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
96         */
97
98 public:
99
100         //! \todo writeme
101         CanvasParser &set_allow_errors(bool x) { allow_errors_=x; return *this; }
102
103         //! Sets the maximum number of warnings before a fatal error is thrown
104         CanvasParser &set_max_warnings(int i) { max_warnings_=i; return *this; }
105
106         //! Returns the maximum number of warnings before a fatal_error is thrown
107         int get_max_warnings() { return max_warnings_; }
108
109         //! Returns the number of errors in the last parse
110         int error_count()const { return total_errors_; }
111
112         //! Returns the number of warnings in the last parse
113         int warning_count()const { return total_warnings_; }
114
115         void set_path(const synfig::String& x) { path=x; }
116
117         const synfig::String& get_path()const { return path; }
118
119         const synfig::String& get_errors_text()const { return errors_text; }
120         const synfig::String& get_warnings_text()const { return warnings_text; }
121
122         static void register_canvas_in_map(Canvas::Handle canvas, String as);
123
124 #ifdef _DEBUG
125         static void show_canvas_map(String file, int line, String text);
126 #endif  // _DEBUG
127
128         //! \todo writeme
129         Canvas::Handle parse_from_file_as(const String &filename,const String &as,String &errors);
130
131         static std::set<String> loading_;
132
133 private:
134
135         // Error/Warning handling functions
136
137         void error(xmlpp::Node *node,const String &text);
138         void fatal_error(xmlpp::Node *node,const String &text);
139         void warning(xmlpp::Node *node,const String &text);
140         void error_unexpected_element(xmlpp::Node *node,const String &got, const String &expected);
141         void error_unexpected_element(xmlpp::Node *node,const String &got);
142
143         // Parsing Functions
144
145         Canvas::Handle parse_canvas(xmlpp::Element *node,Canvas::Handle parent=0,bool inline_=false, String path=".");
146         void parse_canvas_defs(xmlpp::Element *node,Canvas::Handle canvas);
147         etl::handle<Layer> parse_layer(xmlpp::Element *node,Canvas::Handle canvas);
148         ValueBase parse_value(xmlpp::Element *node,Canvas::Handle canvas);
149         etl::handle<ValueNode> parse_value_node(xmlpp::Element *node,Canvas::Handle canvas);
150
151         // ValueBase Parsing Functions
152
153         Real parse_real(xmlpp::Element *node);
154         Time parse_time(xmlpp::Element *node,Canvas::Handle canvas);
155         int parse_integer(xmlpp::Element *node);
156         Vector parse_vector(xmlpp::Element *node);
157         Color parse_color(xmlpp::Element *node);
158         Angle parse_angle(xmlpp::Element *node);
159         String parse_string(xmlpp::Element *node);
160         bool parse_bool(xmlpp::Element *node);
161         Segment parse_segment(xmlpp::Element *node);
162         ValueBase parse_list(xmlpp::Element *node,Canvas::Handle canvas);
163         Gradient parse_gradient(xmlpp::Element *node);
164         BLinePoint parse_bline_point(xmlpp::Element *node);
165
166         Keyframe parse_keyframe(xmlpp::Element *node,Canvas::Handle canvas);
167
168         // ValueNode Parsing Functions
169
170         etl::handle<ValueNode_Animated> parse_animated(xmlpp::Element *node,Canvas::Handle canvas);
171         etl::handle<ValueNode_Subtract> parse_subtract(xmlpp::Element *node,Canvas::Handle canvas);
172         etl::handle<LinkableValueNode> parse_linkable_value_node(xmlpp::Element *node,Canvas::Handle canvas);
173         etl::handle<ValueNode_DynamicList> parse_dynamic_list(xmlpp::Element *node,Canvas::Handle canvas);
174
175 }; // END of CanvasParser
176
177 /* === E X T E R N S ======================================================= */
178
179 //!     Loads a canvas from \a filename
180 /*!     \return The Canvas's handle on success, an empty handle on failure */
181 extern Canvas::Handle open_canvas(const String &filename,String &errors,String &warnings);
182 extern Canvas::Handle open_canvas_as(const String &filename,const String &as,String &errors,String &warnings);
183
184 std::map<synfig::String, etl::loose_handle<Canvas> >& get_open_canvas_map();
185
186 }; // END of namespace synfig
187
188 /* === E N D =============================================================== */
189
190 #endif