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