merge
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue, 09 Oct 2007 13:25:30 +0100
changeset 1766 1207df3ad6f2
parent 1765 763f8d1bb058 (current diff)
parent 1702 0fbe74581141 (diff)
child 1767 22e95c5a41c4
merge
--- a/samples/main-default-value.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/samples/main-default-value.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -62,7 +62,7 @@
   //utilize the loops variable to show that it can be read from the command line
   if(loops>0)
   {
-    cout<<"You requested "<<loops<<" iterations of a loop";
+    std::cerr<<"You requested "<<loops<<" iterations of a loop";
     for(uint32_t i=0;i<loops;++i)
       cout<<"iteration "<<i;
   }
--- a/src/common/packet-metadata.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/common/packet-metadata.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -43,6 +43,7 @@
     {
       PacketMetadata::Deallocate (*i);
     }
+  PacketMetadata::m_enable = false;
 }
 
 void 
@@ -643,6 +644,11 @@
 void
 PacketMetadata::Recycle (struct PacketMetadata::Data *data)
 {
+  if (!m_enable)
+    {
+      PacketMetadata::Deallocate (data);
+      return;
+    } 
   NS_LOG_LOGIC ("recycle size="<<data->m_size<<", list="<<m_freeList.size ());
   NS_ASSERT (data->m_count == 0);
   if (m_freeList.size () > 1000 ||
--- a/src/common/packet-metadata.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/common/packet-metadata.h	Tue Oct 09 13:25:30 2007 +0100
@@ -190,7 +190,9 @@
   public:
     ~DataFreeList ();
   };
-  
+
+  friend DataFreeList::~DataFreeList ();
+
   PacketMetadata ();
   void DoAddHeader (uint32_t uid, uint32_t size);
   void DoRemoveHeader (uint32_t uid, uint32_t size);
--- a/src/core/command-line.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/core/command-line.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -20,6 +20,7 @@
  */
 
 #include "command-line.h"
+#include "ns3/debug.h"
 #include <unistd.h>
 
 namespace ns3 {
@@ -109,8 +110,15 @@
       std::string name, value;
       if (cur == std::string::npos)
         {
+          if (argc == 1)
+            {
+              // invalid argument. ignore it.
+              continue;
+            }
+          argv++;
+          argc--;
           name = param;
-          value = "";
+          value = *argv;
         }
       else
         {
@@ -124,7 +132,12 @@
           DefaultValueBase *item = *i;
           if (item->GetName () == name)
             {
-              item->ParseValue (value);
+              if (!item->ParseValue (value))
+                {
+                  std::cerr << "Warning: failed to parse command line argument `"
+                            << name << "' of type '" << item->GetType ()
+                            << "' with value `" << value << "'." << std::endl;
+                }
               continue;
             }
         }
@@ -144,3 +157,83 @@
 }
 
 }//namespace ns3
+
+
+
+#ifdef RUN_SELF_TESTS
+#include "test.h"
+#include <iostream>
+#include <sstream>
+
+namespace ns3 {
+
+
+class CommandLineTest : public Test
+{
+public:
+  CommandLineTest () : Test ("CommandLine") {}
+  virtual bool RunTests (void)
+  {
+    bool result = true;
+
+    // redirect stderr temporarily (else warnings appear during unit testing, which is not nice)
+    std::ostringstream nullout;
+    std::streambuf *origcerr = std::cerr.rdbuf (nullout.rdbuf ());
+    {
+      char *argv[] = {"run-tests", "--loops", "bad-value", NULL};
+      int argc = sizeof (argv) / sizeof (argv[0]) - 1;
+      
+      uint32_t loops = 123;
+      CommandLine::AddArgValue ("loops","a test of the command line", loops);
+      CommandLine::Parse (argc, argv);
+      
+      NS_TEST_ASSERT_EQUAL (loops, 123);
+    }
+
+    {
+      char *argv[] = {"run-tests", "--loops=bad-value", NULL};
+      int argc = sizeof (argv) / sizeof (argv[0]) - 1;
+      
+      uint32_t loops = 123;
+      CommandLine::AddArgValue ("loops","a test of the command line", loops);
+      CommandLine::Parse (argc, argv);
+      
+      NS_TEST_ASSERT_EQUAL (loops, 123);
+    }
+
+    {
+      char *argv[] = {"run-tests", "--loops", "456", NULL};
+      int argc = sizeof (argv) / sizeof (argv[0]) - 1;
+      
+      uint32_t loops = 123;
+      CommandLine::AddArgValue ("loops","a test of the command line", loops);
+      CommandLine::Parse (argc, argv);
+      
+      NS_TEST_ASSERT_EQUAL (loops, 456);
+    }
+
+    {
+      char *argv[] = {"run-tests", "--loops=456", NULL};
+      int argc = sizeof (argv) / sizeof (argv[0]) - 1;
+      
+      uint32_t loops = 123;
+      CommandLine::AddArgValue ("loops","a test of the command line", loops);
+      CommandLine::Parse (argc, argv);
+      
+      NS_TEST_ASSERT_EQUAL (loops, 456);
+    }
+
+    // unredirect cerr
+    std::cerr.rdbuf (origcerr);
+
+
+    return result;
+  }
+};
+
+
+static CommandLineTest g_commandLineTests;
+
+}//namespace ns3
+
+#endif /* RUN_SELF_TESTS */
--- a/src/core/command-line.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/core/command-line.h	Tue Oct 09 13:25:30 2007 +0100
@@ -123,14 +123,18 @@
   iss.str (value);
   T v;
   iss >> v;
-  *m_valuePtr = v;
-  return !iss.bad () && !iss.fail ();
+  bool ok = (!iss.bad () && !iss.fail ());
+  if (ok)
+    {
+      *m_valuePtr = v;
+    }
+  return ok;
 }
 template <typename T>
 std::string
 CommandLine::UserDefaultValue<T>::DoGetType (void) const
 {
-  return "";
+  return TypeNameGet<T> ();
 }
 template <typename T>
 std::string
--- a/src/core/default-value.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/core/default-value.h	Tue Oct 09 13:25:30 2007 +0100
@@ -97,6 +97,21 @@
   static Iterator End (void);
   static void Remove (const std::string &name);
   static void Add (DefaultValueBase *defaultValue);
+
+  template <typename T>
+  static const T* Get (const std::string &name)
+  {
+    for (Iterator iter = Begin (); iter != End (); iter++)
+      {
+        const DefaultValueBase *value = *iter;
+        if (value->GetName () == name)
+          {
+            return dynamic_cast<const T*> (value);
+          }
+      }
+    return NULL;
+  }
+
  private:
   typedef std::list<DefaultValueBase *> List;
   static List *GetList (void);
--- a/src/core/ptr.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/core/ptr.h	Tue Oct 09 13:25:30 2007 +0100
@@ -352,6 +352,11 @@
   return PeekPointer (lhs) != PeekPointer (rhs);
 }
 
+template <typename T>
+bool operator < (const Ptr<T> &lhs, const Ptr<T> &rhs)
+{
+  return PeekPointer<T> (lhs) < PeekPointer<T> (rhs);
+}
 
 template <typename T1, typename T2>
 Ptr<T1>
--- a/src/simulator/event-id.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/event-id.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/event-id.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/event-id.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/event-impl.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/event-impl.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/event-impl.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/event-impl.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005,2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/high-precision-128.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/high-precision-128.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/high-precision-128.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/high-precision-128.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/high-precision-double.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/high-precision-double.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/high-precision-double.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/high-precision-double.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/high-precision.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/high-precision.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/high-precision.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/high-precision.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/nstime.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/nstime.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005,2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler-factory.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-factory.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler-factory.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-factory.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler-heap.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-heap.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -2,7 +2,6 @@
 /*
  * Copyright (c) 2006 INRIA
  * Copyright (c) 2005 Mathieu Lacage
- * All rights reserved.
  *
  * 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
@@ -20,7 +19,7 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  *
  * This code started as a c++ translation of a java-based code written in 2005
- * to implement a heap sort. Which explains the Copyright Mathieu Lacage at the
+ * to implement a heap sort. Which explains the "Copyright Mathieu Lacage" at the
  * top of this file.
  *
  * What is smart about this code ?
--- a/src/simulator/scheduler-heap.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-heap.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler-list.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-list.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler-list.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-list.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler-map.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-map.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler-map.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler-map.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/scheduler.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/scheduler.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/simulation-singleton.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/simulation-singleton.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2007 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/simulator.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/simulator.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005,2006 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/simulator.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/simulator.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2005 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/time-default-value.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/time-default-value.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2007 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/time-default-value.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/time-default-value.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,7 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * Copyright (c) 2007 INRIA
- * All rights reserved.
  *
  * 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
--- a/src/simulator/time.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/time.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -2,7 +2,6 @@
 /*
  * Copyright (c) 2005,2006 INRIA
  * Copyright (c) 2007 Emmanuelle Laprise
- * All rights reserved.
  *
  * 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
--- a/src/simulator/timer.cc	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/timer.cc	Tue Oct 09 13:25:30 2007 +0100
@@ -1,3 +1,22 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2007 INRIA
+ *
+ * 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
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
 #include "timer.h"
 #include "simulator.h"
 #include "simulation-singleton.h"
--- a/src/simulator/timer.h	Mon Oct 08 11:37:03 2007 +0100
+++ b/src/simulator/timer.h	Tue Oct 09 13:25:30 2007 +0100
@@ -1,3 +1,22 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2007 INRIA
+ *
+ * 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
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
 #ifndef TIMER_H
 #define TIMER_H