destroy prototype stack upon Simulator::Destroy

Mathieu Lacage 2007-05-02 10:41:34 +02:00
parent 6d4e502109
commit 9bb706c627
2 changed files with 29 additions and 11 deletions

View File

@ -29,8 +29,6 @@
namespace ns3{
Node::SmartNodeVec_t Node::g_prototypes; // The node prototypes stack
Node::Node()
: m_id(0), m_sid(0)
{
@ -113,6 +111,18 @@ Node::GetNodeVector (void)
return &vector;
}
Node::SmartNodeVec_t **
Node::GetPrototypeVector (void)
{
static SmartNodeVec_t *vector = 0;
if (vector == 0)
{
vector = new SmartNodeVec_t ();
Simulator::ScheduleDestroy (&Node::DestroyPrototypes);
}
return &vector;
}
void
Node::DestroyNodes (void)
{
@ -120,11 +130,18 @@ Node::DestroyNodes (void)
delete *vector;
*vector = 0;
}
void
Node::DestroyPrototypes (void)
{
SmartNodeVec_t **vector = GetPrototypeVector ();
delete *vector;
*vector = 0;
}
// Node stack creation and management routines.
Node* Node::Create()
{
Node* n = g_prototypes.Back()->Copy(); // Copy the top of the stack
Node* n = (*GetPrototypeVector ())->Back()->Copy(); // Copy the top of the stack
(*GetNodeVector ())->Add (n);
NodeList::Add (n); // Add to global list of nodes
return n;
@ -140,30 +157,30 @@ Node* Node::Create(uint32_t sid)
Node* Node::GetNodePrototype()
{ // Get node* to top of prototypes stack
return g_prototypes.Back();
return (*GetPrototypeVector ())->Back();
}
Node* Node::PushNodePrototype(const Node& n)
{ // Add a new node to the top of the prototypes stack
g_prototypes.Add(n.Copy());
return g_prototypes.Back();
(*GetPrototypeVector ())->Add(n.Copy());
return (*GetPrototypeVector ())->Back();
}
Node* Node::PushNodePrototype()
{ // Replicate the top of the prototype stack
g_prototypes.Add(GetNodePrototype()->Copy());
return g_prototypes.Back();
(*GetPrototypeVector ())->Add(GetNodePrototype()->Copy());
return (*GetPrototypeVector ())->Back();
}
void Node::PopNodePrototype()
{
if (!g_prototypes.Empty()) g_prototypes.Remove();
if (!(*GetPrototypeVector ())->Empty()) (*GetPrototypeVector ())->Remove();
}
void Node::ClearAll()
{ // Delete all nodes for memory leak checking, including prototypes
(*GetNodeVector ())->Clear ();
g_prototypes.Clear();
(*GetPrototypeVector ())->Clear();
}
L3Demux*

View File

@ -165,10 +165,11 @@ public:
// Global static variables
private:
static uint32_t g_nextId; // Next available ID
static SmartNodeVec_t g_prototypes; // Node prototype stack
static Node::SmartNodeVec_t **GetNodeVector (void);
static Node::SmartNodeVec_t **GetPrototypeVector (void);
static void DestroyNodes (void);
static void DestroyPrototypes (void);
protected:
void SetId(uint32_t); // NodeList::Add() calls this