121ca15806e90dd96204a84e9cdae3b7f343335a
[melted] / mlt++ / src / MltProperties.cpp
1 /**
2 * MltProperties.cpp - MLT Wrapper
3 * Copyright (C) 2004-2005 Charles Yates
4 * Author: Charles Yates <charles.yates@pandora.be>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by 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 Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include "MltProperties.h"
22 using namespace Mlt;
23
24 Properties::Properties( ) :
25 instance( NULL )
26 {
27 instance = mlt_properties_new( );
28 }
29
30 Properties::Properties( bool dummy ) :
31 instance( NULL )
32 {
33 }
34
35 Properties::Properties( Properties &properties ) :
36 instance( properties.get_properties( ) )
37 {
38 fprintf( stderr, "Incrementing ref count on properties #1\n" );
39 inc_ref( );
40 }
41
42 Properties::Properties( mlt_properties properties ) :
43 instance( properties )
44 {
45 fprintf( stderr, "Incrementing ref count on properties #2\n" );
46 inc_ref( );
47 }
48
49 Properties::Properties( char *file ) :
50 instance( NULL )
51 {
52 instance = mlt_properties_load( file );
53 }
54
55 Properties::~Properties( )
56 {
57 mlt_properties_close( instance );
58 }
59
60 mlt_properties Properties::get_properties( )
61 {
62 return instance;
63 }
64
65 int Properties::inc_ref( )
66 {
67 return mlt_properties_inc_ref( get_properties( ) );
68 }
69
70 int Properties::dec_ref( )
71 {
72 return mlt_properties_dec_ref( get_properties( ) );
73 }
74
75 bool Properties::is_valid( )
76 {
77 return get_properties( ) != NULL;
78 }
79
80 int Properties::count( )
81 {
82 return mlt_properties_count( get_properties( ) );
83 }
84
85 char *Properties::get( char *name )
86 {
87 return mlt_properties_get( get_properties( ), name );
88 }
89
90 int Properties::get_int( char *name )
91 {
92 return mlt_properties_get_int( get_properties( ), name );
93 }
94
95 double Properties::get_double( char *name )
96 {
97 return mlt_properties_get_double( get_properties( ), name );
98 }
99
100 void *Properties::get_data( char *name, int &size )
101 {
102 return mlt_properties_get_data( get_properties( ), name, &size );
103 }
104
105 int Properties::set( char *name, char *value )
106 {
107 return mlt_properties_set( get_properties( ), name, value );
108 }
109
110 int Properties::set( char *name, int value )
111 {
112 return mlt_properties_set_int( get_properties( ), name, value );
113 }
114
115 int Properties::set( char *name, double value )
116 {
117 return mlt_properties_set_double( get_properties( ), name, value );
118 }
119
120 int Properties::set( char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
121 {
122 return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
123 }
124
125 int Properties::pass_values( Properties &that, char *prefix )
126 {
127 return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
128 }
129
130 int Properties::parse( char *namevalue )
131 {
132 return mlt_properties_parse( get_properties( ), namevalue );
133 }
134
135 char *Properties::get_name( int index )
136 {
137 return mlt_properties_get_name( get_properties( ), index );
138 }
139
140 char *Properties::get( int index )
141 {
142 return mlt_properties_get_value( get_properties( ), index );
143 }
144
145 void *Properties::get_data( int index, int &size )
146 {
147 return mlt_properties_get_data_at( get_properties( ), index, &size );
148 }
149
150 void Properties::mirror( Properties &that )
151 {
152 mlt_properties_mirror( get_properties( ), that.get_properties( ) );
153 }
154
155 int Properties::inherit( Properties &that )
156 {
157 return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
158 }
159
160 int Properties::rename( char *source, char *dest )
161 {
162 return mlt_properties_rename( get_properties( ), source, dest );
163 }
164
165 void Properties::dump( FILE *output )
166 {
167 mlt_properties_dump( get_properties( ), output );
168 }
169
170 void Properties::debug( char *title, FILE *output )
171 {
172 mlt_properties_debug( get_properties( ), title, output );
173 }
174
175 int Properties::save( char *file )
176 {
177 int error = 0;
178 FILE *f = fopen( file, "w" );
179 if ( f != NULL )
180 {
181 dump( f );
182 fclose( f );
183 }
184 else
185 {
186 error = 1;
187 }
188 return error;
189 }