src/core/object.h
changeset 2230 9f13ac3291e0
parent 1534 6b7a4e88c422
child 2231 a5b898c1ee2c
equal deleted inserted replaced
2205:57710f066013 2230:9f13ac3291e0
   164    * This method should be rarely called by users.
   164    * This method should be rarely called by users.
   165    */
   165    */
   166   virtual Ptr<TraceResolver> GetTraceResolver (void) const;
   166   virtual Ptr<TraceResolver> GetTraceResolver (void) const;
   167 protected:
   167 protected:
   168   /**
   168   /**
   169    * \param iid an InterfaceId
       
   170    *
       
   171    * Every subclass which defines a new InterfaceId for itself
       
   172    * should register this InterfaceId by calling this method
       
   173    * from its constructor.
       
   174    */
       
   175   void SetInterfaceId (InterfaceId iid);
       
   176   /**
       
   177    * This method is called by Object::Dispose.
   169    * This method is called by Object::Dispose.
   178    * Subclasses are expected to override this method and chain
   170    * Subclasses are expected to override this method and chain
   179    * up to their parent's implementation once they are done.
   171    * up to their parent's implementation once they are done.
   180    */
   172    */
   181   virtual void DoDispose (void);
   173   virtual void DoDispose (void);
   182 private:
   174 private:
   183   friend class InterfaceIdTraceResolver;
   175   friend class InterfaceIdTraceResolver;
       
   176   template <typename T>
       
   177   friend Ptr<T> CreateObject (void);
       
   178   template <typename T, typename T1>
       
   179   friend Ptr<T> CreateObject (T1 a1);
       
   180   template <typename T, typename T1, typename T2>
       
   181   friend Ptr<T> CreateObject (T1 a1, T2 a2);
       
   182   template <typename T, typename T1, typename T2, typename T3>
       
   183   friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3);
       
   184   template <typename T, typename T1, typename T2, typename T3, typename T4>
       
   185   friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4);
       
   186   template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
       
   187   friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
       
   188   template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
       
   189   friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
       
   190   template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
       
   191   friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7);
       
   192 
   184   Ptr<Object> DoQueryInterface (InterfaceId iid) const;
   193   Ptr<Object> DoQueryInterface (InterfaceId iid) const;
   185   void DoCollectSources (std::string path, const TraceContext &context, 
   194   void DoCollectSources (std::string path, const TraceContext &context, 
   186                          TraceResolver::SourceCollection *collection) const;
   195                          TraceResolver::SourceCollection *collection) const;
   187   void DoTraceAll (std::ostream &os, const TraceContext &context) const;
   196   void DoTraceAll (std::ostream &os, const TraceContext &context) const;
   188   bool Check (void) const;
   197   bool Check (void) const;
   189   bool CheckLoose (void) const;
   198   bool CheckLoose (void) const;
   190   void MaybeDelete (void) const;
   199   void MaybeDelete (void) const;
       
   200   /**
       
   201    * \param iid an InterfaceId
       
   202    *
       
   203    * Every subclass which defines a new InterfaceId for itself
       
   204    * should register this InterfaceId by calling this method
       
   205    * from its constructor.
       
   206    */
       
   207   void SetInterfaceId (InterfaceId iid);
       
   208 
   191   mutable uint32_t m_count;
   209   mutable uint32_t m_count;
   192   InterfaceId m_iid;
   210   InterfaceId m_iid;
   193   bool m_disposed;
   211   bool m_disposed;
   194   mutable bool m_collecting;
   212   mutable bool m_collecting;
   195   Object *m_next;
   213   Object *m_next;
   196 };
   214 };
   197 
   215 
       
   216 template <typename T>
       
   217 Ptr<T> CreateObject (void);
       
   218 
       
   219 template <typename T, typename T1>
       
   220 Ptr<T> CreateObject (T1 a1);
       
   221 
       
   222 template <typename T, typename T1, typename T2>
       
   223 Ptr<T> CreateObject (T1 a1, T2 a2);
       
   224 
       
   225 template <typename T, typename T1, typename T2, typename T3>
       
   226 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3);
       
   227 
       
   228 template <typename T, typename T1, typename T2, typename T3, typename T4>
       
   229 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4);
       
   230 
       
   231 template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
       
   232 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
       
   233 
       
   234 template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
       
   235 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
       
   236 
       
   237 template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
       
   238 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7);
       
   239 
   198 } // namespace ns3
   240 } // namespace ns3
   199 
   241 
   200 namespace ns3 {
   242 namespace ns3 {
   201 
   243 
   202 void
   244 void
   225       return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
   267       return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
   226     }
   268     }
   227   return 0;
   269   return 0;
   228 }
   270 }
   229 
   271 
       
   272 template <typename T>
       
   273 Ptr<T> CreateObject (void)
       
   274 {
       
   275   Ptr<T> p = Ptr<T> (new T (), false);
       
   276   p->SetInterfaceId (T::iid);
       
   277   return p;
       
   278 }
       
   279 
       
   280 template <typename T, typename T1>
       
   281 Ptr<T> CreateObject (T1 a1)
       
   282 {
       
   283   Ptr<T> p = Ptr<T> (new T (a1), false);
       
   284   p->SetInterfaceId (T::iid);
       
   285   return p;
       
   286 }
       
   287 
       
   288 template <typename T, typename T1, typename T2>
       
   289 Ptr<T> CreateObject (T1 a1, T2 a2)
       
   290 {
       
   291   Ptr<T> p = Ptr<T> (new T (a1, a2), false);
       
   292   p->SetInterfaceId (T::iid);
       
   293   return p;
       
   294 }
       
   295 
       
   296 template <typename T, typename T1, typename T2, typename T3>
       
   297 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3)
       
   298 {
       
   299   Ptr<T> p = Ptr<T> (new T (a1, a2, a3), false);
       
   300   p->SetInterfaceId (T::iid);
       
   301   return p;
       
   302 }
       
   303 
       
   304 template <typename T, typename T1, typename T2, typename T3, typename T4>
       
   305 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4)
       
   306 {
       
   307   Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4), false);
       
   308   p->SetInterfaceId (T::iid);
       
   309   return p;
       
   310 }
       
   311 
       
   312 template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
       
   313 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
       
   314 {
       
   315   Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4, a5), false);
       
   316   p->SetInterfaceId (T::iid);
       
   317   return p;
       
   318 }
       
   319 
       
   320 template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
       
   321 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
       
   322 {
       
   323   Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4, a5, a6), false);
       
   324   p->SetInterfaceId (T::iid);
       
   325   return p;
       
   326 }
       
   327 
       
   328 template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
       
   329 Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
       
   330 {
       
   331   Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4, a5, a6, a7), false);
       
   332   p->SetInterfaceId (T::iid);
       
   333   return p;
       
   334 }
       
   335 
       
   336 
   230 } // namespace ns3
   337 } // namespace ns3
   231 
   338 
   232 #endif /* OBJECT_H */
   339 #endif /* OBJECT_H */
   233 
   340