|
Lines 475-480
static ns3::TypeId GetTypeId (void)
|
Link Here
|
|---|
|
| 475 |
Object.add_helper_class_hook(helper_class_hook) |
475 |
Object.add_helper_class_hook(helper_class_hook) |
| 476 |
|
476 |
|
| 477 |
## Replace all class constructors with a generic constructor based on CreateObject<T> (AttributeList) |
477 |
## Replace all class constructors with a generic constructor based on CreateObject<T> (AttributeList) |
|
|
478 |
module.header.writeln(''' |
| 479 |
namespace ns3 { |
| 480 |
template <typename T> |
| 481 |
Ptr<T> CreateObjectPython (PyObject *pyobj, const AttributeList &attributes) |
| 482 |
{ |
| 483 |
Ptr<T> p = Ptr<T> (new T (), false); |
| 484 |
p->set_pyobj (pyobj); |
| 485 |
p->SetTypeId (T::GetTypeId ()); |
| 486 |
p->Object::Construct (attributes); |
| 487 |
return p; |
| 488 |
} |
| 489 |
|
| 490 |
} // namespace ns3 |
| 491 |
|
| 492 |
''') |
| 493 |
|
| 478 |
for cls in module.classes: |
494 |
for cls in module.classes: |
| 479 |
if not cls.is_subclass(Object): |
495 |
if not cls.is_subclass(Object): |
| 480 |
continue |
496 |
continue |
|
Lines 500-509
static ns3::TypeId GetTypeId (void)
|
Link Here
|
|---|
|
| 500 |
construct_code = ''' |
516 |
construct_code = ''' |
| 501 |
if (self->ob_type != &%(PYTYPESTRUCT)s) |
517 |
if (self->ob_type != &%(PYTYPESTRUCT)s) |
| 502 |
{ |
518 |
{ |
| 503 |
ns3::Ptr< %(HELPER_CLASS_NAME)s > obj = ns3::CreateObject< %(HELPER_CLASS_NAME)s > (attrList); |
519 |
ns3::Ptr< %(HELPER_CLASS_NAME)s > obj = ns3::CreateObjectPython< %(HELPER_CLASS_NAME)s > ((PyObject *)self, attrList); |
| 504 |
obj->Ref (); |
520 |
obj->Ref (); |
| 505 |
self->obj = ns3::PeekPointer (obj); |
521 |
self->obj = ns3::PeekPointer (obj); |
| 506 |
((%(HELPER_CLASS_NAME)s*) self->obj)->set_pyobj((PyObject *)self); |
522 |
//((%(HELPER_CLASS_NAME)s*) self->obj)->set_pyobj((PyObject *)self); |
| 507 |
} else { |
523 |
} else { |
| 508 |
PyErr_SetString(PyExc_TypeError, "Class cannot be constructed (unless subclassed)"); |
524 |
PyErr_SetString(PyExc_TypeError, "Class cannot be constructed (unless subclassed)"); |
| 509 |
{ |
525 |
{ |
|
Lines 521-530
static ns3::TypeId GetTypeId (void)
|
Link Here
|
|---|
|
| 521 |
construct_code = ''' |
537 |
construct_code = ''' |
| 522 |
if (self->ob_type != &%(PYTYPESTRUCT)s) |
538 |
if (self->ob_type != &%(PYTYPESTRUCT)s) |
| 523 |
{ |
539 |
{ |
| 524 |
ns3::Ptr< %(HELPER_CLASS_NAME)s > obj = ns3::CreateObject< %(HELPER_CLASS_NAME)s > (attrList); |
540 |
ns3::Ptr< %(HELPER_CLASS_NAME)s > obj = ns3::CreateObjectPython< %(HELPER_CLASS_NAME)s > ((PyObject *)self, attrList); |
| 525 |
obj->Ref (); |
541 |
obj->Ref (); |
| 526 |
self->obj = ns3::PeekPointer (obj); |
542 |
self->obj = ns3::PeekPointer (obj); |
| 527 |
((%(HELPER_CLASS_NAME)s*) self->obj)->set_pyobj((PyObject *)self); |
543 |
//((%(HELPER_CLASS_NAME)s*) self->obj)->set_pyobj((PyObject *)self); |
| 528 |
} else { |
544 |
} else { |
| 529 |
ns3::Ptr< %(CONSTRUCT_NAME)s > obj = ns3::CreateObject< %(CONSTRUCT_NAME)s > (attrList); |
545 |
ns3::Ptr< %(CONSTRUCT_NAME)s > obj = ns3::CreateObject< %(CONSTRUCT_NAME)s > (attrList); |
| 530 |
obj->Ref (); |
546 |
obj->Ref (); |