40d70815d54eb8eaeb67f8783ec4591d1c3253f8
[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 destroy( true ),
26 instance( NULL )
27 {
28 instance = mlt_properties_new( );
29 }
30
31 Properties::Properties( Properties &properties ) :
32 destroy( false ),
33 instance( properties.get_properties( ) )
34 {
35 }
36
37 Properties::Properties( mlt_properties properties ) :
38 destroy( false ),
39 instance( properties )
40 {
41 }
42
43 Properties::Properties( char *file ) :
44 destroy( true ),
45 instance( NULL )
46 {
47 instance = mlt_properties_load( file );
48 }
49
50 Properties::~Properties( )
51 {
52 if ( destroy )
53 mlt_properties_close( instance );
54 }
55
56 mlt_properties Properties::get_properties( )
57 {
58 return instance;
59 }
60
61 bool Properties::is_valid( )
62 {
63 return get_properties( ) != NULL;
64 }
65
66 int Properties::count( )
67 {
68 return mlt_properties_count( get_properties( ) );
69 }
70
71 char *Properties::get( char *name )
72 {
73 return mlt_properties_get( get_properties( ), name );
74 }
75
76 int Properties::get_int( char *name )
77 {
78 return mlt_properties_get_int( get_properties( ), name );
79 }
80
81 double Properties::get_double( char *name )
82 {
83 return mlt_properties_get_double( get_properties( ), name );
84 }
85
86 void *Properties::get_data( char *name, int &size )
87 {
88 return mlt_properties_get_data( get_properties( ), name, &size );
89 }
90
91 int Properties::set( char *name, char *value )
92 {
93 return mlt_properties_set( get_properties( ), name, value );
94 }
95
96 int Properties::set( char *name, int value )
97 {
98 return mlt_properties_set_int( get_properties( ), name, value );
99 }
100
101 int Properties::set( char *name, double value )
102 {
103 return mlt_properties_set_double( get_properties( ), name, value );
104 }
105
106 int Properties::set( char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
107 {
108 return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
109 }
110
111 int Properties::pass_values( Properties &that, char *prefix )
112 {
113 return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
114 }
115
116 int Properties::parse( char *namevalue )
117 {
118 return mlt_properties_parse( get_properties( ), namevalue );
119 }
120
121 char *Properties::get_name( int index )
122 {
123 return mlt_properties_get_name( get_properties( ), index );
124 }
125
126 char *Properties::get( int index )
127 {
128 return mlt_properties_get_value( get_properties( ), index );
129 }
130
131 void *Properties::get_data( int index, int &size )
132 {
133 return mlt_properties_get_data_at( get_properties( ), index, &size );
134 }
135
136 void Properties::mirror( Properties &that )
137 {
138 mlt_properties_mirror( get_properties( ), that.get_properties( ) );
139 }
140
141 int Properties::inherit( Properties &that )
142 {
143 return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
144 }
145
146 int Properties::rename( char *source, char *dest )
147 {
148 return mlt_properties_rename( get_properties( ), source, dest );
149 }
150
151 void Properties::dump( FILE *output )
152 {
153 mlt_properties_dump( get_properties( ), output );
154 }
155
156 int Properties::save( char *file )
157 {
158 int error = 0;
159 FILE *f = fopen( file, "w" );
160 if ( f != NULL )
161 {
162 dump( f );
163 fclose( f );
164 }
165 else
166 {
167 error = 1;
168 }
169 return error;
170 }