File: tConvert.cc

package info (click to toggle)
python-casacore 3.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,488 kB
  • sloc: python: 4,170; cpp: 1,549; makefile: 67
file content (145 lines) | stat: -rw-r--r-- 6,183 bytes parent folder | download | duplicates (2)
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

//# tConvert.cc: Test program for libcasacore_python's C++/Python converters
//# Copyright (C) 2006
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Lesser General Public License as published by
//# the Free Software Foundation; either version 3 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Lesser General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: aips2-request@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA
//#
//# $Id: tConvert.cc,v 1.4 2006/11/06 00:14:44 gvandiep Exp $

#include <casacore/casa/version.h>
#include <casacore/python/Converters/PycExcp.h>
#include <casacore/python/Converters/PycBasicData.h>
#include <casacore/python/Converters/PycValueHolder.h>
#include <casacore/python/Converters/PycRecord.h>
#include <casacore/python/Converters/PycArray.h>
#if CASACORE_MAJOR_VERSION < 3 || \
    (CASACORE_MAJOR_VERSION == 3 && CASACORE_MINOR_VERSION < 4)
// This include disappeared in the arrays refactor for casacore 3.4.0
#include <casacore/casa/Arrays/ArrayIO.h>
#endif
#include <casacore/casa/BasicSL/STLIO.h>
#include <casacore/casa/Exceptions/Error.h>

#include <boost/python.hpp>

using namespace boost::python;

namespace casacore { namespace python {

  struct TConvert
  {
    TConvert() {}
    Bool  testbool (Bool in)
      {cout << "bool " << in << endl; return in;}
    Int testint (Int in)
      {cout << "Int " << in << endl; return in;}
    Int64 testint64 (Int64 in)
      {cout << "Int64 " << in << endl; return in;}
    Int testssize (::ssize_t in)
      {cout << "ssize " << in << endl; return in;}
    Float testfloat (Float in)
      {cout << "Float " << in << endl; return in;}
    Double testdouble (Double in)
      {cout << "Double " << in << endl; return in;}
    Complex testcomplex (const Complex& in)
      {cout << "Complex " << in << endl; return in;}
    DComplex testdcomplex (const DComplex& in)
      {cout << "DComplex " << in << endl; return in;}
    String teststring (const String& in)
      {cout << "String " << in << endl; String out=in; return out;}
    String testunicode (const String& in)
      {cout << "Unicode " << in << endl; String out=in; return out;}
    Record testrecord (const Record& in)
      {cout << "Record "; in.print(cout); cout << endl; return in;}
    ValueHolder testvh (const ValueHolder& in)
      {cout << "VH " << in.dataType() << endl; return in;}
    Vector<Bool> testvecbool (const Vector<Bool>& in)
      {cout << "VecBool " << in << endl; return in;}
    Vector<Int> testvecint (const Vector<int>& in)
      {cout << "VecInt " << in << endl; return in;}
    Vector<DComplex> testveccomplex (const Vector<DComplex>& in)
      {cout << "VecComplex " << in << endl; return in;}
    Vector<String> testvecstr (const Vector<String>& in)
      {cout << "VecStr " << in << endl; return in;}
    std::vector<bool> teststdvecbool (const std::vector<bool>& in)
      {cout << "vecbool " << in << endl; return in;}
    std::vector<uInt> teststdvecuint (const std::vector<uInt>& in)
      {cout << "vecuInt " << in << endl; return in;}
    std::vector<std::vector<uInt> > teststdvecvecuint
    (const std::vector<std::vector<uInt> >& in)
      {cout << "vecvecuInt " << in << endl; return in;}
    std::vector<ValueHolder> teststdvecvh (const std::vector<ValueHolder>& in)
      {cout << "vecvh " << in.size() << endl; return in;}
    IPosition testipos (const IPosition& in)
      {cout << "IPos " << in << endl; return in;}
    void testIterError()
      {throw IterError();}
  };


  void testConvert()
  {
    class_<TConvert> ("tConvert", init<>())
      .def ("testbool",       &TConvert::testbool)
      .def ("testint",        &TConvert::testint)
      .def ("testint64",      &TConvert::testint64)
      .def ("testssize",      &TConvert::testssize)
      .def ("testfloat",      &TConvert::testfloat)
      .def ("testdouble",     &TConvert::testdouble)
      .def ("testcomplex",    &TConvert::testcomplex)
      .def ("testdcomplex",   &TConvert::testdcomplex)
      .def ("teststring",     &TConvert::teststring)
      .def ("testunicode",    &TConvert::testunicode)
      .def ("testrecord",     &TConvert::testrecord)
      .def ("testvh",         &TConvert::testvh)
      .def ("testvecbool",    &TConvert::testvecbool)
      .def ("testvecint",     &TConvert::testvecint)
      .def ("testveccomplex", &TConvert::testveccomplex)
      .def ("testvecstr",     &TConvert::testvecstr)
      .def ("teststdvecbool", &TConvert::teststdvecbool)
      .def ("teststdvecuint", &TConvert::teststdvecuint)
      .def ("teststdvecvecuint", &TConvert::teststdvecvecuint)
      .def ("teststdvecvh"  , &TConvert::teststdvecvh)
      .def ("testipos",       &TConvert::testipos)
      .def ("testitererror",  &TConvert::testIterError)
      ;
  }

}}


BOOST_PYTHON_MODULE(_tConvert)
{
  // Register the required converters.
  casacore::python::register_convert_excp();
  casacore::python::register_convert_basicdata();
  casacore::python::register_convert_casa_valueholder();
  casacore::python::register_convert_casa_record();
  casacore::python::register_convert_std_vector<bool>();
  casacore::python::register_convert_std_vector<casacore::uInt>();
  casacore::python::register_convert_std_vector<std::vector<casacore::uInt> >();
  casacore::python::register_convert_std_vector<casacore::ValueHolder>();

  // Execute the test.
  casacore::python::testConvert();
}