fix bug in batchrender job load from xml
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / filexml.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef FILEXML_H
23 #define FILEXML_H
24
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <limits.h>
28
29 #include "arraylist.h"
30 #include "bcwindowbase.inc"
31 #include "mutex.h"
32 #include "keyframe.inc"
33 #include "filexml.inc"
34 #include "sizes.h"
35
36 #define MAX_TITLE 256
37
38 class XMLBuffer
39 {
40         long bsz, isz;
41         unsigned char *inp, *outp, *bfr, *lmt;
42         int destroy;
43         Mutex *share_lock;
44
45         int demand(long len);
46         friend class KeyFrame;
47         friend class FileXML;
48 public:
49         XMLBuffer(long buf_size=0x1000, long max_size=LONG_MAX, int del=1);
50         XMLBuffer(long buf_size, char *buf, int del=0); // writing
51         XMLBuffer(const char *buf, long buf_size, int del=0); // reading
52         ~XMLBuffer();
53
54         long otell() { return inp - bfr; }
55         long itell() { return outp - bfr; }
56         void oseek(long pos) { inp = bfr + pos; }
57         void iseek(long pos) { outp = bfr + pos; }
58         unsigned char *pos(long ofs=0) { return bfr+ofs; }
59         char *cstr() { if( demand(otell()+1) ) *inp = 0; return (char*)bfr; }
60         int read(char *bp, int n);
61         int write(const char *bp, int n);
62         void copy_from(XMLBuffer *xbfr);
63
64         int cur()  { return outp>=inp ? -1 : *outp; }
65         int next() { return outp>=inp ? -1 : *outp++; }
66         int next(int ch) { return !demand(otell()+1) ? -1 : *inp++ = ch; }
67
68         static char *decode_data(char *bp, const char *sp, int n=-1);
69         static char *encode_data(char *bp, const char *sp, int n=-1);
70         static char *copy_data(char *bp, const char *sp, int n=-1);
71         static long encoded_length(const char *sp, int n=-1);
72         static long copy_length(const char *sp, int n=-1);
73 };
74
75 class XMLTag
76 {
77         XMLBuffer *buffer;
78         class Property {
79         public:
80                 const char *prop;
81                 const char *value;
82
83                 Property(const char *pp, const char *vp);
84                 ~Property();
85         };
86         bool ws(char ch) { return ch==' ' || ch=='\n'; }
87
88 public:
89         XMLTag();
90         ~XMLTag();
91
92         int reset_tag();
93
94         int title_is(const char *title);
95         char *get_title();
96         int get_title(char *value);
97         int test_property(char *property, char *value);
98         const char *get_property_text(int number);
99         int get_property_int(int number);
100         float get_property_float(int number);
101         const char *get_property(const char *property);
102         const char* get_property(const char *property, char *value);
103         int32_t get_property(const char *property, int32_t default_);
104         int64_t get_property(const char *property, int64_t default_);
105         float get_property(const char *property, float default_);
106         double get_property(const char *property, double default_);
107
108         int set_title(const char *text);
109         int set_property(const char *text, const char *value);
110         int set_property(const char *text, int32_t value);
111         int set_property(const char *text, int64_t value);
112         int set_property(const char *text, float value);
113         int set_property(const char *text, double value);
114
115         int write_tag(FileXML *xml);
116         int read_tag(FileXML *xml);
117
118         char title[MAX_TITLE];
119         ArrayList<Property*> properties;
120         char *string;
121         long used, avail;
122 };
123
124
125 class FileXML
126 {
127 public:
128         FileXML(int coded=1);
129         ~FileXML();
130
131         int terminate_string();
132         int append_newline();
133         int append_tag();
134         int append_text(const char *text);
135         int append_text(const char *text, long len);
136         int append_data(const char *text);
137         int append_data(const char *text, long len);
138
139         char *read_text(const char *tag_title=0);
140         int read_data_until(const char *tag_end, XMLBuffer *xbfr, int skip=0);
141         int read_text_until(const char *tag_end, XMLBuffer *xbfr, int skip=0);
142         int read_tag();
143         int skip_tag();
144         int write_to_file(const char *filename);
145         int write_to_file(FILE *file, const char *filename="");
146         int read_from_file(const char *filename, int ignore_error = 0);
147         int read_from_string(char *string);
148         char *(*decode)(char *bp, const char *sp, int n);
149         char *(*encode)(char *bp, const char *sp, int n);
150         long (*coded_length)(const char *sp, int n);
151
152         void set_coding(int coding);
153         int get_coding();
154         int set_shared_input(XMLBuffer *xbfr);
155         int set_shared_output(XMLBuffer *xbfr);
156
157         int rewind();
158         char *get_data();
159         char *string();
160         long length();
161
162         XMLBuffer *buffer;
163         int coded, shared;
164
165         XMLTag tag;
166         long output_length;
167         char *output;
168         char left_delimiter, right_delimiter;
169         char filename[BCTEXTLEN];
170         static const char *xml_header;
171         static const int xml_header_size;
172 };
173
174 #endif