PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/octave/octprimtypes.swg

#
Unknown | 232 lines | 204 code | 28 blank | 0 comment | 0 complexity | 26144d9e233d4d6d0ea46553113ca332 MD5 | raw file
  1/* ------------------------------------------------------------
  2 * Primitive Types
  3 * ------------------------------------------------------------ */
  4
  5
  6// boolean
  7
  8%fragment(SWIG_From_frag(bool),"header") {
  9SWIGINTERNINLINE octave_value
 10  SWIG_From_dec(bool)(bool value)
 11{
 12  return octave_value(value);
 13}
 14}
 15
 16%fragment(SWIG_AsVal_frag(bool),"header",
 17	  fragment=SWIG_AsVal_frag(long)) {
 18SWIGINTERN int
 19SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val)
 20{
 21  if (!ov.is_bool_type())
 22    return SWIG_ERROR;
 23  if (val)
 24    *val = ov.bool_value();
 25  return SWIG_OK;
 26}
 27}
 28
 29// long
 30
 31%fragment(SWIG_From_frag(long),"header") {
 32  SWIGINTERNINLINE octave_value SWIG_From_dec(long)  (long value)
 33    {    
 34      return octave_value(value);
 35    }
 36}
 37
 38
 39%fragment(SWIG_AsVal_frag(long),"header") {
 40  SWIGINTERN int SWIG_AsVal_dec(long)(const octave_value& ov, long* val)
 41    {
 42      if (!ov.is_scalar_type())
 43	return SWIG_TypeError;
 44      if (ov.is_complex_scalar())
 45	return SWIG_TypeError;
 46      if (ov.is_double_type()||ov.is_single_type()) {
 47	double v=ov.double_value();
 48	if (v!=floor(v))
 49	  return SWIG_TypeError;
 50      }
 51      if (val)
 52	*val = ov.long_value();
 53      return SWIG_OK;
 54    }
 55}
 56
 57// unsigned long
 58
 59%fragment(SWIG_From_frag(unsigned long),"header") {
 60  SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long)  (unsigned long value)
 61    {    
 62      return octave_value(value);
 63    }
 64}
 65
 66
 67%fragment(SWIG_AsVal_frag(unsigned long),"header") {
 68  SWIGINTERN int SWIG_AsVal_dec(unsigned long)(const octave_value& ov, unsigned long* val)
 69    {
 70      if (!ov.is_scalar_type())
 71	return SWIG_TypeError;
 72      if (ov.is_complex_scalar())
 73	return SWIG_TypeError;
 74      if (ov.is_double_type()||ov.is_single_type()) {
 75	double v=ov.double_value();
 76	if (v<0)
 77	  return SWIG_OverflowError;  
 78	if (v!=floor(v))
 79	  return SWIG_TypeError;
 80      }
 81      if (ov.is_int8_type()||ov.is_int16_type()||
 82	  ov.is_int32_type()) {
 83	long v=ov.long_value();
 84	if (v<0)
 85	  return SWIG_OverflowError;  
 86      }
 87      if (ov.is_int64_type()) {
 88	long long v=ov.int64_scalar_value().value();
 89	if (v<0)
 90	  return SWIG_OverflowError;  
 91      }
 92      if (val)
 93	*val = ov.ulong_value();
 94      return SWIG_OK;
 95    }
 96}
 97
 98// long long
 99
100%fragment(SWIG_From_frag(long long),"header") {
101  SWIGINTERNINLINE octave_value SWIG_From_dec(long long)  (long long value)
102    {    
103      return octave_int64(value);
104    }
105}
106
107
108%fragment(SWIG_AsVal_frag(long long),"header") {
109  SWIGINTERN int SWIG_AsVal_dec(long long)(const octave_value& ov, long long* val)
110    {
111      if (!ov.is_scalar_type())
112	return SWIG_TypeError;
113      if (ov.is_complex_scalar())
114	return SWIG_TypeError;
115      if (ov.is_double_type()||ov.is_single_type()) {
116	double v=ov.double_value();
117	if (v!=floor(v))
118	  return SWIG_TypeError;
119      }
120      if (val) {
121	if (ov.is_int64_type())
122	  *val = ov.int64_scalar_value().value();
123	else if (ov.is_uint64_type())
124	  *val = ov.uint64_scalar_value().value();
125	else
126	  *val = ov.long_value();
127      }
128      return SWIG_OK;
129    }
130}
131
132%fragment(SWIG_From_frag(unsigned long long),"header") {
133  SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long long)  (unsigned long long value)
134    {    
135      return octave_uint64(value);
136    }
137}
138
139%fragment(SWIG_AsVal_frag(unsigned long long),"header") {
140  SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(const octave_value& ov, unsigned long long* val)
141    {
142      if (!ov.is_scalar_type())
143	return SWIG_TypeError;
144      if (ov.is_complex_scalar())
145	return SWIG_TypeError;
146      if (ov.is_double_type()||ov.is_single_type()) {
147	double v=ov.double_value();
148	if (v<0)
149	  return SWIG_OverflowError;  
150	if (v!=floor(v))
151	  return SWIG_TypeError;
152      }
153      if (ov.is_int8_type()||ov.is_int16_type()||
154	  ov.is_int32_type()) {
155	long v=ov.long_value();
156	if (v<0)
157	  return SWIG_OverflowError;  
158      }
159      if (ov.is_int64_type()) {
160	long long v=ov.int64_scalar_value().value();
161	if (v<0)
162	  return SWIG_OverflowError;  
163      }
164      if (val) {
165	if (ov.is_int64_type())
166	  *val = ov.int64_scalar_value().value();
167	else if (ov.is_uint64_type())
168	  *val = ov.uint64_scalar_value().value();
169	else
170	  *val = ov.long_value();
171      }
172      return SWIG_OK;
173    }
174}
175
176// double
177
178%fragment(SWIG_From_frag(double),"header") {
179  SWIGINTERNINLINE octave_value SWIG_From_dec(double)  (double value)
180    {    
181      return octave_value(value);
182    }
183}
184
185
186%fragment(SWIG_AsVal_frag(double),"header") {
187  SWIGINTERN int SWIG_AsVal_dec(double)(const octave_value& ov, double* val)
188    {
189      if (!ov.is_scalar_type())
190	return SWIG_TypeError;
191      if (ov.is_complex_scalar())
192	return SWIG_TypeError;
193      if (val)
194	*val = ov.double_value();
195      return SWIG_OK;
196    }
197}
198
199// const char* (strings)
200
201%fragment("SWIG_AsCharPtrAndSize","header") {
202SWIGINTERN int
203SWIG_AsCharPtrAndSize(octave_value ov, char** cptr, size_t* psize, int *alloc)
204{
205  if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
206    ov = ov.cell_value()(0);
207  if (!ov.is_string())
208    return SWIG_TypeError;
209  
210  std::string str=ov.string_value();
211  size_t len=str.size();
212  char* cstr=(char*)str.c_str();
213  if (alloc) {
214    *cptr = %new_copy_array(cstr, len + 1, char);
215    *alloc = SWIG_NEWOBJ;
216  } else if (cptr)
217    *cptr = cstr;
218  if (psize)
219    *psize = len + 1;
220  return SWIG_OK;
221}
222}
223
224%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
225SWIGINTERNINLINE octave_value
226SWIG_FromCharPtrAndSize(const char* carray, size_t size)
227{
228  return std::string(carray,carray+size);
229}
230}
231
232