Files
unison/src/core/object.h

750 lines
21 KiB
C
Raw Normal View History

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA, Gustavo Carneiro
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Gustavo Carneiro <gjcarneiro@gmail.com>,
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
2007-05-25 10:02:50 +02:00
#ifndef OBJECT_H
#define OBJECT_H
#include <stdint.h>
#include <string>
#include "ptr.h"
#include "trace-resolver.h"
2008-01-02 15:54:53 +01:00
#include "callback.h"
2008-02-20 21:45:42 +01:00
#include "attribute.h"
#include "object-base.h"
2008-01-03 11:30:02 +01:00
#define NS_OBJECT_ENSURE_REGISTERED(type) \
static struct X##type##RegistrationClass \
{ \
X##type##RegistrationClass () { \
ns3::TypeId tid = type::GetTypeId (); \
2008-01-15 12:44:09 +01:00
tid.GetParent (); \
2008-01-03 11:30:02 +01:00
} \
} x_##type##RegistrationVariable
namespace ns3 {
class TraceContext;
class CallbackBase;
2008-01-02 15:54:53 +01:00
class Object;
2008-02-20 20:57:59 +01:00
class AttributeAccessor;
2008-02-20 21:17:34 +01:00
class AttributeValue;
class Parameters;
2007-05-25 18:00:50 +02:00
/**
* \brief a unique identifier for an interface.
*
* This class records a lot of meta-information about a
* subclass of the Object base class:
* - the base class of the subclass
* - the set of accessible constructors in the subclass
* - the set of 'parameters' accessible in the subclass
2007-05-25 18:00:50 +02:00
*/
2008-01-15 12:36:22 +01:00
class TypeId
{
public:
enum {
2008-02-20 19:33:59 +01:00
ATTR_GET = 1<<0,
ATTR_SET = 1<<1,
ATTR_CONSTRUCT = 1<<2,
ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT,
};
2007-05-25 18:00:50 +02:00
/**
* \param name the name of the requested interface
* \returns the unique id associated with the requested
* name.
*
* This method cannot fail: it will crash if the input
* name is not a valid interface name.
*/
2008-01-15 12:36:22 +01:00
static TypeId LookupByName (std::string name);
/**
* \returns the number of TypeId instances constructed
*/
static uint32_t GetRegisteredN (void);
/**
* \param i index
* \returns the TypeId instance whose index is \i.
*/
2008-01-15 12:36:22 +01:00
static TypeId GetRegistered (uint32_t i);
/**
* \param name the name of the interface to construct.
*
* No two instances can share the same name.
*/
TypeId (std::string name);
2007-05-25 18:00:50 +02:00
/**
* \returns the parent of this TypeId
2007-05-25 18:00:50 +02:00
*
* This method cannot fail: it will crash if the input
* id is not a valid interface id.
*/
2008-01-15 12:36:22 +01:00
TypeId GetParent (void) const;
/**
* \returns the name of the group associated to this TypeId.
*/
std::string GetGroupName (void) const;
/**
* \returns the fully-qualified C++ typename of this TypeId.
*/
std::string GetTypeName (void) const;
/**
* \returns the name of this interface.
*/
std::string GetName (void) const;
2008-01-02 15:54:53 +01:00
2008-01-03 09:10:23 +01:00
/**
2008-01-15 12:36:22 +01:00
* \returns true if this TypeId has a constructor
2008-01-03 09:10:23 +01:00
*/
bool HasConstructor (void) const;
/**
* \returns the number of parameters associated to this TypeId
*/
uint32_t GetParametersN (void) const;
/**
* \param i index into parameter array
* \returns the name associated to the parameter whose
* index is \i i.
*/
std::string GetParameterName (uint32_t i) const;
/**
* \param i index into parameter array
* \returns the full name associated to the parameter whose
* index is \i i.
*/
std::string GetParameterFullName (uint32_t i) const;
2008-02-20 19:57:31 +01:00
Attribute GetParameterInitialValue (uint32_t i) const;
2008-02-17 04:38:34 +01:00
Ptr<Object> CreateObject (const Parameters &parameters) const;
2008-01-02 15:54:53 +01:00
Ptr<Object> CreateObject (void) const;
template <typename T1>
Ptr<Object> CreateObject (T1 a1) const;
template <typename T1, typename T2>
Ptr<Object> CreateObject (T1 a1, T2 a2) const;
/**
* \param tid the TypeId of the base class.
* \return this TypeId instance.
*
* Record in this TypeId which TypeId is the TypeId
* of the base class of the subclass.
*/
2008-01-15 12:44:09 +01:00
TypeId SetParent (TypeId tid);
/**
* \return this TypeId instance.
*
* Record in this TypeId which TypeId is the TypeId
* of the base class of the subclass.
*/
2008-01-03 08:34:31 +01:00
template <typename T>
2008-01-15 12:36:22 +01:00
TypeId SetParent (void);
2008-01-03 08:34:31 +01:00
/**
* \param groupName the name of the group this TypeId belongs to.
* \returns this TypeId instance.
*
* The group name is purely an advisory information used to
* group together types according to a user-specific grouping
* scheme.
*/
TypeId SetGroupName (std::string groupName);
/**
* \param typeName the fully-qualified C++ typename of this TypeId.
* \returns this TypeId instance.
*/
TypeId SetTypeName (std::string typeName);
/**
* \returns this TypeId instance
*
* Record in this TypeId the fact that the default constructor
* is accessible.
*/
2008-01-02 15:54:53 +01:00
template <typename T>
2008-01-15 12:36:22 +01:00
TypeId AddConstructor (void);
2008-01-02 15:54:53 +01:00
template <typename T, typename T1>
2008-01-15 12:36:22 +01:00
TypeId AddConstructor (void);
2008-01-02 15:54:53 +01:00
template <typename T, typename T1, typename T2>
2008-01-15 12:36:22 +01:00
TypeId AddConstructor (void);
2008-01-02 15:54:53 +01:00
/**
* \param name the name of the new parameter
* \param help some help text which describes the purpose of this
* parameter
2008-02-20 20:24:52 +01:00
* \param param an instance of the associated Accessor subclass
* \returns this TypeId instance
*
* Record in this TypeId the fact that a new parameter exists.
*/
TypeId AddParameter (std::string name,
2008-02-17 04:38:34 +01:00
std::string help,
2008-02-20 19:57:31 +01:00
Attribute initialValue,
2008-02-20 20:57:59 +01:00
Ptr<const AttributeAccessor> spec,
2008-02-18 00:18:45 +01:00
Ptr<const AttributeChecker> checker);
2008-01-02 15:54:53 +01:00
/**
* \param name the name of the new parameter
* \param help some help text which describes the purpose of this
* parameter
* \param flags flags which describe how this parameter can be read and/or written.
2008-02-20 20:24:52 +01:00
* \param param an instance of the associated Accessor subclass
* \returns this TypeId instance
*
* Record in this TypeId the fact that a new parameter exists.
*/
TypeId AddParameter (std::string name,
std::string help,
uint32_t flags,
2008-02-20 19:57:31 +01:00
Attribute initialValue,
2008-02-20 20:57:59 +01:00
Ptr<const AttributeAccessor> spec,
2008-02-18 00:18:45 +01:00
Ptr<const AttributeChecker> checker);
2008-01-02 15:54:53 +01:00
// construct an invalid TypeId.
TypeId ();
2008-01-15 12:36:22 +01:00
~TypeId ();
private:
friend class Object;
friend class Parameters;
2008-01-15 12:36:22 +01:00
friend bool operator == (TypeId a, TypeId b);
friend bool operator != (TypeId a, TypeId b);
2008-01-02 15:54:53 +01:00
2008-02-06 18:31:15 +01:00
struct ParameterInfo {
2008-02-20 20:57:59 +01:00
Ptr<const AttributeAccessor> spec;
2008-02-20 19:57:31 +01:00
Attribute initialValue;
2008-02-06 18:31:15 +01:00
uint32_t flags;
2008-02-18 00:18:45 +01:00
Ptr<const AttributeChecker> checker;
2008-02-06 18:31:15 +01:00
};
/**
* \param name the name of the requested parameter
2008-02-20 20:24:52 +01:00
* \returns the Accessor associated to the requested parameter
*/
2008-02-06 18:31:15 +01:00
bool LookupParameterByName (std::string name, struct ParameterInfo *info) const;
/**
* \param i the position of the requested parameter
2008-02-20 20:24:52 +01:00
* \returns the Accessor associated to the requested parameter
*/
2008-02-06 18:31:15 +01:00
bool LookupParameterByPosition (uint32_t i, struct ParameterInfo *info) const;
/**
* \param fullName the full name of the requested parameter
2008-02-20 20:24:52 +01:00
* \returns the Accessor associated to the requested parameter
*/
2008-02-06 18:31:15 +01:00
static bool LookupParameterByFullName (std::string fullName, struct ParameterInfo *info);
2008-01-15 12:44:09 +01:00
explicit TypeId (uint16_t tid);
2008-01-02 15:54:53 +01:00
void DoAddConstructor (CallbackBase callback, uint32_t nArguments);
CallbackBase LookupConstructor (uint32_t nArguments) const;
2008-02-20 20:57:59 +01:00
Ptr<const AttributeAccessor> GetParameterAccessor (uint32_t i) const;
2008-02-06 18:31:15 +01:00
uint32_t GetParameterFlags (uint32_t i) const;
2008-02-18 00:18:45 +01:00
Ptr<const AttributeChecker> GetParameterChecker (uint32_t i) const;
2008-01-02 15:54:53 +01:00
2008-01-15 12:44:09 +01:00
uint16_t m_tid;
};
/**
* \brief a container of parameters to be used during object's construction
* and in ns3::Object::Set.
*
*/
class Parameters
{
public:
Parameters ();
Parameters (const Parameters &o);
Parameters &operator = (const Parameters &o);
~Parameters ();
/**
* \param name the name of the parameter to set
* \param value the value to set
*
* This method checks that a parameter with the requested
* name exists and that the value specified is an acceptable
* value of that parameter. If any of these checks fails,
* the program terminates with a message.
*/
2008-02-20 19:57:31 +01:00
bool Set (std::string name, Attribute value);
2008-02-20 19:57:31 +01:00
void SetWithTid (TypeId tid, std::string name, Attribute value);
void SetWithTid (TypeId tid, uint32_t position, Attribute value);
/**
* Clear the content of this instance.
*/
void Reset (void);
/**
* \returns the global parameter container
*
* The global parameter container can be used to specify
* a set of parameter values without having to re-specify
* them for each object when it is created. This container
* is checked only during object construction and
* it is always checked last, after any per-object
* container is checked.
*/
static Parameters *GetGlobal (void);
std::string SerializeToString (void) const;
bool DeserializeFromString (std::string value);
private:
friend class Object;
struct Param {
2008-02-18 00:18:45 +01:00
Ptr<const AttributeChecker> checker;
2008-02-20 19:57:31 +01:00
Attribute value;
};
typedef std::vector<struct Param> Params;
typedef Params::iterator Iterator;
typedef Params::const_iterator CIterator;
2008-02-20 19:57:31 +01:00
bool DoSet (struct TypeId::ParameterInfo *info, Attribute param);
void DoSetOne (Ptr<const AttributeChecker> checker, Attribute param);
2008-02-18 00:18:45 +01:00
std::string LookupParameterFullNameByChecker (Ptr<const AttributeChecker> checker) const;
Params m_parameters;
};
2007-05-25 18:00:50 +02:00
/**
* \brief a base class which provides memory management and object aggregation
*
*/
2008-01-30 17:25:06 +01:00
class Object : public ObjectBase
{
public:
2008-01-15 12:43:07 +01:00
static TypeId GetTypeId (void);
2007-05-25 10:02:50 +02:00
Object ();
virtual ~Object ();
/**
* \param name the name of the parameter to set
* \param value the name of the parameter to set
*
* Set a single parameter.
*/
2008-02-20 19:57:31 +01:00
bool Set (std::string name, Attribute value);
/**
* \param name the name of the parameter to read
* \param value a reference to the string where the value of the
* parameter should be stored.
* \returns true if the requested parameter was found, false otherwise.
*/
bool Get (std::string name, std::string &value) const;
/**
* \param name the name of the parameter to read
* \param value a reference to the object where the value of the
* parameter should be stored.
* \returns true if the requested parameter was found, false otherwise.
*/
2008-02-20 19:57:31 +01:00
Attribute Get (std::string name) const;
2007-05-25 18:00:50 +02:00
/**
* Increment the reference count. This method should not be called
* by user code. Object instances are expected to be used in conjunction
* of the Ptr template which would make calling Ref unecessary and
* dangerous.
*/
2007-05-25 10:02:50 +02:00
inline void Ref (void) const;
2007-05-25 18:00:50 +02:00
/**
* Decrement the reference count. This method should not be called
* by user code. Object instances are expected to be used in conjunction
* of the Ptr template which would make calling Ref unecessary and
* dangerous.
*/
2007-05-25 10:02:50 +02:00
inline void Unref (void) const;
2007-05-25 18:00:50 +02:00
/**
* \returns a pointer to the requested interface or zero if it could not be found.
*/
template <typename T>
2008-01-31 22:11:03 +01:00
Ptr<T> GetObject (void) const;
/**
2008-01-15 12:44:09 +01:00
* \param tid the interface id of the requested interface
* \returns a pointer to the requested interface or zero if it could not be found.
2007-05-25 18:00:50 +02:00
*/
template <typename T>
2008-01-31 22:11:03 +01:00
Ptr<T> GetObject (TypeId tid) const;
2007-05-25 18:00:50 +02:00
/**
* Run the DoDispose methods of this object and all the
* objects aggregated to it.
* After calling this method, the object is expected to be
* totally unusable except for the Ref and Unref methods.
* It is an error to call Dispose twice on the same object
* instance
*/
void Dispose (void);
2007-05-25 18:00:50 +02:00
/**
* \param other another object pointer
*
* This method aggregates the two objects together: after this
2008-01-31 22:11:03 +01:00
* method returns, it becomes possible to call GetObject
2007-05-25 18:00:50 +02:00
* on one to get the other, and vice-versa.
*/
2008-01-31 22:23:46 +01:00
void AggregateObject (Ptr<Object> other);
2007-08-10 14:43:15 +02:00
2007-08-28 13:14:43 +02:00
/**
* \param path the path to match for the callback
* \param cb callback to connect
*
* Connect the input callback to all trace sources which
* match the input path.
*
*/
2007-08-28 14:33:53 +02:00
void TraceConnect (std::string path, const CallbackBase &cb) const;
2007-08-28 13:14:43 +02:00
/**
* \param path the path to match for the callback
* \param cb callback to disconnect
*
* Disconnect the input callback from all trace sources which
* match the input path.
*/
2007-08-28 14:33:53 +02:00
void TraceDisconnect (std::string path, const CallbackBase &cb) const;
2007-08-28 13:14:43 +02:00
/**
* \returns the trace resolver associated to this object.
*
* This method should be rarely called by users.
*/
2007-08-28 14:33:53 +02:00
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
protected:
2007-05-25 18:00:50 +02:00
/**
* This method is called by Object::Dispose.
* Subclasses are expected to override this method and chain
* up to their parent's implementation once they are done.
*/
virtual void DoDispose (void);
virtual void NotifyConstructionCompleted (void);
2007-05-25 10:02:50 +02:00
private:
2008-01-15 12:36:22 +01:00
friend class TypeIdTraceResolver;
template <typename T>
friend Ptr<T> CreateObject (const Parameters &parameters);
template <typename T>
friend Ptr<T> CreateObject (void);
template <typename T, typename T1>
friend Ptr<T> CreateObject (T1 a1);
template <typename T, typename T1, typename T2>
friend Ptr<T> CreateObject (T1 a1, T2 a2);
template <typename T, typename T1, typename T2, typename T3>
friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3);
template <typename T, typename T1, typename T2, typename T3, typename T4>
friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4);
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
friend Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7);
2008-02-20 20:57:59 +01:00
bool DoSet (Ptr<const AttributeAccessor> spec, Attribute intialValue,
2008-02-20 19:57:31 +01:00
Ptr<const AttributeChecker> checker, Attribute value);
2008-01-31 22:11:03 +01:00
Ptr<Object> DoGetObject (TypeId tid) const;
void DoCollectSources (std::string path, const TraceContext &context,
2007-08-28 14:33:53 +02:00
TraceResolver::SourceCollection *collection) const;
2007-09-06 13:32:29 +02:00
void DoTraceAll (std::ostream &os, const TraceContext &context) const;
2007-05-25 10:02:50 +02:00
bool Check (void) const;
bool CheckLoose (void) const;
/**
* Attempt to delete this object. This method iterates
* over all aggregated objects to check if they all
* have a zero refcount. If yes, the object and all
* its aggregates are deleted. If not, nothing is done.
*/
2007-05-25 10:02:50 +02:00
void MaybeDelete (void) const;
/**
2008-01-15 12:44:09 +01:00
* \param tid an TypeId
*
* Invoked from ns3::CreateObject only.
* Initialize the m_tid member variable to
* keep track of the type of this object instance.
*/
2008-01-15 12:44:09 +01:00
void SetTypeId (TypeId tid);
/**
* \param parameters the parameter values used to initialize
* the member variables of this object's instance.
*
* Invoked from ns3::CreateObject only.
* Initialize all the member variables which were
* registered with the associated TypeId.
*/
void Construct (const Parameters &parameters);
/**
* The reference count for this object. Each aggregate
* has an individual reference count. When the global
* reference count (the sum of all reference counts)
* reaches zero, the object and all its aggregates is
* deleted.
*/
2007-05-25 10:02:50 +02:00
mutable uint32_t m_count;
/**
* Identifies the type of this object instance.
*/
2008-01-15 12:44:09 +01:00
TypeId m_tid;
/**
* Set to true when the DoDispose method of the object
* has run, false otherwise.
*/
2007-05-25 12:27:40 +02:00
bool m_disposed;
2007-08-28 14:33:53 +02:00
mutable bool m_collecting;
/**
* A pointer to the next aggregate object. This is a circular
* linked list of aggregated objects: the last one points
* back to the first one. If an object is not aggregated to
* any other object, the value of this field is equal to the
* value of the 'this' pointer.
*/
2007-05-25 10:02:50 +02:00
Object *m_next;
};
} // namespace ns3
namespace ns3 {
/*************************************************************************
* The TypeId implementation which depends on templates
*************************************************************************/
2008-01-03 08:34:31 +01:00
template <typename T>
2008-01-15 12:36:22 +01:00
TypeId
TypeId::SetParent (void)
2008-01-03 08:34:31 +01:00
{
2008-01-15 12:43:07 +01:00
return SetParent (T::GetTypeId ());
2008-01-03 08:34:31 +01:00
}
2008-01-02 15:54:53 +01:00
template <typename T>
2008-01-15 12:36:22 +01:00
TypeId
TypeId::AddConstructor (void)
2008-01-02 15:54:53 +01:00
{
struct Maker {
static Ptr<Object> Create (const Parameters &parameters) {
return ns3::CreateObject<T> (parameters);
2008-01-02 15:54:53 +01:00
}
};
CallbackBase cb = MakeCallback (&Maker::Create);
DoAddConstructor (cb, 0);
return *this;
}
template <typename T, typename T1>
2008-01-15 12:36:22 +01:00
TypeId
TypeId::AddConstructor (void)
2008-01-02 15:54:53 +01:00
{
struct Maker {
static Ptr<Object> Create (T1 a1) {
return ns3::CreateObject<T,T1> (a1);
2008-01-02 15:54:53 +01:00
}
};
CallbackBase cb = MakeCallback (&Maker::Create);
DoAddConstructor (cb, 1);
return *this;
}
template <typename T, typename T1, typename T2>
2008-01-15 12:36:22 +01:00
TypeId
TypeId::AddConstructor (void)
2008-01-02 15:54:53 +01:00
{
struct Maker {
static Ptr<Object> Create (T1 a1, T2 a2) {
return ns3::CreateObject<T,T1,T2> (a1, a2);
2008-01-02 15:54:53 +01:00
}
};
CallbackBase cb = MakeCallback (&Maker::Create);
DoAddConstructor (cb, 2);
return *this;
}
template <typename T1>
Ptr<Object>
TypeId::CreateObject (T1 a1) const
2008-01-02 15:54:53 +01:00
{
CallbackBase cb = LookupConstructor (1);
Callback<Ptr<Object>,T1> realCb;
realCb.Assign (cb);
Ptr<Object> object = realCb (a1);
return object;
}
template <typename T1, typename T2>
Ptr<Object>
TypeId::CreateObject (T1 a1, T2 a2) const
2008-01-02 15:54:53 +01:00
{
CallbackBase cb = LookupConstructor (2);
Callback<Ptr<Object>,T1,T2> realCb;
realCb.Assign (cb);
Ptr<Object> object = realCb (a1,a2);
return object;
}
/*************************************************************************
* The Object implementation which depends on templates
*************************************************************************/
2008-01-02 15:54:53 +01:00
2007-05-17 17:21:49 +02:00
void
2007-05-25 10:02:50 +02:00
Object::Ref (void) const
2007-05-17 17:21:49 +02:00
{
m_count++;
}
void
2007-05-25 10:02:50 +02:00
Object::Unref (void) const
2007-05-17 17:21:49 +02:00
{
NS_ASSERT (Check ());
m_count--;
if (m_count == 0)
{
MaybeDelete ();
}
}
template <typename T>
Ptr<T>
2008-01-31 22:11:03 +01:00
Object::GetObject () const
{
2008-01-31 22:11:03 +01:00
Ptr<Object> found = DoGetObject (T::GetTypeId ());
if (found != 0)
{
return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
}
return 0;
}
template <typename T>
Ptr<T>
2008-01-31 22:11:03 +01:00
Object::GetObject (TypeId tid) const
{
2008-01-31 22:11:03 +01:00
Ptr<Object> found = DoGetObject (tid);
if (found != 0)
{
return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
}
return 0;
}
/*************************************************************************
* The helper functions which need templates.
*************************************************************************/
template <typename T>
Ptr<T> CreateObject (const Parameters &parameters)
{
Ptr<T> p = Ptr<T> (new T (), false);
p->SetTypeId (T::GetTypeId ());
p->Object::Construct (parameters);
return p;
}
template <typename T>
Ptr<T> CreateObject (void)
{
Ptr<T> p = Ptr<T> (new T (), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
p->Object::Construct (Parameters ());
return p;
}
template <typename T, typename T1>
Ptr<T> CreateObject (T1 a1)
{
Ptr<T> p = Ptr<T> (new T (a1), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
p->Object::Construct (Parameters ());
return p;
}
template <typename T, typename T1, typename T2>
Ptr<T> CreateObject (T1 a1, T2 a2)
{
Ptr<T> p = Ptr<T> (new T (a1, a2), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
p->Object::Construct (Parameters ());
return p;
}
template <typename T, typename T1, typename T2, typename T3>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3)
{
Ptr<T> p = Ptr<T> (new T (a1, a2, a3), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
return p;
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4)
{
Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
return p;
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4, a5), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
return p;
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
{
Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4, a5, a6), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
return p;
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
{
Ptr<T> p = Ptr<T> (new T (a1, a2, a3, a4, a5, a6, a7), false);
2008-01-15 12:43:07 +01:00
p->SetTypeId (T::GetTypeId ());
return p;
}
template <typename T>
Ptr<T>
2008-02-20 19:57:31 +01:00
CreateObjectWith (std::string n1, Attribute v1,
std::string n2 = "", Attribute v2 = Attribute ())
{
Parameters parameters;
parameters.SetWithTid (T::GetTypeId (), n1, v1);
parameters.SetWithTid (T::GetTypeId (), n2, v2);
return CreateObject<T> (parameters);
}
} // namespace ns3
2007-05-25 10:02:50 +02:00
#endif /* OBJECT_H */