diff --git a/samples/main-default-value.cc b/samples/main-default-value.cc index dcaa8a83a..35ccb5547 100644 --- a/samples/main-default-value.cc +++ b/samples/main-default-value.cc @@ -62,7 +62,7 @@ int main (int argc, char* argv[]) //utilize the loops variable to show that it can be read from the command line if(loops>0) { - cout<<"You requested "< namespace ns3 { @@ -109,8 +110,15 @@ CommandLine::Parse (int argc, char *argv[]) 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 @@ CommandLine::Parse (int argc, char *argv[]) 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 @@ CommandLine::Parse (int argc, char *argv[]) } }//namespace ns3 + + + +#ifdef RUN_SELF_TESTS +#include "test.h" +#include +#include + +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 */ diff --git a/src/core/command-line.h b/src/core/command-line.h index 36e5382c9..8a1c49daa 100644 --- a/src/core/command-line.h +++ b/src/core/command-line.h @@ -123,14 +123,18 @@ CommandLine::UserDefaultValue::DoParseValue (const std::string &value) 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 std::string CommandLine::UserDefaultValue::DoGetType (void) const { - return ""; + return TypeNameGet (); } template std::string diff --git a/src/core/default-value.h b/src/core/default-value.h index b43f013be..8d252ab45 100644 --- a/src/core/default-value.h +++ b/src/core/default-value.h @@ -97,6 +97,21 @@ class DefaultValueList static Iterator End (void); static void Remove (const std::string &name); static void Add (DefaultValueBase *defaultValue); + + template + 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 (value); + } + } + return NULL; + } + private: typedef std::list List; static List *GetList (void); diff --git a/src/core/ptr.h b/src/core/ptr.h index f2436dd63..62f536f34 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -352,6 +352,11 @@ operator != (Ptr const &lhs, Ptr const &rhs) return PeekPointer (lhs) != PeekPointer (rhs); } +template +bool operator < (const Ptr &lhs, const Ptr &rhs) +{ + return PeekPointer (lhs) < PeekPointer (rhs); +} template Ptr diff --git a/src/simulator/event-id.cc b/src/simulator/event-id.cc index ca3766503..78d476f94 100644 --- a/src/simulator/event-id.cc +++ b/src/simulator/event-id.cc @@ -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 diff --git a/src/simulator/event-id.h b/src/simulator/event-id.h index efa74d930..653f20bfe 100644 --- a/src/simulator/event-id.h +++ b/src/simulator/event-id.h @@ -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 diff --git a/src/simulator/event-impl.cc b/src/simulator/event-impl.cc index 9c89bb52f..9f9c39346 100644 --- a/src/simulator/event-impl.cc +++ b/src/simulator/event-impl.cc @@ -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 diff --git a/src/simulator/event-impl.h b/src/simulator/event-impl.h index 51ac1e7a1..9fb967577 100644 --- a/src/simulator/event-impl.h +++ b/src/simulator/event-impl.h @@ -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 diff --git a/src/simulator/high-precision-128.cc b/src/simulator/high-precision-128.cc index 282750548..8c1bfecfb 100644 --- a/src/simulator/high-precision-128.cc +++ b/src/simulator/high-precision-128.cc @@ -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 diff --git a/src/simulator/high-precision-128.h b/src/simulator/high-precision-128.h index 775f59ea0..61ef029b9 100644 --- a/src/simulator/high-precision-128.h +++ b/src/simulator/high-precision-128.h @@ -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 diff --git a/src/simulator/high-precision-double.cc b/src/simulator/high-precision-double.cc index c4639c1eb..5d1b7bbc6 100644 --- a/src/simulator/high-precision-double.cc +++ b/src/simulator/high-precision-double.cc @@ -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 diff --git a/src/simulator/high-precision-double.h b/src/simulator/high-precision-double.h index 16f3d05d0..c25196f80 100644 --- a/src/simulator/high-precision-double.h +++ b/src/simulator/high-precision-double.h @@ -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 diff --git a/src/simulator/high-precision.cc b/src/simulator/high-precision.cc index 0313be6b2..6f98a1949 100644 --- a/src/simulator/high-precision.cc +++ b/src/simulator/high-precision.cc @@ -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 diff --git a/src/simulator/high-precision.h b/src/simulator/high-precision.h index 8f5426c62..61e414dd5 100644 --- a/src/simulator/high-precision.h +++ b/src/simulator/high-precision.h @@ -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 diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index 2958f2f3e..6b6660f70 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -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 diff --git a/src/simulator/scheduler-factory.cc b/src/simulator/scheduler-factory.cc index 760b2ea8b..da0d1b559 100644 --- a/src/simulator/scheduler-factory.cc +++ b/src/simulator/scheduler-factory.cc @@ -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 diff --git a/src/simulator/scheduler-factory.h b/src/simulator/scheduler-factory.h index 6883a6fd8..566307ac3 100644 --- a/src/simulator/scheduler-factory.h +++ b/src/simulator/scheduler-factory.h @@ -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 diff --git a/src/simulator/scheduler-heap.cc b/src/simulator/scheduler-heap.cc index f924c70f4..3a9bf541d 100644 --- a/src/simulator/scheduler-heap.cc +++ b/src/simulator/scheduler-heap.cc @@ -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 * * 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 ? diff --git a/src/simulator/scheduler-heap.h b/src/simulator/scheduler-heap.h index fbc6e1ca1..3b2f74f32 100644 --- a/src/simulator/scheduler-heap.h +++ b/src/simulator/scheduler-heap.h @@ -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 diff --git a/src/simulator/scheduler-list.cc b/src/simulator/scheduler-list.cc index c3de7891a..8fa57f473 100644 --- a/src/simulator/scheduler-list.cc +++ b/src/simulator/scheduler-list.cc @@ -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 diff --git a/src/simulator/scheduler-list.h b/src/simulator/scheduler-list.h index 306d19270..86dfc991f 100644 --- a/src/simulator/scheduler-list.h +++ b/src/simulator/scheduler-list.h @@ -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 diff --git a/src/simulator/scheduler-map.cc b/src/simulator/scheduler-map.cc index e73abf4cf..5e20ff8d6 100644 --- a/src/simulator/scheduler-map.cc +++ b/src/simulator/scheduler-map.cc @@ -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 diff --git a/src/simulator/scheduler-map.h b/src/simulator/scheduler-map.h index dbbc7fdbd..56e3587d0 100644 --- a/src/simulator/scheduler-map.h +++ b/src/simulator/scheduler-map.h @@ -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 diff --git a/src/simulator/scheduler.cc b/src/simulator/scheduler.cc index 4ba1d01b6..03d262e19 100644 --- a/src/simulator/scheduler.cc +++ b/src/simulator/scheduler.cc @@ -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 diff --git a/src/simulator/scheduler.h b/src/simulator/scheduler.h index d8dea8672..bb8a7fc23 100644 --- a/src/simulator/scheduler.h +++ b/src/simulator/scheduler.h @@ -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 diff --git a/src/simulator/simulation-singleton.h b/src/simulator/simulation-singleton.h index b7d65f899..8aa69a66f 100644 --- a/src/simulator/simulation-singleton.h +++ b/src/simulator/simulation-singleton.h @@ -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 diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index 5e6d3bad4..0277cf7f2 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -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 diff --git a/src/simulator/simulator.h b/src/simulator/simulator.h index 0d48b2990..4f55a7687 100644 --- a/src/simulator/simulator.h +++ b/src/simulator/simulator.h @@ -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 diff --git a/src/simulator/time-default-value.cc b/src/simulator/time-default-value.cc index 46449f4c2..2d2e4a6a6 100644 --- a/src/simulator/time-default-value.cc +++ b/src/simulator/time-default-value.cc @@ -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 diff --git a/src/simulator/time-default-value.h b/src/simulator/time-default-value.h index 87d0c7fcb..0fb64cae1 100644 --- a/src/simulator/time-default-value.h +++ b/src/simulator/time-default-value.h @@ -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 diff --git a/src/simulator/time.cc b/src/simulator/time.cc index 8c0e43e35..a58a54925 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -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 diff --git a/src/simulator/timer.cc b/src/simulator/timer.cc index d3c09a0c8..2642698cb 100644 --- a/src/simulator/timer.cc +++ b/src/simulator/timer.cc @@ -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 + */ #include "timer.h" #include "simulator.h" #include "simulation-singleton.h" diff --git a/src/simulator/timer.h b/src/simulator/timer.h index 5087db294..969ea8ad3 100644 --- a/src/simulator/timer.h +++ b/src/simulator/timer.h @@ -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 + */ #ifndef TIMER_H #define TIMER_H