Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_04 / synfig-core / src / synfig / loadcanvas.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file loadcanvas.h
3 **      \brief writeme
4 **
5 **      $Id: loadcanvas.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package 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 GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_LOADCANVAS_H
26 #define __SYNFIG_LOADCANVAS_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "string.h"
31 #include "canvas.h"
32 #include "valuenode.h"
33 #include "vector.h"
34 #include "value.h"
35 #include "valuenode_subtract.h"
36 #include "valuenode_animated.h"
37 #include "valuenode_composite.h"
38 #include "valuenode_const.h"
39 #include "valuenode_linear.h"
40 #include "valuenode_dynamiclist.h"
41 #include "valuenode_reference.h"
42 #include "valuenode_timedswap.h"
43 #include "keyframe.h"
44 #include "guid.h"
45
46 /* === M A C R O S ========================================================= */
47
48 /* === T Y P E D E F S ===================================================== */
49
50 /* === C L A S S E S & S T R U C T S ======================================= */
51
52 namespace xmlpp { class Node; class Element; };
53
54 namespace synfig {
55
56 /*!     \class CanvasParser
57 **      \todo writeme
58 */
59 class CanvasParser
60 {
61         /*
62  --     ** -- D A T A -------------------------------------------------------------
63         */
64
65 private:
66
67         int max_warnings_;
68
69     int total_warnings_;
70
71     int total_errors_;
72
73         bool allow_errors_;
74
75         String filename;
76
77         String path;
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         //! \todo writeme
120         Canvas::Handle parse_from_file(const String &filename);
121
122         Canvas::Handle parse_from_file_as(const String &filename,const String &as);
123
124         //! \todo writeme
125         Canvas::Handle parse_from_string(const String &data);
126
127 private:
128
129         // Error/Warning handling functions
130
131         void error(xmlpp::Node *node,const String &text);
132         void fatal_error(xmlpp::Node *node,const String &text);
133         void warning(xmlpp::Node *node,const String &text);
134         void error_unexpected_element(xmlpp::Node *node,const String &got, const String &expected);
135         void error_unexpected_element(xmlpp::Node *node,const String &got);
136
137         // Parsing Functions
138
139         Canvas::Handle parse_canvas(xmlpp::Element *node,Canvas::Handle parent=0,bool inline_=false, String path=".");
140         void parse_canvas_defs(xmlpp::Element *node,Canvas::Handle canvas);
141         etl::handle<Layer> parse_layer(xmlpp::Element *node,Canvas::Handle canvas);
142         ValueBase parse_value(xmlpp::Element *node,Canvas::Handle canvas);
143         etl::handle<ValueNode> parse_value_node(xmlpp::Element *node,Canvas::Handle canvas);
144
145         // ValueBase Parsing Functions
146
147         Real parse_real(xmlpp::Element *node,Canvas::Handle canvas);
148         Time parse_time(xmlpp::Element *node,Canvas::Handle canvas);
149         int parse_integer(xmlpp::Element *node,Canvas::Handle canvas);
150         Vector parse_vector(xmlpp::Element *node,Canvas::Handle canvas);
151         Color parse_color(xmlpp::Element *node,Canvas::Handle canvas);
152         Angle parse_angle(xmlpp::Element *node,Canvas::Handle canvas);
153         String parse_string(xmlpp::Element *node,Canvas::Handle canvas);
154         bool parse_bool(xmlpp::Element *node,Canvas::Handle canvas);
155         Segment parse_segment(xmlpp::Element *node,Canvas::Handle canvas);
156         ValueBase parse_list(xmlpp::Element *node,Canvas::Handle canvas);
157         Gradient parse_gradient(xmlpp::Element *node,Canvas::Handle canvas);
158         BLinePoint parse_bline_point(xmlpp::Element *node,Canvas::Handle canvas);
159
160         Keyframe parse_keyframe(xmlpp::Element *node,Canvas::Handle canvas);
161
162         // ValueNode Parsing Functions
163
164         etl::handle<ValueNode_Animated> parse_animated(xmlpp::Element *node,Canvas::Handle canvas);
165         etl::handle<ValueNode_Subtract> parse_subtract(xmlpp::Element *node,Canvas::Handle canvas);
166         etl::handle<ValueNode_Animated> parse_timedswap(xmlpp::Element *node,Canvas::Handle canvas);
167         etl::handle<LinkableValueNode> parse_linkable_value_node(xmlpp::Element *node,Canvas::Handle canvas);
168         etl::handle<ValueNode_Composite> parse_composite(xmlpp::Element *node,Canvas::Handle canvas);
169         etl::handle<ValueNode_DynamicList> parse_dynamic_list(xmlpp::Element *node,Canvas::Handle canvas);
170
171 }; // END of CanvasParser
172
173 /* === E X T E R N S ======================================================= */
174
175 //!     Loads a canvas from \a filename
176 /*!     \return The Canvas's handle on success, an empty handle on failure */
177 extern Canvas::Handle open_canvas(const String &filename);
178 extern Canvas::Handle open_canvas_as(const String &filename,const String &as);
179
180 //! Retrieves a Canvas from a string in XML format
181 extern Canvas::Handle string_to_canvas(const String &data);
182
183 std::map<synfig::String, etl::loose_handle<Canvas> >& get_open_canvas_map();
184
185 }; // END of namespace synfig
186
187 /* === E N D =============================================================== */
188
189 #endif