dynamic keyframes, textbox rework, andrea ffmpeg.opts, perpetual chkpt undo, lv2...
[goodguy/history.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 "keyframe.inc"
31 #include "filexml.inc"
32 #include "sizes.h"
33
34 #define MAX_TITLE 256
35
36 class XMLBuffer
37 {
38         long bsz, isz;
39         unsigned char *inp, *outp, *bfr, *lmt;
40         int destroy;
41
42         int demand(long len);
43         friend class KeyFrame;
44 public:
45         XMLBuffer(long buf_size=0x1000, long max_size=LONG_MAX, int del=1);
46         XMLBuffer(long buf_size, char *buf, int del=0); // writing
47         XMLBuffer(const char *buf, long buf_size, int del=0); // reading
48         ~XMLBuffer();
49
50         long otell() { return inp - bfr; }
51         long itell() { return outp - bfr; }
52         void oseek(long pos) { inp = bfr + pos; }
53         void iseek(long pos) { outp = bfr + pos; }
54         unsigned char *pos(long ofs=0) { return bfr+ofs; }
55         char *cstr() { if( demand(otell()+1) ) *inp = 0; return (char*)bfr; }
56         int read(char *bp, int n);
57         int write(const char *bp, int n);
58         void copy_from(XMLBuffer *xbfr);
59
60         int cur()  { return outp>=inp ? -1 : *outp; }
61         int next() { return outp>=inp ? -1 : *outp++; }
62         int next(int ch) { return !demand(otell()+1) ? -1 : *inp++ = ch; }
63
64         static char *decode_data(char *bp, const char *sp, int n=-1);
65         static char *encode_data(char *bp, const char *sp, int n=-1);
66         static char *copy_data(char *bp, const char *sp, int n=-1);
67         static long encoded_length(const char *sp, int n=-1);
68         static long copy_length(const char *sp, int n=-1);
69 };
70
71 class XMLTag
72 {
73         XMLBuffer *buffer;
74         class Property {
75         public:
76                 const char *prop;
77                 const char *value;
78
79                 Property(const char *pp, const char *vp);
80                 ~Property();
81         };
82         bool ws(char ch) { return ch==' ' || ch=='\n'; }
83
84 public:
85         XMLTag();
86         ~XMLTag();
87
88         int reset_tag();
89
90         int title_is(const char *title);
91         char *get_title();
92         int get_title(char *value);
93         int test_property(char *property, char *value);
94         const char *get_property_text(int number);
95         int get_property_int(int number);
96         float get_property_float(int number);
97         const char *get_property(const char *property);
98         const char* get_property(const char *property, char *value);
99         int32_t get_property(const char *property, int32_t default_);
100         int64_t get_property(const char *property, int64_t default_);
101         float get_property(const char *property, float default_);
102         double get_property(const char *property, double default_);
103
104         int set_title(const char *text);
105         int set_property(const char *text, const char *value);
106         int set_property(const char *text, int32_t value);
107         int set_property(const char *text, int64_t value);
108         int set_property(const char *text, float value);
109         int set_property(const char *text, double value);
110
111         int write_tag(FileXML *xml);
112         int read_tag(FileXML *xml);
113
114         char title[MAX_TITLE];
115         ArrayList<Property*> properties;
116         char *string;
117         long used, avail;
118 };
119
120
121 class FileXML
122 {
123 public:
124         FileXML(int coded=1);
125         ~FileXML();
126
127         int terminate_string();
128         int append_newline();
129         int append_tag();
130         int append_text(const char *text);
131         int append_text(const char *text, long len);
132         int append_data(const char *text);
133         int append_data(const char *text, long len);
134
135         char *read_text();
136         int read_data_until(const char *tag_end, XMLBuffer *xbfr, int skip=0);
137         int read_text_until(const char *tag_end, XMLBuffer *xbfr, int skip=0);
138         int read_tag();
139         int skip_tag();
140         int write_to_file(const char *filename);
141         int write_to_file(FILE *file, const char *filename="");
142         int read_from_file(const char *filename, int ignore_error = 0);
143         int read_from_string(char *string);
144         char *(*decode)(char *bp, const char *sp, int n);
145         char *(*encode)(char *bp, const char *sp, int n);
146         long (*coded_length)(const char *sp, int n);
147
148         void set_coding(int coding);
149         int get_coding();
150         int set_shared_input(XMLBuffer *xbfr);
151         int set_shared_output(XMLBuffer *xbfr);
152
153         int rewind();
154         char *get_data();
155         char *string();
156         long length();
157
158         XMLBuffer *buffer;
159         int coded, shared;
160
161         XMLTag tag;
162         long output_length;
163         char *output;
164         char left_delimiter, right_delimiter;
165         char filename[MAX_TITLE];
166         static const char *xml_header;
167         static const int xml_header_size;
168 };
169
170 #endif