View | Details | Raw Unified | Return to bug 228
Collapse All | Expand All

(-)a/bindings/python/ns3modulegen_core_customizations.py (-4 / +20 lines)
 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 ();
(-)a/src/core/object.h (-17 / +18 lines)
 Lines 159-164   public: Link Here 
159
   */
159
   */
160
  AggregateIterator GetAggregateIterator (void) const;
160
  AggregateIterator GetAggregateIterator (void) const;
161
161
162
  /**
163
   * \param tid an TypeId
164
   *
165
   * Invoked from ns3::CreateObject only.
166
   * Initialize the m_tid member variable to
167
   * keep track of the type of this object instance.
168
   */
169
  void SetTypeId (TypeId tid);
170
   /**
171
   * \param attributes the attribute values used to initialize 
172
   *        the member variables of this object's instance.
173
   *
174
   * Invoked from ns3::ObjectFactory::Create and ns3::CreateObject only.
175
   * Initialize all the member variables which were
176
   * registered with the associated TypeId.
177
   */
178
  void Construct (const AttributeList &attributes);
179
162
protected:
180
protected:
163
  /**
181
  /**
164
   * This method is called by Object::Dispose or by the object's 
182
   * This method is called by Object::Dispose or by the object's 
 Lines 212-234   private: Link Here 
212
   * its aggregates are deleted. If not, nothing is done.
230
   * its aggregates are deleted. If not, nothing is done.
213
   */
231
   */
214
  void MaybeDelete (void) const;
232
  void MaybeDelete (void) const;
215
  /**
216
   * \param tid an TypeId
217
   *
218
   * Invoked from ns3::CreateObject only.
219
   * Initialize the m_tid member variable to
220
   * keep track of the type of this object instance.
221
   */
222
  void SetTypeId (TypeId tid);
223
   /**
224
   * \param attributes the attribute values used to initialize 
225
   *        the member variables of this object's instance.
226
   *
227
   * Invoked from ns3::ObjectFactory::Create and ns3::CreateObject only.
228
   * Initialize all the member variables which were
229
   * registered with the associated TypeId.
230
   */
231
  void Construct (const AttributeList &attributes);
232
233
233
  /**
234
  /**
234
   * The reference count for this object. Each aggregate
235
   * The reference count for this object. Each aggregate

Return to bug 228