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