本文整理汇总了C++中PyObjectPtr类的典型用法代码示例。如果您正苦于以下问题:C++ PyObjectPtr类的具体用法?C++ PyObjectPtr怎么用?C++ PyObjectPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyObjectPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Nonlocals_call
static PyObject*
Nonlocals_call( Nonlocals* self, PyObject* args, PyObject* kwargs )
{
unsigned int level;
static char* kwlist[] = { "level", 0 };
if( !PyArg_ParseTupleAndKeywords( args, kwargs, "I", kwlist, &level ) )
return 0;
unsigned int offset = 0;
PyObjectPtr parentptr;
PyObjectPtr objptr( newref( self->owner ) );
while( offset != level )
{
parentptr = PyObject_GetAttr( objptr.get(), parent_str );
if( !parentptr )
return 0;
if( parentptr.get() == Py_None )
break;
objptr = parentptr;
++offset;
}
if( offset != level )
{
PyErr_Format( PyExc_ValueError, "Scope level %u is out of range", level );
return 0;
}
PyObject* res = PyType_GenericNew( self->ob_type, 0, 0 );
if( res )
{
Nonlocals* nl = reinterpret_cast<Nonlocals*>( res );
nl->owner = objptr.newref();
nl->tracer = xnewref( self->tracer );
}
return res;
}
示例2: event_handler
static int
event_handler( Member* member, CAtom* atom, PyObject* value )
{
PyObjectPtr valueptr( member->full_validate( atom, Py_None, value ) );
if( !valueptr )
return -1;
if( atom->get_notifications_enabled() )
{
PyObjectPtr argsptr;
if( member->has_observers() )
{
argsptr = event_args( atom, member, valueptr.get() );
if( !argsptr )
return -1;
if( !member->notify( atom, argsptr.get(), 0 ) )
return -1;
}
if( atom->has_observers( member->name ) )
{
if( !argsptr )
{
argsptr = event_args( atom, member, valueptr.get() );
if( !argsptr )
return -1;
}
if( !atom->notify( member->name, argsptr.get(), 0 ) )
return -1;
}
}
return 0;
}
示例3: CAtom_observe
static PyObject*
CAtom_observe( CAtom* self, PyObject* args )
{
if( PyTuple_GET_SIZE( args ) != 2 )
return py_type_fail( "observe() takes exactly 2 arguments" );
PyObject* topic = PyTuple_GET_ITEM( args, 0 );
PyObject* callback = PyTuple_GET_ITEM( args, 1 );
if( PyString_Check( topic ) )
{
if( !self->observe( topic, callback ) )
return 0;
}
else
{
PyObjectPtr iterator( PyObject_GetIter( topic ) );
if( !iterator )
return 0;
PyObjectPtr topicptr;
while( ( topicptr = PyIter_Next( iterator.get() ) ) )
{
if( !self->observe( topicptr.get(), callback ) )
return 0;
}
if( PyErr_Occurred() )
return 0;
}
Py_RETURN_NONE;
}
示例4: importModule
PyObjectPtr importModule(const std::string& module)
{
PyObjectPtr pyModuleName = String::make(module).obj;
throwPythonException();
PyObjectPtr pyModule = makePyObjectPtr(PyImport_Import(pyModuleName.get()));
throwPythonException();
return pyModule;
}
示例5:
bool EntityApp<E>::destroyEntity(ENTITY_ID entityID, bool callScript)
{
PyObjectPtr entity = pEntities_->erase(entityID);
if(entity != NULL)
{
static_cast<E*>(entity.get())->destroy(callScript);
return true;
}
ERROR_MSG(boost::format("EntityApp::destroyEntity: not found %1%!\n") % entityID);
return false;
}
示例6: getAttribute
PyObjectPtr getAttribute(PyObjectPtr obj, const std::string& attribute)
{
PyObjectPtr pyAttr = makePyObjectPtr(PyObject_GetAttrString(
obj.get(), attribute.c_str()));
throwPythonException();
return pyAttr;
}
示例7: test_dynamic_attr
/*-----------------------------------------------------------------------------
| Utilities
|----------------------------------------------------------------------------*/
static int
test_dynamic_attr( PyObject* obj, PyObject* name )
{
PyTypeObject* tp;
PyObject** dictptr;
PyObjectPtr descr;
descrgetfunc descr_f;
PyObjectPtr objptr( newref( obj ) );
// The body of this loop is PyObject_GenericGetAttr, modified to
// use smart pointers and _PyObject_GetDictPtr, and only test for
// the presence of descriptors, not evaluate them.
while( objptr.get() != Py_None )
{
tp = Py_TYPE( objptr.get() );
// Data descriptor
descr_f = 0;
descr = xnewref( _PyType_Lookup( tp, name ) );
if( descr && PyType_HasFeature( descr.get()->ob_type, Py_TPFLAGS_HAVE_CLASS ) )
{
descr_f = descr.get()->ob_type->tp_descr_get;
if( descr_f && PyDescr_IsData( descr.get() ) )
return 1;
}
// Instance dictionary
dictptr = _PyObject_GetDictPtr( objptr.get() );
if( dictptr && *dictptr )
{
if( PyDict_GetItem( *dictptr, name ) )
return 1;
}
// Non-data descriptor
if( descr_f || descr )
return 1;
// Step up to the parent object
objptr = PyObject_GetAttr( objptr.get(), parent_str );
if( !objptr )
return -1;
}
return 0;
}
示例8: propHelper
/**
* Called when cloned to clear the cloned links.
*/
void EditorChunkItemLinkable::clearAllLinks()
{
// Clear from managers lists
WorldManager::instance().linkerManager().removeFromLists(this);
// Iterate through the properties of this linker
int propCounter = propHelper()->propCount();
for (int i=0; i < propCounter; i++)
{
DataDescription* pDD = propHelper()->pType()->property( i );
if (!pDD->editable())
continue;
// If this property is a linkable property
if (propHelper()->isUserDataObjectLink( i ))
{
propHelper()->propSetToDefault(i);
}
// If this property is an array of linkable properties
else if (propHelper()->isUserDataObjectLinkArray( i ))
{
PyObjectPtr ob
(
propHelper()->propGetPy( i ),
PyObjectPtr::STEAL_REFERENCE
);
SequenceDataType* dataType =
static_cast<SequenceDataType*>( pDD->dataType() );
ArrayPropertiesHelper propArray;
propArray.init(chunkItem(), &(dataType->getElemType()), ob.getObject());
// Iterate through the array of links
while (propArray.propCount())
{
// Delete the link
propArray.delItem(0);
}
}
}
// Save changes
chunkItem()->edSave( chunkItem()->pOwnSect() );
if ( chunkItem()->chunk() != NULL )
WorldManager::instance().changedChunk( chunkItem()->chunk() );
}
示例9: slot_handler
static int
slot_handler( Member* member, CAtom* atom )
{
if( member->index >= atom->get_slot_count() )
{
py_no_attr_fail( pyobject_cast( atom ), PyString_AsString( member->name ) );
return -1;
}
if( atom->is_frozen() )
{
PyErr_SetString( PyExc_AttributeError, "can't delete attribute of frozen Atom" );
return -1;
}
PyObjectPtr valueptr( atom->get_slot( member->index ) );
if( !valueptr )
return 0;
atom->set_slot( member->index, 0 );
if( atom->get_notifications_enabled() )
{
PyObjectPtr argsptr;
if( member->has_observers() )
{
argsptr = deleted_args( atom, member, valueptr.get() );
if( !argsptr )
return -1;
if( !member->notify( atom, argsptr.get(), 0 ) )
return -1;
}
if( atom->has_observers( member->name ) )
{
if( !argsptr )
{
argsptr = deleted_args( atom, member, valueptr.get() );
if( !argsptr )
return -1;
}
if( !atom->notify( member->name, argsptr.get(), 0 ) )
return -1;
}
}
return 0;
}
示例10:
//-------------------------------------------------------------------------------------
FileDataDownload::FileDataDownload(PyObjectPtr objptr,
const std::string & descr, int16 id):
DataDownload(objptr, descr, id)
{
wchar_t* PyUnicode_AsWideCharStringRet1 = PyUnicode_AsWideCharString(objptr.get(), NULL);
char* pDescr = strutil::wchar2char(PyUnicode_AsWideCharStringRet1);
PyMem_Free(PyUnicode_AsWideCharStringRet1);
path_ = pDescr;
free(pDescr);
stream_ = new char[65537];
}
示例11: _BoundSignal_New
static PyObject*
_BoundSignal_New( PyObject* owner, PyObject* objref )
{
PyObjectPtr ownerptr( owner, true );
PyObjectPtr objrefptr( objref, true );
PyObjectPtr bsigptr;
if( numfree > 0 )
{
PyObject* o = reinterpret_cast<PyObject*>( freelist[ --numfree ] );
_Py_NewReference( o );
bsigptr = o;
}
else
{
bsigptr = PyType_GenericAlloc( &BoundSignal_Type, 0 );
if( !bsigptr )
return 0;
}
BoundSignal* bsig = reinterpret_cast<BoundSignal*>( bsigptr.get() );
bsig->owner = ownerptr.release();
bsig->objref = objrefptr.release();
return bsigptr.release();
}
示例12: _CAtom_unobserve_2
static PyObject*
_CAtom_unobserve_2( CAtom* self, PyObject* topic, PyObject* callback )
{
if( PyString_Check( topic ) )
{
if( !self->unobserve( topic, callback ) )
return 0;
}
else
{
PyObjectPtr iterator( PyObject_GetIter( topic ) );
if( !iterator )
return 0;
PyObjectPtr topicptr;
while( ( topicptr = PyIter_Next( iterator.get() ) ) )
{
if( !self->unobserve( topicptr.get(), callback ) )
return 0;
}
if( PyErr_Occurred() )
return 0;
}
Py_RETURN_NONE;
}
示例13: SortedMap_new
static PyObject*
SortedMap_new( PyTypeObject* type, PyObject* args, PyObject* kwargs )
{
PyObject* map = 0;
static char* kwlist[] = { "map", 0 };
if( !PyArg_ParseTupleAndKeywords( args, kwargs, "|O:__new__", kwlist, &map ) )
return 0;
PyObject* self = PyType_GenericNew( type, 0, 0 );
if( !self )
return 0;
SortedMap* cself = reinterpret_cast<SortedMap*>( self );
cself->m_items = new SortedMap::Items();
PyObjectPtr seq;
if( map )
{
if( PyDict_Check( map ) )
{
seq = PyObject_GetIter( PyDict_Items( map ) );
if( !seq )
return 0;
}
else
{
seq = PyObject_GetIter( map );
if( !seq )
return 0;
}
}
if( seq )
{
PyObjectPtr item;
while( (item = PyIter_Next( seq.get() )) )
{
if( PySequence_Length( item.get() ) != 2)
return py_expected_type_fail( item.get(), "pairs of objects" );
cself->setitem( PySequence_GetItem( item.get(), 0 ),
PySequence_GetItem( item.get(), 1 ) );
}
}
return self;
}
示例14: set_dynamic_attr
static int
set_dynamic_attr( PyObject* obj, PyObject* name, PyObject* value )
{
PyTypeObject* tp;
PyObject* dict;
PyObject** dictptr;
PyObjectPtr descr;
descrsetfunc descr_f;
PyObjectPtr objptr( newref( obj ) );
// The body of this loop is PyObject_GenericGetAttr, modified to
// use smart pointers.
while( objptr.get() != Py_None )
{
tp = Py_TYPE( objptr.get() );
// Data desciptor
descr_f = 0;
descr = xnewref( _PyType_Lookup( tp, name ) );
if( descr && PyType_HasFeature( descr.get()->ob_type, Py_TPFLAGS_HAVE_CLASS ) )
{
descr_f = descr.get()->ob_type->tp_descr_set;
if( descr_f && PyDescr_IsData( descr.get() ) )
return descr_f( descr.get(), objptr.get(), value );
}
// Instance dictionary
dict = 0;
dictptr = _PyObject_GetDictPtr( obj );
if( dictptr )
{
dict = *dictptr;
if( !dict && value )
{
dict = PyDict_New();
if( !dict )
return -1;
*dictptr = dict;
}
}
if( dict )
{
if( value )
return PyDict_SetItem( dict, name, value );
if( PyDict_DelItem( dict, name ) == 0 )
return 0;
if( !PyErr_ExceptionMatches( PyExc_KeyError ) )
return -1;
PyErr_Clear();
}
// Non-data descriptor
if( descr_f )
return descr_f( descr.get(), objptr.get(), value );
// Read-only descriptor
if( descr )
PyErr_Format(
PyExc_AttributeError,
"'%.50s' object attribute '%.400s' is read-only",
tp->tp_name, PyString_AS_STRING( name )
);
// Step up to the parent object
objptr = PyObject_GetAttr( objptr.get(), parent_str );
if( !objptr )
return -1;
}
return -1;
}
示例15: load_dynamic_attr
static PyObject*
load_dynamic_attr( PyObject* obj, PyObject* name, PyObject* tracer=0 )
{
PyTypeObject* tp;
PyObject** dictptr;
PyObjectPtr descr;
descrgetfunc descr_f;
PyObjectPtr objptr( newref( obj ) );
// The body of this loop is PyObject_GenericGetAttr, modified to
// use smart pointers and _PyObject_GetDictPtr, and run a tracer.
while( objptr.get() != Py_None )
{
tp = Py_TYPE( objptr.get() );
// Data descriptor
descr_f = 0;
descr = xnewref( _PyType_Lookup( tp, name ) );
if( descr && PyType_HasFeature( descr.get()->ob_type, Py_TPFLAGS_HAVE_CLASS ) )
{
descr_f = descr.get()->ob_type->tp_descr_get;
if( descr_f && PyDescr_IsData( descr.get() ) )
{
PyObjectPtr res(
descr_f( descr.get(), objptr.get(), pyobject_cast( tp ) )
);
if( !res )
maybe_translate_key_error();
else if( tracer && !run_tracer( tracer, objptr.get(), name, res.get() ) )
return 0;
return res.release();
}
}
// Instance dictionary
dictptr = _PyObject_GetDictPtr( objptr.get() );
if( dictptr && *dictptr )
{
PyObject* item = PyDict_GetItem( *dictptr, name );
if( item )
{
if( tracer && !run_tracer( tracer, objptr.get(), name, item ) )
return 0;
return newref( item );
}
}
// Non-data descriptor
if( descr_f )
{
PyObjectPtr res(
descr_f( descr.get(), objptr.get(), pyobject_cast( tp ) )
);
if( !res )
maybe_translate_key_error();
else if( tracer && !run_tracer( tracer, objptr.get(), name, res.get() ) )
return 0;
return res.release();
}
// Non-readable descriptor
if( descr )
{
if( tracer && !run_tracer( tracer, objptr.get(), name, descr.get() ) )
return 0;
return descr.release();
}
// Step up to the parent object
objptr = PyObject_GetAttr( objptr.get(), parent_str );
if( !objptr )
return 0;
}
return 0;
}