Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Feature.swg
1 /*
2  * Copyright (c) 2010-2012 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();
67 %newobject features;
68 extern am_feature_t *am_features(Set *);
69
70 %perlcode %{
71
72 package Amanda::Feature::Set;
73
74 # this does not work, because SWIG uses the string value of objects as a hash key
75 # even after calling their destructor, which leads to a segfault.
76 #
77 # use overload '""' => sub { $_[0]->as_string(); };
78
79 sub Amanda::Feature::Set::from_string {
80     my $class = shift;
81     return Amanda::Feature::am_string_to_feature(@_);
82 }
83
84 sub Amanda::Feature::Set::old {
85     my $class = shift;
86     return Amanda::Feature::am_set_default_feature_set();
87 }
88
89 sub Amanda::Feature::Set::mine {
90     my $class = shift;
91     return Amanda::Feature::am_init_feature_set();
92 }
93
94 sub Amanda::Feature::Set::features {
95     my $class = shift;
96     return Amanmda::Feature::features();
97 }
98
99
100 package Amanda::Feature;
101
102 %}