summaryrefslogtreecommitdiff
path: root/Lib/scilab/scisequence.swg
blob: 5fe0fdbe22a762a8029c0d21f0539f95be83889c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 *
 * Scilab sequence conversions
 *
 */

#define SWIG_Traits_Sequence_frag(Type) %fragment_name(AsVal_Traits_Sequence, Type)

#define SWIG_AsCheck_Sequence_frag(Type...) %fragment_name(AsCheck_Sequence, Type)
#define SWIG_AsCheck_Sequence_dec(Type...) %symbol_name(AsCheck_Sequence, Type)
#define SWIG_AsGet_Sequence_frag(Type...) %fragment_name(AsGet_Sequence, Type)
#define SWIG_AsGet_Sequence_dec(Type...) %symbol_name(AsGet_Sequence, Type)
#define SWIG_AsSize_Sequence_frag(Type...) %fragment_name(AsSize_Sequence, Type)
#define SWIG_AsSize_Sequence_dec(Type...) %symbol_name(AsSize_Sequence, Type)
#define SWIG_FromCreate_Sequence_frag(Type...) %fragment_name(FromCreate_Sequence, Type)
#define SWIG_FromCreate_Sequence_dec(Type...) %symbol_name(FromCreate_Sequence, Type)
#define SWIG_FromSet_Sequence_frag(Type...) %fragment_name(FromSet_Sequence, Type)
#define SWIG_FromSet_Sequence_dec(Type...) %symbol_name(FromSet_Sequence, Type)

#define SWIG_Traits_SequenceItem_frag(Type) %fragment_name(AsVal_Traits_SequenceItem, Type)
#define SWIG_AsVal_SequenceItem_frag(Type...) %fragment_name(AsVal_SequenceItem, Type)
#define SWIG_AsVal_SequenceItem_dec(Type...) %symbol_name(AsVal_SequenceItem, Type)
#define SWIG_From_SequenceItem_frag(Type...) %fragment_name(From_SequenceItem, Type)
#define SWIG_From_SequenceItem_dec(Type...) %symbol_name(From_SequenceItem, Type)

%include <scisequencepointer.swg>
%include <scisequenceint.swg>
%include <scisequencedouble.swg>
%include <scisequencefloat.swg>
%include <scisequencestring.swg>
%include <scisequencebool.swg>

//
// Sequence conversion
//

%fragment(SWIG_Traits_Sequence_frag(ptr), "header",
  fragment=SWIG_AsCheck_Sequence_frag(ptr),
  fragment=SWIG_AsGet_Sequence_frag(ptr),
  fragment=SWIG_AsSize_Sequence_frag(ptr),
  fragment=SWIG_FromCreate_Sequence_frag(ptr),
  fragment=SWIG_FromSet_Sequence_frag(ptr),
  fragment="StdTraits",
  fragment="<stdint.h>") {

namespace swig {
  // Error returned for sequence containers of default item type
  template <typename T> struct traits_as_sequence {
    static int check(SwigSciObject obj) {
      throw std::invalid_argument("The container data type is not supported."); 
    }
    static int get(SwigSciObject obj, void **sequence) {
      throw std::invalid_argument("The container data type is not supported."); 
    }
    static int size(SwigSciObject obj, int *size) {
      throw std::invalid_argument("The container data type is not supported."); 
    }
  };
  template <typename T> struct traits_from_sequence {
    static int create(int size, void **sequence) {
      throw std::invalid_argument("The container data type is not supported."); 
    }
    static SwigSciObject set(int size, void *sequence) {
      throw std::invalid_argument("The container data type is not supported.");       
    }
  };

  // Support sequence containers of pointers
  template <typename T> struct traits_as_sequence<T*> {
    static int check(SwigSciObject obj) {
      return SWIG_AsCheck_Sequence_dec(ptr)(obj);
    }
    static int get(SwigSciObject obj, void **sequence) {
      return SWIG_AsGet_Sequence_dec(ptr)(obj, (int **)sequence);
    }
    static int size(SwigSciObject obj, int *size) {
      return SWIG_AsSize_Sequence_dec(ptr)(obj, size);
    }
  };
  template <typename T> struct traits_from_sequence<T*> {
    static int create(int size, void **sequence) {
      return SWIG_FromCreate_Sequence_dec(ptr)(size, (uintptr_t **)sequence);
    }
    static SwigSciObject set(int size, void *sequence) {
      return SWIG_FromSet_Sequence_dec(ptr)(size, (uintptr_t *)sequence);
    }
  };
}
}

%define %traits_sequence(CppType, ScilabType)
  %fragment(SWIG_Traits_Sequence_frag(CppType), "header",
    fragment=SWIG_Traits_Sequence_frag(ptr),
    fragment=SWIG_AsCheck_Sequence_frag(CppType),
    fragment=SWIG_AsGet_Sequence_frag(CppType),
    fragment=SWIG_AsSize_Sequence_frag(CppType),
    fragment=SWIG_FromCreate_Sequence_frag(CppType),
    fragment=SWIG_FromSet_Sequence_frag(CppType)) {

namespace swig {
  template <> struct traits_as_sequence<CppType > {
    static int check(SwigSciObject obj) {
      return SWIG_AsCheck_Sequence_dec(CppType)(obj);
    }
    static int get(SwigSciObject obj, void **sequence) {
      return SWIG_AsGet_Sequence_dec(CppType)(obj, (ScilabType **)sequence);
    }
    static int size(SwigSciObject obj, int *size) {
      return SWIG_AsSize_Sequence_dec(CppType)(obj, size);
    }
  };
  template <> struct traits_from_sequence<CppType > {
    static int create(int size, void **sequence) {
      return SWIG_FromCreate_Sequence_dec(CppType)(size, (ScilabType **)sequence);
    }
    static SwigSciObject set(int size, void *sequence) {
      return SWIG_FromSet_Sequence_dec(CppType)(size, (ScilabType *)sequence);
    }
  };
}
}
%enddef


//
// Sequence item conversion
//

%fragment(SWIG_Traits_SequenceItem_frag(ptr), "header",
  fragment=SWIG_AsVal_SequenceItem_frag(ptr),
  fragment=SWIG_From_SequenceItem_frag(ptr),
  fragment="StdTraits",
  fragment="<stdint.h>") {

namespace swig {
  // Error returned for sequence containers of default item type
  template <typename T> struct traits_asval_sequenceitem {
    static T asval(SwigSciObject obj, void *pSequence, int iItemIndex) {
      throw std::invalid_argument("The container data type is not supported."); 
    }
  };
  template <typename T> struct traits_from_sequenceitem {
    static int from(void *pSequence, int iItemIndex, T itemValue) {
      throw std::invalid_argument("The container data type is not supported."); 
    }
  };

  // Support sequence containers of pointers
  template <typename T> struct traits_asval_sequenceitem<T*> {
    static T* asval(SwigSciObject obj, void *pSequence, int iItemIndex) {
      return static_cast<T*>(SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex));
    }
  };
  template <typename T> struct traits_from_sequenceitem<T*> {
    static int from(void *pSequence, int iItemIndex, T *itemValue) {
      return SWIG_From_SequenceItem_dec(ptr)((uintptr_t *)pSequence, iItemIndex, (uintptr_t) itemValue);
     }
   };
}
}

%define %traits_sequenceitem(CppType, ScilabType)
  %fragment(SWIG_Traits_SequenceItem_frag(CppType), "header",
    fragment=SWIG_Traits_SequenceItem_frag(ptr),
    fragment=SWIG_AsVal_SequenceItem_frag(CppType),
    fragment=SWIG_From_SequenceItem_frag(CppType)) {

namespace swig {
  template <> struct traits_asval_sequenceitem<CppType > {
    static CppType asval(SwigSciObject obj, void *pSequence, int iItemIndex) {
      return SWIG_AsVal_SequenceItem_dec(CppType)(obj, (ScilabType *)pSequence, iItemIndex);
    }
  };
  template <> struct traits_from_sequenceitem<CppType > {
    static int from(void *pSequence, int iItemIndex, CppType itemValue) {
      return SWIG_From_SequenceItem_dec(CppType)((ScilabType *)pSequence, iItemIndex, itemValue);
    }
  };
}
}
%enddef

%define %add_traits_sequence(CppType, ScilabType)
  %traits_sequence(CppType, ScilabType);
  %fragment(SWIG_Traits_Sequence_frag(CppType));
  %traits_sequenceitem(CppType, ScilabType);
  %fragment(SWIG_Traits_SequenceItem_frag(CppType));
%enddef

%add_traits_sequence(int, int);
%add_traits_sequence(double, double);
%add_traits_sequence(float, float);
%add_traits_sequence(std::string, char*);
%add_traits_sequence(bool, int);