src/node/node-list.cc
changeset 345 47b41507a45a
child 359 91b7ad7fa784
equal deleted inserted replaced
344:b547ec7dbbc1 345:47b41507a45a
       
     1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2007 INRIA
       
     4  * All rights reserved.
       
     5  *
       
     6  * This program is free software; you can redistribute it and/or modify
       
     7  * it under the terms of the GNU General Public License version 2 as
       
     8  * published by the Free Software Foundation;
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    18  *
       
    19  * Authors: 
       
    20  *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
       
    21  */
       
    22 
       
    23 #include "ns3/array-trace-resolver.h"
       
    24 #include "ns3/trace-root.h"
       
    25 #include "node-list.h"
       
    26 #include "node.h"
       
    27 
       
    28 namespace ns3 {
       
    29 
       
    30 void 
       
    31 NodeList::Add (Node *node)
       
    32 {
       
    33   GetNodes ()->push_back (node);
       
    34 }
       
    35 NodeList::Iterator 
       
    36 NodeList::Begin (void)
       
    37 {
       
    38   return GetNodes ()->begin ();
       
    39 }
       
    40 NodeList::Iterator 
       
    41 NodeList::End (void)
       
    42 {
       
    43   return GetNodes ()->end ();
       
    44 }
       
    45 
       
    46 std::vector<Node *> *
       
    47 NodeList::GetNodes (void)
       
    48 {
       
    49   static bool firstTime = true;
       
    50   if (firstTime)
       
    51     {
       
    52       TraceRoot::Register ("nodes", MakeCallback (&NodeList::CreateTraceResolver));
       
    53     }
       
    54   static std::vector<Node *> nodes;
       
    55   return &nodes;
       
    56 }
       
    57 uint32_t 
       
    58 NodeList::GetNNodes (void)
       
    59 {
       
    60   return GetNodes ()->size ();
       
    61 }
       
    62 Node *
       
    63 NodeList::GetNode (uint32_t n)
       
    64 {
       
    65   return (*GetNodes ())[n];
       
    66 }
       
    67 
       
    68 TraceResolver *
       
    69 NodeList::CreateTraceResolver (TraceContext const &context)
       
    70 {
       
    71   ArrayTraceResolver<Node> *resolver =
       
    72     new ArrayTraceResolver<Node>
       
    73     (context, 
       
    74      MakeCallback (&NodeList::GetNNodes),
       
    75      MakeCallback (&NodeList::GetNode));
       
    76   return resolver;
       
    77 }
       
    78 
       
    79 }//namespace ns3