Const string usage in properties
[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 #include "MltEvent.h"
23 using namespace Mlt;
24
25 Properties::Properties( ) :
26 instance( NULL )
27 {
28 instance = mlt_properties_new( );
29 }
30
31 Properties::Properties( bool dummy ) :
32 instance( NULL )
33 {
34 }
35
36 Properties::Properties( Properties &properties ) :
37 instance( properties.get_properties( ) )
38 {
39 inc_ref( );
40 }
41
42 Properties::Properties( mlt_properties properties ) :
43 instance( properties )
44 {
45 inc_ref( );
46 }
47
48 Properties::Properties( const char *file ) :
49 instance( NULL )
50 {
51 instance = mlt_properties_load( file );
52 }
53
54 Properties::~Properties( )
55 {
56 mlt_properties_close( instance );
57 }
58
59 mlt_properties Properties::get_properties( )
60 {
61 return instance;
62 }
63
64 int Properties::inc_ref( )
65 {
66 return mlt_properties_inc_ref( get_properties( ) );
67 }
68
69 int Properties::dec_ref( )
70 {
71 return mlt_properties_dec_ref( get_properties( ) );
72 }
73
74 int Properties::ref_count( )
75 {
76 return mlt_properties_ref_count( get_properties( ) );
77 }
78
79 void Properties::block( void *object )
80 {
81 mlt_events_block( get_properties( ), object != NULL ? object : get_properties( ) );
82 }
83
84 void Properties::unblock( void *object )
85 {
86 mlt_events_unblock( get_properties( ), object != NULL ? object : get_properties( ) );
87 }
88
89 void Properties::fire_event( const char *event )
90 {
91 mlt_events_fire( get_properties( ), ( char * )event, NULL );
92 }
93
94 bool Properties::is_valid( )
95 {
96 return get_properties( ) != NULL;
97 }
98
99 int Properties::count( )
100 {
101 return mlt_properties_count( get_properties( ) );
102 }
103
104 char *Properties::get( const char *name )
105 {
106 return mlt_properties_get( get_properties( ), name );
107 }
108
109 int Properties::get_int( const char *name )
110 {
111 return mlt_properties_get_int( get_properties( ), name );
112 }
113
114 double Properties::get_double( const char *name )
115 {
116 return mlt_properties_get_double( get_properties( ), name );
117 }
118
119 void *Properties::get_data( const char *name, int &size )
120 {
121 return mlt_properties_get_data( get_properties( ), name, &size );
122 }
123
124 int Properties::set( const char *name, const char *value )
125 {
126 return mlt_properties_set( get_properties( ), name, value );
127 }
128
129 int Properties::set( const char *name, int value )
130 {
131 return mlt_properties_set_int( get_properties( ), name, value );
132 }
133
134 int Properties::set( const char *name, double value )
135 {
136 return mlt_properties_set_double( get_properties( ), name, value );
137 }
138
139 int Properties::set( const char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
140 {
141 return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
142 }
143
144 int Properties::pass_values( Properties &that, const char *prefix )
145 {
146 return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
147 }
148
149 int Properties::parse( const char *namevalue )
150 {
151 return mlt_properties_parse( get_properties( ), namevalue );
152 }
153
154 char *Properties::get_name( int index )
155 {
156 return mlt_properties_get_name( get_properties( ), index );
157 }
158
159 char *Properties::get( int index )
160 {
161 return mlt_properties_get_value( get_properties( ), index );
162 }
163
164 void *Properties::get_data( int index, int &size )
165 {
166 return mlt_properties_get_data_at( get_properties( ), index, &size );
167 }
168
169 void Properties::mirror( Properties &that )
170 {
171 mlt_properties_mirror( get_properties( ), that.get_properties( ) );
172 }
173
174 int Properties::inherit( Properties &that )
175 {
176 return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
177 }
178
179 int Properties::rename( const char *source, const char *dest )
180 {
181 return mlt_properties_rename( get_properties( ), source, dest );
182 }
183
184 void Properties::dump( FILE *output )
185 {
186 mlt_properties_dump( get_properties( ), output );
187 }
188
189 void Properties::debug( const char *title, FILE *output )
190 {
191 mlt_properties_debug( get_properties( ), title, output );
192 }
193
194 void Properties::load( const char *file )
195 {
196 mlt_properties properties = mlt_properties_load( file );
197 if ( properties != NULL )
198 mlt_properties_pass( get_properties( ), properties, "" );
199 mlt_properties_close( properties );
200 }
201
202 int Properties::save( const char *file )
203 {
204 int error = 0;
205 FILE *f = fopen( file, "w" );
206 if ( f != NULL )
207 {
208 dump( f );
209 fclose( f );
210 }
211 else
212 {
213 error = 1;
214 }
215 return error;
216 }
217
218 Event *Properties::listen( char *id, void *object, mlt_listener listener )
219 {
220 mlt_event event = mlt_events_listen( get_properties( ), object, id, listener );
221 return new Event( event );
222 }
223
224 Event *Properties::setup_wait_for( char *id )
225 {
226 return new Event( mlt_events_setup_wait_for( get_properties( ), id ) );
227 }
228
229 void Properties::wait_for( Event *event, bool destroy )
230 {
231 mlt_events_wait_for( get_properties( ), event->get_event( ) );
232 if ( destroy )
233 mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
234 }
235