utils/bench-object.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 02 Jan 2008 09:09:24 +0100
changeset 2230 9f13ac3291e0
parent 732 df256f32b6ae
permissions -rw-r--r--
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.

#include <vector>
#include <stdlib.h>
#include "ns3/object.h"

using namespace ns3;

class BaseA : public ns3::Object
{
public:
  static const ns3::InterfaceId iid;
  BaseA ()
  {
    SetInterfaceId (BaseA::iid);
  }
  virtual void Dispose (void) {}
};

const ns3::InterfaceId BaseA::iid = 
ns3::MakeInterfaceId ("BaseABench", Object::iid);



int main (int argc, char *argv[])
{
  int nobjects = atoi (argv[1]);
  int nswaps = atoi (argv[2]);

  std::vector< Ptr<BaseA> > objlist;

  for (int i = 0; i < nobjects; ++i)
    objlist.push_back (CreateObject<BaseA> ());

  for (int swapCounter = nswaps; swapCounter; --swapCounter)
    {
      int x1 = swapCounter % nobjects;
      int x2 = (swapCounter+1) % nobjects;
      Ptr<BaseA> obj1 = objlist[x1];
      Ptr<BaseA> obj2 = objlist[x2];
      objlist[x2] = obj1;
      objlist[x1] = obj2;
    }
}