当前位置: 首页>>代码示例>>C++>>正文


C++ python::object类代码示例

本文整理汇总了C++中boost::python::object的典型用法代码示例。如果您正苦于以下问题:C++ object类的具体用法?C++ object怎么用?C++ object使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了object类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: callScintilla

boost::python::str ScintillaWrapper::getWord(boost::python::object position, boost::python::object useOnlyWordChars /* = true */)
{
	int pos;
	if (position.is_none())
	{
		pos = callScintilla(SCI_GETCURRENTPOS);
	}
	else
	{
		pos = boost::python::extract<int>(position);
	}

	bool wordChars;
	if (useOnlyWordChars.is_none())
	{
		wordChars = true;
	}
	else
	{
		wordChars = boost::python::extract<bool>(useOnlyWordChars);
	}

	int startPos = callScintilla(SCI_WORDSTARTPOSITION, pos, wordChars);
	int endPos = callScintilla(SCI_WORDENDPOSITION, pos, wordChars);
	Sci_TextRange tr;
	tr.chrg.cpMin = startPos;
	tr.chrg.cpMax = endPos;
	tr.lpstrText = new char[size_t((endPos - startPos) + 1)];
	callScintilla(SCI_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
	boost::python::str retVal(const_cast<const char *>(tr.lpstrText));
	delete[] tr.lpstrText;
	return retVal;
}
开发者ID:juntalis,项目名称:PythonScript,代码行数:33,代码来源:ScintillaWrapper.cpp

示例2: MaxMinPicks

// REVIEW: the poolSize can be pulled from the numeric array
RDKit::INT_VECT MaxMinPicks(MaxMinPicker *picker, python::object distMat,
                            int poolSize, int pickSize,
                            python::object firstPicks, int seed) {
  if (pickSize >= poolSize) {
    throw ValueErrorException("pickSize must be less than poolSize");
  }

  if (!PyArray_Check(distMat.ptr())) {
    throw ValueErrorException("distance mat argument must be a numpy matrix");
  }

  PyArrayObject *copy;
  copy = (PyArrayObject *)PyArray_ContiguousFromObject(distMat.ptr(),
                                                       PyArray_DOUBLE, 1, 1);
  double *dMat = (double *)copy->data;

  RDKit::INT_VECT firstPickVect;
  for (unsigned int i = 0;
       i < python::extract<unsigned int>(firstPicks.attr("__len__")()); ++i) {
    firstPickVect.push_back(python::extract<int>(firstPicks[i]));
  }
  RDKit::INT_VECT res =
      picker->pick(dMat, poolSize, pickSize, firstPickVect, seed);
  Py_DECREF(copy);
  return res;
}
开发者ID:DoliathGavid,项目名称:rdkit,代码行数:27,代码来源:MaxMinPicker.cpp

示例3: pySurf

	inGtsSurface(py::object _surf, bool _noPad=false): pySurf(_surf), noPad(_noPad), noPadWarned(false) {
		if(!pygts_surface_check(_surf.ptr())) throw std::invalid_argument("Ctor must receive a gts.Surface() instance."); 
		surf=PYGTS_SURFACE_AS_GTS_SURFACE(PYGTS_SURFACE(_surf.ptr()));
	 	if(!gts_surface_is_closed(surf)) throw std::invalid_argument("Surface is not closed.");
		is_open=gts_surface_volume(surf)<0.;
		if((tree=gts_bb_tree_surface(surf))==NULL) throw std::runtime_error("Could not create GTree.");
	}
开发者ID:DEMANY,项目名称:trunk,代码行数:7,代码来源:_packPredicates.cpp

示例4: if

      void SequenceTypeHandler<ContainerType>::set(Kernel::IPropertyManager* alg, const std::string &name,
                                                   const boost::python::object & value) const
      {
        using boost::python::len;
        typedef typename ContainerType::value_type DestElementType;

        // Current workaround for things that still pass back wrapped vectors...
        if(boost::starts_with(value.ptr()->ob_type->tp_name, "std_vector"))
        {
          alg->setProperty(name, StdVectorExtractor<DestElementType>::extract(value));
        }
        // numpy arrays requires special handling to extract their types. Hand-off to a more appropriate handler
        else if( PyArray_Check(value.ptr()) )
        {
          alg->setProperty(name, Converters::NDArrayToVector<DestElementType>(value)());
        }
        else if( PySequence_Check(value.ptr()) )
        {
          alg->setProperty(name, Converters::PySequenceToVector<DestElementType>(value)());
        }
        else // assume it is a scalar and try to convert into a vector of length one
        {
          DestElementType scalar = boost::python::extract<DestElementType>(value.ptr());
          alg->setProperty(name, std::vector<DestElementType>(1, scalar));
        }
      }
开发者ID:BigShows,项目名称:mantid,代码行数:26,代码来源:SequenceTypeHandler.cpp

示例5: update

    void update(boost::python::object source)
    {
        // See if we have a dictionary-like object.
        if (py_hasattr(source, "items"))
        {
            return this->update(source.attr("items")());
        }
        if (!py_hasattr(source, "__iter__")) {
            THROW_EX(ValueError, "Must provide a dictionary-like object to update()");
        }

        object iter = source.attr("__iter__")();
        while (true) {
            PyObject *pyobj = PyIter_Next(iter.ptr());
            if (!pyobj) break;
            if (PyErr_Occurred()) {
                throw_error_already_set();
            }

            object obj = object(handle<>(pyobj));

            tuple tup = extract<tuple>(obj);
            std::string attr = extract<std::string>(tup[0]);
            std::string value = extract<std::string>(tup[1]);
            setitem(attr, value);
        }
    }
开发者ID:,项目名称:,代码行数:27,代码来源:

示例6: call

void OutputHook::call(std::string name, boost::python::object obj)
{
    Hooks::checkName(name);

    auto repr_ = PyObject_Repr(obj.ptr());
    if (PyErr_Occurred())
    {
        PyErr_Clear();
        throw Hooks::Exception("Failed to get __repr__ of argument");
    }
    auto repr = std::string(PyUnicode_AsUTF8(repr_));
    Py_DECREF(repr_);

    PyObject* g = Py_BuildValue(
            "{sO}", "__builtins__", PyEval_GetBuiltins());
    node->parent->loadDatumHooks(g);
    auto out = PyRun_String(repr.c_str(), Py_eval_input, g, g);
    Py_DECREF(g);
    Py_XDECREF(out);
    if (PyErr_Occurred())
    {
        PyErr_Clear();
        throw Hooks::Exception("Could not evaluate __repr__ of output");
    }

    const bool result = node->makeDatum(
            name, obj.ptr()->ob_type, Datum::SIGIL_OUTPUT + repr, true);

    if (!result)
        throw Hooks::Exception("Datum was already defined in this script.");
}
开发者ID:CreativeLabs0X3CF,项目名称:antimony,代码行数:31,代码来源:output.cpp

示例7: it

TypeGeneral::EdgeData::EdgeData(const py::object& obj)
{
    typedef TypeGeneral::REAL REAL;
    bool isiterable = PyObject_HasAttrString(obj.ptr(), "__iter__");
    
    if(isiterable)
    {
        py::stl_input_iterator<REAL> it(obj), end;
        bool haslen = PyObject_HasAttrString(obj.ptr(), "__len__");
        
        m_type = GENERAL;
        
        if(haslen)
        {
            m_dataGeneral.resize(py::len(obj));
            std::copy(it, end, m_dataGeneral.begin());
        }
        else
        {
            for(; it!=end; ++it)
            {
               m_dataGeneral.push_back(*it);
               std::cout << *it << " ";
            }
        }
    }
    else
    {
        m_type = POTTS;
        m_lambdaPotts = py::extract<REAL>(obj);
    }
}
开发者ID:guorongYu,项目名称:PyTrw,代码行数:32,代码来源:python.cpp

示例8: fromNumpyVector

/** Converts a one-dimensional numpy vector to eigen VectorXd. */
Eigen::VectorXd fromNumpyVector(py::object vec) {
	assert(("Input numpy matrix is not one dimensional.", py::extract<int>(vec.attr("ndim"))==1));
	vec = np_mod.attr("array")(vec, "float64");
	int size = py::extract<int>(vec.attr("size"));

	double* vec_data = getPointer<double>(vec);
	return Eigen::Map<Eigen::VectorXd>(vec_data, size);
}
开发者ID:ankush-me,项目名称:regopt,代码行数:9,代码来源:numpy_utils.hpp

示例9: sizeof

 static void from2dArray(PointCloudT* cloud, py::object arr) {
   arr = np_mod.attr("array")(arr, "float32");
   int npoints = py::extract<int>(arr.attr("shape")[0]);
   int floatfields = py::extract<int>(arr.attr("shape")[1]);
   FAIL_IF_FALSE(floatfields == sizeof(T)/4);
   cloud->resize(npoints);
   float* p = getPointer<float>(arr);
   memcpy(&cloud->points[0], p,  npoints*floatfields*sizeof(float));
 }
开发者ID:panjia1983,项目名称:hd_trajopt,代码行数:9,代码来源:cloudprocpy.cpp

示例10: fromNumpy

/** Converts a two-dimensional numpy matrix to eigen MatrixXd. */
Eigen::MatrixXd fromNumpy(py::object mat) {
	assert(("Input numpy matrix is not two dimensional.", py::extract<int>(mat.attr("ndim"))==2));
	mat = np_mod.attr("array")(mat, "float64");
	int rows = py::extract<int>(mat.attr("shape")[0]);
	int cols = py::extract<int>(mat.attr("shape")[1]);

	double* mat_data = getPointer<double>(mat);
	return Eigen::Map<Eigen::MatrixXd>(mat_data, rows, cols);
}
开发者ID:ankush-me,项目名称:regopt,代码行数:10,代码来源:numpy_utils.hpp

示例11: mat

static Eigen::MatrixXd fromNP(py::object arr) {
  arr = np_mod.attr("array")(arr, "float64");
  int rows = py::extract<int>(arr.attr("shape")[0]);
  int cols = py::extract<int>(arr.attr("shape")[1]);
  Eigen::MatrixXd mat(rows, cols);
  double* p = getPointer<double>(arr);
  memcpy(&mat(0,0), p,  rows*cols*sizeof(double));
  return mat;
}
开发者ID:ankush-me,项目名称:regopt,代码行数:9,代码来源:numpy_utils.hpp

示例12: convert2valarray

 std::valarray<T> convert2valarray(boost::python::object arr)
 {
   import();                 // ### WARNING: forgetting this will end up in segmentation fault!
   
   std::size_t vec_size = PyArray_Size(arr.ptr());
   T * data = (T *) PyArray_DATA(arr.ptr());
   std::valarray<T> vec(vec_size);
   memcpy(&vec[0],data, PyArray_ITEMSIZE((PyArrayObject*) arr.ptr()) * vec_size);
   return vec;
 }
开发者ID:wangleiphy,项目名称:ALPSCore,代码行数:10,代码来源:numpy_array.hpp

示例13: send_alive

void send_alive(boost::python::object ad_obj=boost::python::object(), boost::python::object pid_obj=boost::python::object(), boost::python::object timeout_obj=boost::python::object())
{
    std::string addr;
    if (ad_obj.ptr() == Py_None)
    {
        char *inherit_var = getenv("CONDOR_INHERIT");
        if (!inherit_var) {
            THROW_EX(RuntimeError, "No location specified and $CONDOR_INHERIT not in Unix environment.");
        }
        std::string inherit(inherit_var);
        boost::python::object inherit_obj(inherit);
        boost::python::object inherit_split = inherit_obj.attr("split")();
        if (py_len(inherit_split) < 2) {
            THROW_EX(RuntimeError, "$CONDOR_INHERIT Unix environment variable malformed.");
        }
        addr = boost::python::extract<std::string>(inherit_split[1]);
    }
    else
    {
        const ClassAdWrapper ad = boost::python::extract<ClassAdWrapper>(ad_obj);
        if (!ad.EvaluateAttrString(ATTR_MY_ADDRESS, addr))
        {
            THROW_EX(ValueError, "Address not available in location ClassAd.");
        }
    }
    int pid = getpid();
    if (pid_obj.ptr() != Py_None)
    {
        pid = boost::python::extract<int>(pid_obj);
    }
    int timeout;
    if (timeout_obj.ptr() == Py_None)
    {
        timeout = param_integer("NOT_RESPONDING_TIMEOUT");
    }
    else
    {
        timeout = boost::python::extract<int>(timeout_obj);
    }
    if (timeout < 1) {
        timeout = 1;
    }

    classy_counted_ptr<Daemon> daemon = new Daemon(DT_ANY, addr.c_str());
    classy_counted_ptr<ChildAliveMsg> msg = new ChildAliveMsg(pid, timeout, 0, 0, true);

    {
        condor::ModuleLock ml;
        daemon->sendBlockingMsg(msg.get());
    }
    if (msg->deliveryStatus() != DCMsg::DELIVERY_SUCCEEDED)
    {
        THROW_EX(RuntimeError, "Failed to deliver keepalive message.");
    }
}
开发者ID:blueskyll,项目名称:condor,代码行数:55,代码来源:dc_tool.cpp

示例14: sequence_len

inline index_type sequence_len(boost::python::object const& obj){
    if( !PySequence_Check( obj.ptr() ) ){
        raise_error( PyExc_TypeError, "Sequence expected" );
    }

    index_type result = PyObject_Length( obj.ptr() );
    if( PyErr_Occurred() ){
        boost::python::throw_error_already_set();
    }
    return result;
}
开发者ID:JaneliaSciComp,项目名称:osgpyplusplus,代码行数:11,代码来源:__convenience.pypp.hpp

示例15: checkRadii

 // Used by multiple profile classes to ensure at most one radius is given.
 static void checkRadii(const bp::object & r1, const bp::object & r2, const bp::object & r3) 
 {
     int nRad = (r1.ptr() != Py_None) + (r2.ptr() != Py_None) + (r3.ptr() != Py_None);
     if (nRad > 1) {
         PyErr_SetString(PyExc_TypeError, "Multiple radius parameters given");
         bp::throw_error_already_set();
     }
     if (nRad == 0) {
         PyErr_SetString(PyExc_TypeError, "No radius parameter given");
         bp::throw_error_already_set();
     }
 }
开发者ID:alexabate,项目名称:GalSim,代码行数:13,代码来源:SBExponential.cpp


注:本文中的boost::python::object类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。