LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Static Public Member Functions | List of all members
ndarray::PyConverter< Vector< T, N > > Struct Template Reference

A traits class providing Python conversion functions for Vector. More...

#include <Vector.h>

Inheritance diagram for ndarray::PyConverter< Vector< T, N > >:
ndarray::detail::PyConverterBase< Vector< T, N > >

Static Public Member Functions

static PyObject * toPython (Vector< T, N > const &input)
 Convert a Vector to a new Python object. More...
 
static PyTypeObject const * getPyType ()
 Return the Python TypeObject that corresponds to the object the toPython() function returns. More...
 
static bool fromPythonStage1 (PyPtr &p)
 Check if a Python object is convertible to T and optionally begin the conversion by replacing the input with an intermediate. More...
 
static bool fromPythonStage2 (PyPtr const &p, Vector< T, N > &output)
 Complete a Python to C++ conversion begun with fromPythonStage1(). More...
 
- Static Public Member Functions inherited from ndarray::detail::PyConverterBase< Vector< T, N > >
static bool matches (PyObject *arg)
 Check if a Python object might be convertible to T. More...
 
static int fromPython (PyObject *arg, Vector< T, N > *output)
 Convert a Python object to a C++ object. More...
 

Detailed Description

template<typename T, int N>
struct ndarray::PyConverter< Vector< T, N > >

A traits class providing Python conversion functions for Vector.

Definition at line 41 of file Vector.h.

Member Function Documentation

template<typename T , int N>
static bool ndarray::PyConverter< Vector< T, N > >::fromPythonStage1 ( PyPtr p)
inlinestatic

Check if a Python object is convertible to T and optionally begin the conversion by replacing the input with an intermediate.

Returns
true if a conversion may be possible, and false if it is not (with a Python exception set).
Parameters
pOn input, a Python object to be converted. On output, a Python object to be passed to fromPythonStage2().

Definition at line 73 of file Vector.h.

78  {
79  if (!PySequence_Check(p.get())) {
80  PyErr_Format(PyExc_TypeError,"Expected a Python sequence of length %i.",N);
81  return false;
82  }
83  if (PySequence_Size(p.get()) != N) {
84  PyErr_Format(PyExc_ValueError,"Incorrect sequence length for Vector<T,%i>", N);
85  return false;
86  }
87  return true;
88  }
template<typename T , int N>
static bool ndarray::PyConverter< Vector< T, N > >::fromPythonStage2 ( PyPtr const &  p,
Vector< T, N > &  output 
)
inlinestatic

Complete a Python to C++ conversion begun with fromPythonStage1().

Returns
true if the conversion was successful, and false otherwise (with a Python exception set).
Parameters
pA Python object processed by fromPythonStage1().
outputThe output C++ object.

Definition at line 97 of file Vector.h.

100  {
101  NDARRAY_ASSERT(p);
102  NDARRAY_ASSERT(PySequence_Check(p.get()));
103  Vector<T,N> tmp;
104  for (int n=0; n<N; ++n) {
105  PyPtr item(PySequence_ITEM(p.get(),n),false);
106  if (!item) return false;
107  if (!PyConverter<T>::fromPythonStage1(item)) return false;
108  if (!PyConverter<T>::fromPythonStage2(item,tmp[n])) return false;
109  }
110  output = tmp;
111  return true;
112  }
boost::intrusive_ptr< PyObject > PyPtr
A reference-counting smart pointer for PyObject.
Definition: PyConverter.h:48
#define NDARRAY_ASSERT(ARG)
Definition: ndarray_fwd.h:51
template<typename T , int N>
static PyTypeObject const* ndarray::PyConverter< Vector< T, N > >::getPyType ( )
inlinestatic

Return the Python TypeObject that corresponds to the object the toPython() function returns.

Definition at line 63 of file Vector.h.

63 { return &PyTuple_Type; }
template<typename T , int N>
static PyObject* ndarray::PyConverter< Vector< T, N > >::toPython ( Vector< T, N > const &  input)
inlinestatic

Convert a Vector to a new Python object.

Returns
A new Python object, or NULL on failure (with a Python exception set).
Parameters
inputInput C++ object.

Definition at line 49 of file Vector.h.

51  {
52  PyObject * r = PyTuple_New(N);
53  for (int i=0; i<N; ++i) {
54  PyTuple_SET_ITEM(r,i,PyConverter<T>::toPython(input[i]));
55  }
56  return r;
57  }

The documentation for this struct was generated from the following file: