File: tConvert.cc

package info (click to toggle)
casacore 3.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,912 kB
  • sloc: cpp: 471,569; fortran: 16,372; ansic: 7,416; yacc: 4,714; lex: 2,346; sh: 1,865; python: 629; perl: 531; sed: 499; csh: 201; makefile: 32
file content (137 lines) | stat: -rw-r--r-- 5,894 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
//# tConvert.cc: Test program for libpython'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 Library General Public License as published by
//# the Free Software Foundation; either version 2 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 Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library 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: casa-feedback@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA

#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>
#include <casacore/casa/IO/ArrayIO.h>
#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();
}