コード例 #1
0
    static void* convertible(PyObject* obj_ptr)
    {
        if( !PySequence_Check( obj_ptr ) ) {
            return 0;
        }

        if( !PyObject_HasAttrString( obj_ptr, "__len__" ) ) {
            return 0;
        }

        bp::object py_sequence( bp::handle<>( bp::borrowed( obj_ptr ) ) );
    
        if( 3 != bp::len( py_sequence ) ) {
            return 0;
        }

        // Ensure that the element type is correct
        for (Py_ssize_t i = 0; i < 3; ++i)
        {
            if (! boost::python::extract<double>(py_sequence[i]).check() )
                return 0;
        }
        
        return obj_ptr;
    }
コード例 #2
0
ファイル: tuples.hpp プロジェクト: CTrauma/pypp11
 static TTuple to_c_tuple( PyObject* py_obj ){
     if( !convertible( py_obj ) ){
         throw std::runtime_error( "Unable to construct boost::tuples::tuple from Python object!" );
     }
     TTuple c_tuple;
     python::object py_sequence( handle<>( borrowed( py_obj ) ) );
     construct_impl( py_sequence, c_tuple, mpl::int_< 0 >(), length_type() );
     return c_tuple;
 }
コード例 #3
0
ファイル: tuples.hpp プロジェクト: CTrauma/pypp11
    static void
    construct( PyObject* py_obj, converter::rvalue_from_python_stage1_data* data){
        typedef converter::rvalue_from_python_storage<TTuple> storage_t;
        storage_t* the_storage = reinterpret_cast<storage_t*>( data );
        void* memory_chunk = the_storage->storage.bytes;
        TTuple* c_tuple = new (memory_chunk) TTuple();
        data->convertible = memory_chunk;

        python::object py_sequence( handle<>( borrowed( py_obj ) ) );
        construct_impl( py_sequence, *c_tuple, mpl::int_< 0 >(), length_type() );
    }
コード例 #4
0
ファイル: custom_rvalue.cpp プロジェクト: zhangwise/gimli
    /*! Convert obj into RVector */
    static void construct(PyObject* obj, bpl::converter::rvalue_from_python_stage1_data * data){
        
        bpl::object py_sequence(bpl::handle<>(bpl::borrowed(obj)));

        typedef bpl::converter::rvalue_from_python_storage< std::vector < GIMLI::Pos< double > > > storage_t;
         
        storage_t* the_storage = reinterpret_cast<storage_t*>(data);
        void* memory_chunk = the_storage->storage.bytes;
 
        std::vector < GIMLI::Pos < double > > *vec = new (memory_chunk) std::vector < GIMLI::Pos < double > >(len(py_sequence));
        data->convertible = memory_chunk;

        for (GIMLI::Index i = 0; i < vec->size(); i ++){
            (*vec)[i] = bpl::extract< GIMLI::Pos < double > >(py_sequence[i]);
        }
    }
コード例 #5
0
ファイル: custom_rvalue.cpp プロジェクト: zhangwise/gimli
    /*! Check if the object is convertible */
    static void * convertible(PyObject * obj){
                
        // is obj is a sequence
        if(!PySequence_Check(obj)){
            return NULL;
        }

        // has the obj a len method
        if(!PyObject_HasAttrString(obj, "__len__")){
            return NULL;
        }

        bpl::object py_sequence(bpl::handle<>(bpl::borrowed(obj)));
        
        if (len(py_sequence) > 0) {
            
            bpl::object element = py_sequence[0];
            bpl::extract< GIMLI::Pos< double > > type_checker(element);
            
            if (type_checker.check()){
                return obj;
            } else {
                std::cout << WHERE_AM_I << "element cannot converted to GIMLI::Pos< double > " << std::endl;
            }
            
        } else {
            std::cout << WHERE_AM_I << " " << std::endl;
            return NULL;
        }
        // check if there is a valid converter
//         if(convertible_impl(py_sequence, boost::mpl::int_< 0 >(), length_type())){
//             return obj;
//         } else{
        return NULL;
        
    }
コード例 #6
0
ファイル: tuples.hpp プロジェクト: CTrauma/pypp11
    static void*
    convertible(PyObject* py_obj){

        if( !PySequence_Check( py_obj ) ){
            return 0;
        }

        if( !PyObject_HasAttrString( py_obj, "__len__" ) ){
            return 0;
        }

        python::object py_sequence( handle<>( borrowed( py_obj ) ) );
    
        if( tuples::length< TTuple >::value != len( py_sequence ) ){
            return 0;
        }

        if( convertible_impl( py_sequence, mpl::int_< 0 >(), length_type() ) ){
            return py_obj;
        }
        else{
            return 0;
        }
    }