本文整理汇总了C++中PyType_GenericNew函数的典型用法代码示例。如果您正苦于以下问题:C++ PyType_GenericNew函数的具体用法?C++ PyType_GenericNew怎么用?C++ PyType_GenericNew使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyType_GenericNew函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tp_new
static PyObject*
tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) {
SELF self;
soyatomsPosition* position = NULL;
float radius = 1.0;
soymaterialsMaterial* material = NULL;
// Ensure no keywords were given
if (!_PyArg_NoKeywords("soy.bodies.Sphere", kwds))
return NULL;
// Parse arguments
// TODO optional position radius and material parameters
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
// inherit base type
self = (SELF) PyType_GenericNew(type, args, kwds);
if (!self)
return NULL;
// new gobject
self->g = soy_bodies_sphere_new(position, radius, material);
// return self
return (PyObject*) self;
}
示例2: Alphabet_new
static PyObject *
Alphabet_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Alphabet *self = (Alphabet *)PyType_GenericNew(type, args, kwds);
self->alphabet = NULL;
return (PyObject *)self;
}
示例3: Net_new
static PyObject *
Net_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Net *self = (Net *)PyType_GenericNew(type, args, kwds);
/*I believe PyType_GenericNew zeros the memory, so all pointers are NULL, etc */
self->batch_size = 1;
return (PyObject *)self;
}
示例4: StdIO_tp_new
static PyObject *
StdIO_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
StdIO *self = (StdIO *)PyType_GenericNew(type, args, kwargs);
if (!self) {
return NULL;
}
return (PyObject *)self;
}
示例5: tp_new
static PyObject*
tp_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
SELF self;
PySoy_scenes_Scene_Object* scene;
PySoy_bodies_Body_Object* controlled;
PySoy_atoms_Position_Object* dest;
float radius, speed, granularity = -1.0f, fuzziness = -1.0f;
int updates = FALSE, paused = FALSE;
PyObject* bounds = Py_None;
static char *kw[] = {"scene", "controlled", "dest", "speed", "granularity", "fuzziness", "bounds", "updates", "paused", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!ff|fOii", kw,
&PySoy_scenes_Scene_Type, &scene,
&PySoy_bodies_Body_Type, &controlled,
&PySoy_atoms_Position_Type, &dest,
&speed,
&granularity,
&fuzziness,
&bounds,
&updates,
&paused))
return NULL;
if (fuzziness == -1.0f) {
fuzziness = speed/10000.0f;
} else if (fuzziness < 0.0f) {
PyErr_SetString(PyExc_ValueError, "'fuzziness' must be a number greater than 0");
return NULL;
}
self = (SELF) PyType_GenericNew(type, args, kwds);
if (!self)
return NULL;
if (bounds == Py_None) {
self->g = soy_controllers_space_navigator_new(scene->g, controlled->g, speed, fuzziness, granularity, dest->g, updates, paused);
} else if (PySoy_atoms_Size_Check(bounds)) {
soycontrollersgraphSpace* graph = soy_controllers_graph_space_new_with_size(scene->g, granularity, ((PySoy_atoms_Size_Object*)bounds)->g,NULL);
self->g = soy_controllers_space_navigator_new_with_graph(scene->g, controlled->g, speed, fuzziness, (soycontrollersgraphIGraph*) graph, dest->g, updates, paused);
} else if (PyNumber_Check(bounds)) {
PyObject* flt = PyNumber_Float(bounds);
if (flt == NULL)
return NULL;
radius = (float)PyFloat_AsDouble(flt);
Py_DECREF(flt);
if (PyErr_Occurred()) { return NULL; }
soycontrollersgraphSpace* graph = soy_controllers_graph_space_new_with_radius(scene->g, granularity, radius,NULL);
self->g = soy_controllers_space_navigator_new_with_graph(scene->g, controlled->g, speed, fuzziness, (soycontrollersgraphIGraph*) graph, dest->g, updates, paused);
} else {
PyErr_SetString(PyExc_ValueError, "'bounds' must be either a number greater then 0 or a soy.atoms.Size");
return NULL;
}
return (PyObject*) self;
}
示例6: Request_tp_new
static PyObject *
Request_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
Request *self = (Request *)PyType_GenericNew(type, args, kwargs);
if (!self) {
return NULL;
}
self->req_ptr = NULL;
return (PyObject *)self;
}
示例7: Connection_new
extern PyObject *
Connection_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {
ReQLConnection *self = (ReQLConnection *)PyType_GenericNew(type, args, kwargs);
if (self != NULL) {
self->reql_connection = NULL;
}
return (PyObject *)self;
}
示例8: DNSResolver_tp_new
static PyObject *
DNSResolver_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
DNSResolver *self = (DNSResolver *)PyType_GenericNew(type, args, kwargs);
if (!self) {
return NULL;
}
self->channel = NULL;
return (PyObject *)self;
}
示例9: cbson_dbref_tp_new
static PyObject *
cbson_dbref_tp_new (PyTypeObject *self,
PyObject *args,
PyObject *kwargs)
{
/*
* TODO: Handle args and kwargs.
*/
return PyType_GenericNew(&cbson_dbref_type, args, kwargs);
}
示例10:
//PyObject *PyNewLowercaser_Helper(PyObject *, PyObject* args)
PyObject *PyNewLowercaser_Helper(CSphLowercaser* aLower)
{
if(!aLower) return NULL;
csfHelper_ToLowerObject *self;
self = (csfHelper_ToLowerObject *)PyType_GenericNew(&csfHelper_ToLowerType, NULL, NULL);
self->m_Lower = aLower;
return (PyObject*)self;
}
示例11:
/* Allocate and initialize a new `Instruction' object given the associated
* `xed_decoded_inst_t' structure.
*/
instruction_t *new_instruction(xed_decoded_inst_t *decoded_inst,
xed_uint64_t runtime_address)
{
instruction_t *instruction;
instruction = (instruction_t *)PyType_GenericNew(&type, NULL, NULL);
instruction->decoded_inst = decoded_inst;
instruction->inst = xed_decoded_inst_inst(decoded_inst);
instruction->runtime_address = runtime_address;
return instruction;
}
示例12: tp_new
static PyObject*
tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
SELF self;
PySoy_bodies_Body_Object* py_bodyA;
PySoy_bodies_Body_Object* py_bodyB;
PySoy_materials_Material_Object* py_material = NULL;
soyscenesScene* scene;
soybodiesBody* bodyB;
soymaterialsMaterial* material;
static char* kw[] = {"bodyA", "bodyB", "material", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O|O!", kw,
&PySoy_bodies_Body_Type, &py_bodyA,
&py_bodyB,
&PySoy_materials_Material_Type, &py_material))
return NULL;
// When bodyB is a Body
if (PyObject_TypeCheck(py_bodyB, &PySoy_bodies_Body_Type)) {
scene = py_bodyB->g->scene;
bodyB = py_bodyB->g;
}
// When bodyB is a Scene
else if (PyObject_TypeCheck(py_bodyB, &PySoy_scenes_Scene_Type)) {
scene = ((PySoy_scenes_Scene_Object*) py_bodyB)->g;
bodyB = NULL;
}
// Otherwise raise exception
else {
PyErr_SetString(PyExc_ValueError,
"Second argument must be a Body or Scene");
return NULL;
}
// Ensure bodies are in the same scene
if (py_bodyA->g->scene != scene) {
PyErr_SetString(PyExc_ValueError, "Scene mismatch");
return NULL;
}
// Grab material
material = (py_material) ? py_material->g : NULL;
// Inherit base type
self = (SELF) PyType_GenericNew(type, args, NULL);
if(!self)
return NULL;
// Create gobject and return
self->g = soy_joints_fixed_new(py_bodyA->g, bodyB, material);
return (PyObject*) self;
}
示例13: tp_new
static PyObject*
tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
SELF self;
soyscenesScene* scene;
PySoy_scenes_Scene_Object* pyscene;
PySoy_bodies_Body_Object* bodyOne;
PySoy_bodies_Body_Object* bodyTwo;
PySoy_atoms_Position_Object* anchor;
PySoy_atoms_Axis_Object* axis1;
PySoy_atoms_Axis_Object* axis2;
if (PyArg_ParseTuple(args, "O!O!O!O!O!",
&PySoy_bodies_Body_Type, &bodyOne,
&PySoy_bodies_Body_Type, &bodyTwo,
&PySoy_atoms_Position_Type, &anchor,
&PySoy_atoms_Axis_Type, &axis1,
&PySoy_atoms_Axis_Type, &axis2))
scene = bodyTwo->g->scene;
else {
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!O!O!O!O!",
&PySoy_bodies_Body_Type, &bodyOne,
&PySoy_scenes_Scene_Type, &pyscene,
&PySoy_atoms_Position_Type, &anchor,
&PySoy_atoms_Axis_Type, &axis1,
&PySoy_atoms_Axis_Type, &axis2))
scene = pyscene->g;
else
return NULL;
}
// Ensure bodies are in the same scene
if (bodyOne->g->scene != scene) {
PyErr_SetString(PyExc_ValueError, "Bodies must be in the same scene");
return NULL;
}
self = (SELF) PyType_GenericNew(type, args, NULL);
if(!self)
return NULL;
if(!bodyTwo)
self->g = soy_joints_piston_new(bodyOne->g, NULL,
anchor->g, axis1->g, axis2->g,
NULL);
else
self->g = soy_joints_piston_new(bodyOne->g, bodyTwo->g,
anchor->g, axis1->g, axis2->g,
NULL);
return (PyObject*) self;
}
示例14: simple_new
static PyObject *
simple_new(PyObject *self, PyObject *type_object)
{
if (!PyType_Check(type_object))
{
PyErr_SetString(PyExc_TypeError,
"simple_new argument must be a type object.");
return NULL;
}
return PyType_GenericNew((PyTypeObject *)type_object, NULL, NULL);
}
示例15: Channel_tp_new
static PyObject *
Channel_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
Channel *self = (Channel *)PyType_GenericNew(type, args, kwargs);
if (!self) {
return NULL;
}
self->channel = NULL;
self->lib_initialized = False;
return (PyObject *)self;
}