Imported Upstream version 3.1.0
[debian/amanda] / perl / Amanda / Feature.swg
1 /*
2  * Copyright (c) 2010 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 %module "Amanda::Feature"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
24
25 %include "Amanda/Feature.pod"
26
27 %{
28 #include "amfeatures.h"
29 %}
30
31 /* include the header file directly - this saves us having to remember
32  * to add new constants to both places */
33 #define AMANDA_FEATURE_SWG
34 %include "../common-src/amfeatures.h"
35
36 %{
37 typedef am_feature_t Set;
38 %}
39
40 typedef struct {
41     %extend {
42         ~Set() {
43             am_release_feature_set(self);
44         }
45         void add(int feature) {
46             am_add_feature(self, feature);
47         }
48         void remove(int feature) {
49             am_remove_feature(self, feature);
50         }
51         int has(int feature) {
52             return am_has_feature(self, feature);
53         }
54         %newobject as_string;
55         char *as_string() {
56             return am_feature_to_string(self);
57         }
58     };
59 } Set;
60
61 %newobject am_string_to_feature;
62 extern Set *am_string_to_feature(char *s);
63 %newobject am_set_default_feature_set;
64 extern Set *am_set_default_feature_set(void);
65 %newobject am_init_feature_set;
66 extern Set *am_init_feature_set(void);
67
68 %perlcode %{
69
70 package Amanda::Feature::Set;
71
72 # this does not work, because SWIG uses the string value of objects as a hash key
73 # even after calling their destructor, which leads to a segfault.
74 #
75 # use overload '""' => sub { $_[0]->as_string(); };
76
77 sub Amanda::Feature::Set::from_string {
78     my $class = shift;
79     return Amanda::Feature::am_string_to_feature(@_);
80 }
81
82 sub Amanda::Feature::Set::old {
83     my $class = shift;
84     return Amanda::Feature::am_set_default_feature_set();
85 }
86
87 sub Amanda::Feature::Set::mine {
88     my $class = shift;
89     return Amanda::Feature::am_init_feature_set();
90 }
91
92 package Amanda::Feature;
93
94 %}