--- a/examples/csma-broadcast.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/csma-broadcast.cc Mon Mar 10 00:27:53 2008 +0100
@@ -33,7 +33,6 @@
#include <cassert>
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/csma-multicast.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/csma-multicast.cc Mon Mar 10 00:27:53 2008 +0100
@@ -30,7 +30,6 @@
// - Node n4 listens for the data (actual listener not yet implementted)
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/csma-one-subnet.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/csma-one-subnet.cc Mon Mar 10 00:27:53 2008 +0100
@@ -26,7 +26,6 @@
// - Tracing of queues and packet receptions to file "csma-one-subnet.tr"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/csma-packet-socket.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/csma-packet-socket.cc Mon Mar 10 00:27:53 2008 +0100
@@ -34,7 +34,6 @@
#include <cassert>
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/mixed-global-routing.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/mixed-global-routing.cc Mon Mar 10 00:27:53 2008 +0100
@@ -39,7 +39,6 @@
#include "ns3/log.h"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
--- a/examples/simple-alternate-routing.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/simple-alternate-routing.cc Mon Mar 10 00:27:53 2008 +0100
@@ -40,7 +40,6 @@
#include "ns3/log.h"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
--- a/examples/simple-error-model.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/simple-error-model.cc Mon Mar 10 00:27:53 2008 +0100
@@ -41,7 +41,6 @@
#include "ns3/log.h"
#include "ns3/assert.h"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/config.h"
#include "ns3/uinteger.h"
@@ -54,7 +53,6 @@
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/internet-node.h"
-#include "ns3/default-value.h"
#include "ns3/random-variable.h"
#include "ns3/point-to-point-channel.h"
#include "ns3/point-to-point-net-device.h"
--- a/examples/simple-global-routing.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/simple-global-routing.cc Mon Mar 10 00:27:53 2008 +0100
@@ -45,7 +45,6 @@
#include "ns3/log.h"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
--- a/examples/simple-point-to-point-olsr.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/simple-point-to-point-olsr.cc Mon Mar 10 00:27:53 2008 +0100
@@ -40,7 +40,6 @@
#include "ns3/log.h"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
--- a/examples/simple-point-to-point.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/simple-point-to-point.cc Mon Mar 10 00:27:53 2008 +0100
@@ -40,7 +40,6 @@
#include "ns3/log.h"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
--- a/examples/tcp-large-transfer-errors.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/tcp-large-transfer-errors.cc Mon Mar 10 00:27:53 2008 +0100
@@ -35,7 +35,6 @@
#include <cassert>
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/tcp-large-transfer.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/tcp-large-transfer.cc Mon Mar 10 00:27:53 2008 +0100
@@ -35,7 +35,6 @@
#include <cassert>
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/tcp-nonlistening-server.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/tcp-nonlistening-server.cc Mon Mar 10 00:27:53 2008 +0100
@@ -34,7 +34,6 @@
#include <cassert>
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/tcp-small-transfer-oneloss.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/tcp-small-transfer-oneloss.cc Mon Mar 10 00:27:53 2008 +0100
@@ -35,7 +35,6 @@
#include <cassert>
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/tcp-small-transfer.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/tcp-small-transfer.cc Mon Mar 10 00:27:53 2008 +0100
@@ -35,7 +35,6 @@
#include <cassert>
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/log.h"
--- a/examples/udp-echo.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/examples/udp-echo.cc Mon Mar 10 00:27:53 2008 +0100
@@ -26,7 +26,6 @@
// - Tracing of queues and packet receptions to file "udp-echo.tr"
#include "ns3/command-line.h"
-#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
--- a/samples/main-propagation-loss.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/samples/main-propagation-loss.cc Mon Mar 10 00:27:53 2008 +0100
@@ -18,8 +18,9 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "ns3/propagation-loss-model.h"
-#include "ns3/default-value.h"
#include "ns3/static-mobility-model.h"
+#include "ns3/config.h"
+#include "ns3/string.h"
using namespace ns3;
@@ -50,19 +51,8 @@
int main (int argc, char *argv[])
{
-#if 0
- DefaultValue::Bind ("PropagationLossModelType", "Friis");
- DefaultValue::Bind ("FriisPropagationLossLambda", "0.6");
- DefaultValue::Bind ("FriisPropagationLossSystemLoss", "1.0");
-
- PrintOne (-10, 20, 5, 0, 1000, 5);
-#endif
-
- DefaultValue::Bind ("PropagationLossModelType", "LogDistance");
- DefaultValue::Bind ("LogDistancePropagationLossReferenceDistance", "1.0");
- DefaultValue::Bind ("LogDistancePropagationLossReferenceType", "Random");
- DefaultValue::Bind ("RandomPropagationLossDistribution", "Constant:10");
- DefaultValue::Bind ("LogDistancePropagationLossExponent", "4");
+ Config::SetGlobal ("LogDistancePropagationLossModel::ReferenceDistance", String ("1.0"));
+ Config::SetGlobal ("LogDistancePropagationLossModel::Exponent", String ("4"));
PrintOne (-10, 20, 5, 0, 10000, 2);
--- a/samples/main-random-walk.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/samples/main-random-walk.cc Mon Mar 10 00:27:53 2008 +0100
@@ -5,7 +5,6 @@
#include "ns3/ptr.h"
#include "ns3/mobility-model.h"
#include "ns3/position-allocator.h"
-#include "ns3/default-value.h"
#include "ns3/command-line.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
--- a/src/core/default-value.cc Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,510 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 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 "default-value.h"
-#include "fatal-error.h"
-
-namespace ns3 {
-
-namespace DefaultValue {
-
-enum BindStatus {
- OK,
- INVALID_VALUE,
- NOT_FOUND
-};
-
-
-static
-enum BindStatus
-BindSafe (std::string name, std::string value)
-{
- for (DefaultValueList::Iterator i = DefaultValueList::Begin ();
- i != DefaultValueList::End (); i++)
- {
- DefaultValueBase *cur = *i;
- if (cur->GetName () == name)
- {
- if (!cur->ParseValue (value))
- {
- return INVALID_VALUE;
- }
- return OK;
- }
- }
- return NOT_FOUND;
-}
-
-void
-Bind (std::string name, std::string value)
-{
- switch (BindSafe (name, value)) {
- case INVALID_VALUE:
- NS_FATAL_ERROR ("Invalid value: "<<name<<"="<<value);
- break;
- case NOT_FOUND:
- NS_FATAL_ERROR ("No registered DefaultValue=\"" << name << "\"");
- break;
- case OK:
- break;
- }
-}
-
-}
-
-DefaultValueBase::DefaultValueBase (const std::string &name,
- const std::string &help)
- : m_name (name),
- m_help (help),
- m_dirty (false)
-{}
-DefaultValueBase::~DefaultValueBase ()
-{}
-std::string
-DefaultValueBase::GetName (void) const
-{
- return m_name;
-}
-std::string
-DefaultValueBase::GetHelp (void) const
-{
- return m_help;
-}
-bool
-DefaultValueBase::IsDirty (void) const
-{
- return m_dirty;
-}
-void
-DefaultValueBase::ClearDirtyFlag (void)
-{
- m_dirty = false;
-}
-bool
-DefaultValueBase::ParseValue (const std::string &value)
-{
- bool ok = DoParseValue (value);
- if (ok)
- {
- m_dirty = true;
- }
- return ok;
-}
-std::string
-DefaultValueBase::GetType (void) const
-{
- return DoGetType ();
-}
-std::string
-DefaultValueBase::GetDefaultValue (void) const
-{
- return DoGetDefaultValue ();
-}
-
-
-DefaultValueList::Iterator
-DefaultValueList::Begin (void)
-{
- return GetList ()->begin ();
-}
-DefaultValueList::Iterator
-DefaultValueList::End (void)
-{
- return GetList ()->end ();
-}
-void
-DefaultValueList::Remove (const std::string &name)
-{
- DefaultValueList::List *list = GetList ();
- for (List::iterator i = list->begin (); i != list->end (); /* nothing */)
- {
- if ((*i)->GetName () == name)
- {
- i = list->erase (i);
- }
- else
- {
- i++;
- }
- }
-}
-void
-DefaultValueList::Add (DefaultValueBase *defaultValue)
-{
- GetList ()->push_back (defaultValue);
-}
-
-DefaultValueList::List *
-DefaultValueList::GetList (void)
-{
- static List list;
- return &list;
-}
-
-BooleanDefaultValue::BooleanDefaultValue (std::string name,
- std::string help,
- bool defaultValue)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_value (defaultValue)
-{
- DefaultValueList::Add (this);
-}
-bool
-BooleanDefaultValue::GetValue (void) const
-{
- return m_value;
-}
-bool
-BooleanDefaultValue::DoParseValue (const std::string &value)
-{
- if (value.compare ("0") == 0 ||
- value.compare ("f") == 0 ||
- value.compare ("false") == 0 ||
- value.compare ("FALSE") == 0)
- {
- m_value = false;
- return true;
- }
- else if (value.compare ("1") == 0 ||
- value.compare ("t") == 0 ||
- value.compare ("true") == 0 ||
- value.compare ("TRUE") == 0)
- {
- m_value = true;
- return true;
- }
- else
- {
- return false;
- }
-}
-std::string
-BooleanDefaultValue::DoGetType (void) const
-{
- return "bool";
-}
-std::string
-BooleanDefaultValue::DoGetDefaultValue (void) const
-{
- return m_defaultValue?"true":"false";
-}
-
-
-StringEnumDefaultValue::StringEnumDefaultValue (const std::string &name,
- const std::string &help)
- : DefaultValueBase (name, help),
- m_oneDefault (false)
-{
- DefaultValueList::Add (this);
-}
-void
-StringEnumDefaultValue::AddDefaultValue (const std::string &value)
-{
- if (m_oneDefault)
- {
- NS_FATAL_ERROR ("More than one default value registered: " << value);
- }
- m_oneDefault = true;
- for (std::list<std::string>::iterator i = m_possibleValues.begin ();
- i != m_possibleValues.end (); i++)
- {
- if (value == *i)
- {
- NS_FATAL_ERROR ("Value already exists: " << value);
- }
- }
- m_possibleValues.push_back (value);
- m_value = value;
- m_defaultValue = value;
-}
-void
-StringEnumDefaultValue::AddPossibleValue (const std::string &value)
-{
- for (std::list<std::string>::iterator i = m_possibleValues.begin ();
- i != m_possibleValues.end (); i++)
- {
- if (value == *i)
- {
- NS_FATAL_ERROR ("Value already exists: " << value);
- }
- }
- m_possibleValues.push_back (value);
-}
-std::string
-StringEnumDefaultValue::GetValue (void) const
-{
- return m_value;
-}
-bool
-StringEnumDefaultValue::DoParseValue (const std::string &value)
-{
- for (std::list<std::string>::iterator i = m_possibleValues.begin ();
- i != m_possibleValues.end (); i++)
- {
- if (value == *i)
- {
- m_value = value;
- return true;
- }
- }
- return false;
-}
-std::string
-StringEnumDefaultValue::DoGetType (void) const
-{
- std::string retval;
- retval += "(";
- for (std::list<std::string>::const_iterator i = m_possibleValues.begin ();
- i != m_possibleValues.end (); i++)
- {
- if (i != m_possibleValues.begin ())
- {
- retval += "|";
- }
- retval += *i;
- }
- retval += ")";
- return retval;
-}
-std::string
-StringEnumDefaultValue::DoGetDefaultValue (void) const
-{
- return m_defaultValue;
-}
-
-
-CommandDefaultValue::CommandDefaultValue (const std::string &name,
- const std::string &help,
- Callback<void> cb)
- : DefaultValueBase (name, help),
- m_cb (cb)
-{
- DefaultValueList::Add (this);
-}
-bool
-CommandDefaultValue::DoParseValue (const std::string &value)
-{
- m_cb ();
- return true;
-}
-std::string
-CommandDefaultValue::DoGetType (void) const
-{
- return "";
-}
-std::string
-CommandDefaultValue::DoGetDefaultValue (void) const
-{
- return "";
-}
-
-
-StringDefaultValue::StringDefaultValue (const std::string &name,
- const std::string &help,
- const std::string defaultValue)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_value (defaultValue),
- m_minSize (0),
- m_maxSize (-1)
-{
- DefaultValueList::Add (this);
-}
-StringDefaultValue::StringDefaultValue (const std::string &name,
- const std::string &help,
- const std::string defaultValue,
- int maxSize)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_value (defaultValue),
- m_minSize (0),
- m_maxSize (maxSize)
-{
- DefaultValueList::Add (this);
-}
-StringDefaultValue::StringDefaultValue (const std::string &name,
- const std::string &help,
- const std::string defaultValue,
- int minSize,
- int maxSize)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_value (defaultValue),
- m_minSize (minSize),
- m_maxSize (maxSize)
-{
- DefaultValueList::Add (this);
-}
-
-
-std::string
-StringDefaultValue::GetValue (void) const
-{
- return m_value;
-}
-
-bool
-StringDefaultValue::DoParseValue (const std::string &value)
-{
- if ((int)value.size () < m_minSize)
- {
- return false;
- }
- if (m_maxSize != -1 && (int)value.size () > m_maxSize)
- {
- return false;
- }
- m_value = value;
- return true;
-}
-std::string
-StringDefaultValue::DoGetType (void) const
-{
- if (m_maxSize == -1)
- {
- return "string:0";
- }
- else
- {
- std::ostringstream oss;
- oss << "string:0:" << m_maxSize;
- return oss.str ();
- }
-}
-std::string
-StringDefaultValue::DoGetDefaultValue (void) const
-{
- return m_defaultValue;
-}
-
-
-
-}//namespace ns3
-
-#ifdef RUN_SELF_TESTS
-#include "test.h"
-
-namespace ns3 {
-
-enum MyEnum {
- MY_ENUM_A,
- MY_ENUM_B,
- MY_ENUM_C,
- MY_ENUM_D,
-};
-
-
-class DefaultValueTest : public Test
-{
-public:
- DefaultValueTest ();
- virtual bool RunTests (void);
-};
-
-DefaultValueTest::DefaultValueTest ()
- : Test ("DefaultValue")
-{}
-bool
-DefaultValueTest::RunTests (void)
-{
- bool result = true;
-
- BooleanDefaultValue a ("bool-a", "help a", true);
- NS_TEST_ASSERT (a.GetValue ());
- DefaultValue::Bind ("bool-a", "false");
- NS_TEST_ASSERT (!a.GetValue ());
- BooleanDefaultValue b ("bool-b", "help b", false);
- DefaultValue::Bind ("bool-b", "true");
- NS_TEST_ASSERT (b.GetValue ());
- DefaultValue::Bind ("bool-b", "0");
- NS_TEST_ASSERT (!b.GetValue ());
- DefaultValue::Bind ("bool-b", "1");
- NS_TEST_ASSERT (b.GetValue ());
- DefaultValue::Bind ("bool-b", "f");
- NS_TEST_ASSERT (!b.GetValue ());
- DefaultValue::Bind ("bool-b", "t");
- NS_TEST_ASSERT (b.GetValue ());
-
- DefaultValue::Bind ("bool-b", "false");
- NS_TEST_ASSERT (!b.GetValue ());
- NS_TEST_ASSERT_EQUAL (DefaultValue::BindSafe ("bool-b", "tr"), DefaultValue::INVALID_VALUE)
-
- NumericDefaultValue<int32_t> i ("test-i", "help-i", -1);
- NS_TEST_ASSERT_EQUAL (i.GetValue (), -1);
- DefaultValue::Bind ("test-i", "-2");
- NS_TEST_ASSERT_EQUAL (i.GetValue (), -2);
- DefaultValue::Bind ("test-i", "+2");
- NS_TEST_ASSERT_EQUAL (i.GetValue (), 2);
- NS_TEST_ASSERT_EQUAL (i.GetType (), "int32_t(-2147483648:2147483647)");
- NumericDefaultValue<uint32_t> ui32 ("test-ui32", "help-ui32", 10);
- NS_TEST_ASSERT_EQUAL (ui32.GetType (), "uint32_t(0:4294967295)");
- NumericDefaultValue<int8_t> c ("test-c", "help-c", 10);
- NS_TEST_ASSERT_EQUAL (c.GetValue (), 10);
- DefaultValue::Bind ("test-c", "257");
- NumericDefaultValue<float> x ("test-x", "help-x", 10.0);
- NumericDefaultValue<double> y ("test-y", "help-y", 10.0);
- DefaultValue::Bind ("test-y", "-3");
-
- EnumDefaultValue<enum MyEnum> e ("test-e", "help-e",
- MY_ENUM_C, "C",
- MY_ENUM_A, "A",
- MY_ENUM_B, "B",
- 0, (void*)0);
- NS_TEST_ASSERT_EQUAL (e.GetValue (), MY_ENUM_C);
- DefaultValue::Bind ("test-e", "B");
- NS_TEST_ASSERT_EQUAL (e.GetValue (), MY_ENUM_B);
- NS_TEST_ASSERT_EQUAL (DefaultValue::BindSafe ("test-e", "D"), DefaultValue::INVALID_VALUE);
-
- class MyEnumSubclass : public EnumDefaultValue<enum MyEnum>
- {
- public:
- MyEnumSubclass ()
- : EnumDefaultValue<enum MyEnum> ("test-e1", "help-e1",
- MY_ENUM_B, "B",
- MY_ENUM_A, "A",
- 0, (void*)0)
- {
- AddPossibleValue (MY_ENUM_C, "C");
- AddPossibleValue (MY_ENUM_D, "D");
- }
- } e1 ;
- NS_TEST_ASSERT_EQUAL (e1.GetValue (), MY_ENUM_B);
- DefaultValue::Bind ("test-e1", "D");
- NS_TEST_ASSERT_EQUAL (e1.GetValue (), MY_ENUM_D);
-
- DefaultValueList::Remove ("test-e1");
- DefaultValueList::Remove ("test-e");
- DefaultValueList::Remove ("bool-b");
- DefaultValueList::Remove ("bool-a");
- DefaultValueList::Remove ("test-i");
- DefaultValueList::Remove ("test-c");
- DefaultValueList::Remove ("test-x");
- DefaultValueList::Remove ("test-y");
- DefaultValueList::Remove ("test-ui32");
-
- return result;
-}
-
-static DefaultValueTest g_default_value_tests;
-
-}//namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/core/default-value.h Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,621 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 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 DEFAULT_VALUE_H
-#define DEFAULT_VALUE_H
-
-#include <string>
-#include <list>
-#include "callback.h"
-
-/**
- * \ingroup core
- * \defgroup config Simulation configuration
- *
- */
-
-namespace ns3 {
-
-namespace DefaultValue
-{
-
-/**
- * \ingroup config
- * \param name name of variable to bind
- * \param value value to bind to the specified variable
- *
- * If the variable name does not match any existing
- * variable or if the value is not compatible with
- * the variable type, this function will abort
- * at runtime and print an error message detailing
- * which variable or value triggered the problem.
- */
-void Bind (std::string name, std::string value);
-
-}
-
-
-class DefaultValueBase
-{
-public:
- virtual ~DefaultValueBase ();
- std::string GetName (void) const;
- std::string GetHelp (void) const;
-
- /**
- * \returns true if this value is dirty, false otherwise.
- *
- * A value becomes dirty when ParseValue is invoked
- * and it successfully completes. Dirtyness indicates
- * that the state of the value was changed by a user.
- */
- bool IsDirty (void) const;
- /**
- * Clear the dirty state.
- */
- void ClearDirtyFlag (void);
- // parse a matching parameter
- // return true in case of success, false otherwise.
- bool ParseValue (const std::string &value);
- std::string GetType (void) const;
- std::string GetDefaultValue (void) const;
-protected:
- DefaultValueBase (const std::string &name,
- const std::string &help);
-private:
- DefaultValueBase ();
-private:
- virtual bool DoParseValue (const std::string &value) = 0;
- virtual std::string DoGetType (void) const = 0;
- virtual std::string DoGetDefaultValue (void) const = 0;
- std::string m_name;
- std::string m_help;
- bool m_dirty;
-};
-
-class DefaultValueList
-{
- public:
- typedef std::list<DefaultValueBase *>::iterator Iterator;
-
- static Iterator Begin (void);
- 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);
-};
-
-/**
- * \brief A Boolean variable for ns3::Bind
- * \ingroup config
- *
- * Every instance of this type is automatically
- * registered in the variable pool which is used
- * by ns3::Bind.
- */
-class BooleanDefaultValue : public DefaultValueBase
-{
-public:
- /**
- * \param name name of variable
- * \param help help text which explains the purpose
- * and the semantics of this variable
- * \param defaultValue the default value to assign
- * to this variable.
- *
- * Unless the user invokes ns3::Bind with the right arguments,
- * the GetValue method will return the default value. Otherwise,
- * it will return the user-specified value.
- */
- BooleanDefaultValue (std::string name,
- std::string help,
- bool defaultValue);
- /**
- * \returns the default value for this variable or a
- * user-provided overriden variable.
- */
- bool GetValue (void) const;
-private:
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
- bool m_defaultValue;
- bool m_value;
-};
-
-/**
- * \brief A Numeric variable for ns3::Bind
- * \ingroup config
- *
- * Every instance of this type is automatically
- * registered in the variable pool which is used
- * by ns3::Bind.
- */
-template <typename T>
-class NumericDefaultValue : public DefaultValueBase
-{
-public:
- /**
- * \param name the name of the variable
- * \param help help text which explains the purpose
- * and the semantics of this variable
- * \param defaultValue the default value assigned
- * to this variable
- *
- * By default, the set of allowed values is the entire range
- * of values which can be stored and retrieved from the underlying
- * type.
- */
- NumericDefaultValue (std::string name,
- std::string help,
- T defaultValue);
- /**
- * \param name the name of the variable
- * \param help help text which explains the purpose
- * and the semantics of this variable
- * \param defaultValue the default value assigned to this
- * variable
- * \param minValue the minimum value which can be set
- * in this variable
- */
- NumericDefaultValue (std::string name,
- std::string help,
- T defaultValue,
- T minValue);
-
- /**
- * \param name the name of the variable
- * \param help help text which explains the purpose
- * and the semantics of this variable
- * \param defaultValue the default value assigned to this
- * variable
- * \param minValue the minimum value which can be set
- * in this variable
- * \param maxValue the maximum value which can be set in this
- * variable.
- */
- NumericDefaultValue (std::string name,
- std::string help,
- T defaultValue,
- T minValue,
- T maxValue);
-
- void SetValue (T v);
-
- T GetValue (void) const;
-private:
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
- T RealMin (void) const;
- T m_defaultValue;
- T m_minValue;
- T m_maxValue;
- T m_value;
-};
-
-/**
- * \brief Named enumeration defaults
- * \ingroup config
- *
- * Every instance of this type is automatically
- * registered in the variable pool which is used
- * by ns3::Bind.
- */
-class StringEnumDefaultValue : public DefaultValueBase
-{
-public:
- /**
- * \param name The name of the variable
- * \param help The help string
- */
- StringEnumDefaultValue (const std::string &name,
- const std::string &help);
- /**
- * \brief Add a default value to this enumeration of strings
- * \param value The string to make the default for this
- */
- void AddDefaultValue (const std::string &value);
- /**
- * \brief Add a possible value to accept for this default value
- */
- void AddPossibleValue (const std::string &value);
- /**
- * \brief Get the value of this default value.
- * \return The string that has been assigned to this default value, either by
- * Bind() or by a command line setting
- */
- std::string GetValue (void) const;
-private:
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
-
- bool m_oneDefault;
- std::list<std::string> m_possibleValues;
- std::string m_defaultValue;
- std::string m_value;
-};
-
-/**
- * \brief An enum variable for ns3::Bind
- * \ingroup config
- *
- * Every instance of this type is automatically
- * registered in the variable pool which is used
- * by ns3::Bind.
- */
-template <typename T>
-class EnumDefaultValue : public DefaultValueBase
-{
-public:
- /**
- * \param name the name of this variable
- * \param help help text which explains the purpose
- * and the semantics of this variable
- * \param defaultValue the default value assigned to this
- * variable unless it is overriden with ns3::Bind
- * \param defaultValueString the string which represents
- * the default value which should be used by ns3::Bind
- *
- * This method takes a variable number of arguments. The list of
- * arguments is terminated by the pair of values 0 and (void *)0.
- * Each pair of extra argument is assumed to be of the form
- * (enum value, string representing enum value). If ns3::Bind
- * is invoked on this variable, it will check that the user-provided
- * values are within the set of values specified in this constructor.
- *
- * Typical useage of this method will look like this:
- * \code
- * enum MyEnum {
- * MY_ENUM_A,
- * MY_ENUM_B,
- * MY_ENUM_C,
- * };
- * // set default value to be "B".
- * static EnumDefaultValue<enum MyEnum>
- * g_myDefaultValue ("my", "my help",
- * MY_ENUM_B, "B",
- * MY_ENUM_A, "A",
- * MY_ENUM_C, "C",);
- * 0, (void*)0);
- * \endcode
- * Note that to ensure portability to 64 bit systems, make sure that
- * the last element in the variable list of arguments is (void *)0.
- */
- EnumDefaultValue (const std::string &name, const std::string &help,
- T defaultValue, const char *defaultValueString,
- ...);
- void AddPossibleValue (T value, const std::string &valueString);
- /**
- * \returns the default value or any other value specified by the
- * user with ns3::Bind
- */
- T GetValue (void);
- /**
- * \param value the new default value.
- */
- void SetValue (T value);
- private:
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
-
- typedef std::list<std::pair<T,std::string> > PossibleValues;
-
- T m_defaultValue;
- PossibleValues m_possibleValues;
- T m_value;
-};
-
-/**
- * \brief A string variable for ns3::Bind
- * \ingroup config
- *
- * Every instance of this type is automatically
- * registered in the variable pool which is used
- * by ns3::Bind.
- */
-class StringDefaultValue : public DefaultValueBase
-{
-public:
- StringDefaultValue (const std::string &name,
- const std::string &help,
- const std::string defaultValue);
- StringDefaultValue (const std::string &name,
- const std::string &help,
- const std::string defaultValue,
- int maxSize);
- StringDefaultValue (const std::string &name,
- const std::string &help,
- const std::string defaultValue,
- int minSize,
- int maxSize);
-
- std::string GetValue (void) const;
-private:
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
-
- std::string m_defaultValue;
- std::string m_value;
- int m_minSize;
- int m_maxSize;
-};
-
-/**
- * \brief Class used to call a certain function during the configuration of the
- * simulation
- * \ingroup config
- */
-class CommandDefaultValue : public DefaultValueBase
-{
-public:
- CommandDefaultValue (const std::string &name,
- const std::string &help,
- Callback<void> cb);
-private:
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
- Callback<void> m_cb;
-};
-
-}//namespace ns3
-
-#include "type-name.h"
-#include "assert.h"
-#include <sstream>
-#include <stdarg.h>
-#include <limits>
-
-namespace ns3 {
-
-/**************************************************************
- **************************************************************/
-
-
-template <typename T>
-NumericDefaultValue<T>::NumericDefaultValue (std::string name,
- std::string help,
- T defaultValue)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_minValue (RealMin ()),
- m_maxValue (std::numeric_limits<T>::max ()),
- m_value (defaultValue)
-{
- DefaultValueList::Add (this);
- NS_ASSERT (m_minValue < m_maxValue);
-}
-template <typename T>
-NumericDefaultValue<T>::NumericDefaultValue (std::string name,
- std::string help,
- T defaultValue,
- T minValue)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_minValue (minValue),
- m_maxValue (std::numeric_limits<T>::max ()),
- m_value (defaultValue)
-{
- DefaultValueList::Add (this);
- NS_ASSERT (m_minValue < m_maxValue);
- NS_ASSERT (m_defaultValue <= m_maxValue &&
- m_defaultValue >= m_minValue);
-}
-template <typename T>
-NumericDefaultValue<T>::NumericDefaultValue (std::string name,
- std::string help,
- T defaultValue,
- T minValue,
- T maxValue)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_minValue (minValue),
- m_maxValue (maxValue),
- m_value (defaultValue)
-{
- DefaultValueList::Add (this);
- NS_ASSERT (m_minValue < m_maxValue);
- NS_ASSERT (m_defaultValue <= m_maxValue &&
- m_defaultValue >= m_minValue);
-}
-
-template <typename T>
-void
-NumericDefaultValue<T>::SetValue (T v)
-{
- NS_ASSERT (v <= m_maxValue &&
- v >= m_minValue);
- m_value = v;
-}
-
-template <typename T>
-T
-NumericDefaultValue<T>::GetValue (void) const
-{
- return m_value;
-}
-
-template <typename T>
-bool
-NumericDefaultValue<T>::DoParseValue (const std::string &value)
-{
- std::istringstream iss;
- iss.str (value);
- iss >> m_value;
- if (m_value > m_maxValue ||
- m_value < m_minValue)
- {
- return false;
- }
- return !iss.bad () && !iss.fail ();
-}
-
-template <typename T>
-std::string
-NumericDefaultValue<T>::DoGetType (void) const
-{
- std::ostringstream oss;
- oss << TypeNameGet<T> () << "("
- << m_minValue << ":"
- << m_maxValue << ")";
- return oss.str ();
-}
-
-template <typename T>
-std::string
-NumericDefaultValue<T>::DoGetDefaultValue (void) const
-{
- std::ostringstream oss;
- oss << m_defaultValue;
- return oss.str ();
-}
-
-template <typename T>
-T
-NumericDefaultValue<T>::RealMin (void) const
-{
- if (std::numeric_limits<T>::is_integer)
- {
- return std::numeric_limits<T>::min ();
- }
- else
- {
- return -std::numeric_limits<T>::max ();
- }
-}
-
-
-/**************************************************************
- **************************************************************/
-
-template <typename T>
-EnumDefaultValue<T>::EnumDefaultValue (const std::string &name, const std::string &help,
- T defaultValue, const char *defaultValueString,
- ...)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_value (defaultValue)
-{
- AddPossibleValue (defaultValue, defaultValueString);
- va_list list;
- va_start (list, defaultValueString);
- while (true)
- {
- T v = (T) va_arg (list, int);
- const char *str = va_arg (list, const char *);
- if (v == 0 && str == 0)
- {
- break;
- }
- AddPossibleValue (v, str);
- }
- DefaultValueList::Add (this);
-}
-template <typename T>
-void
-EnumDefaultValue<T>::AddPossibleValue (T value, const std::string &valueString)
-{
- m_possibleValues.push_back (std::make_pair (value, valueString));
-}
-template <typename T>
-T
-EnumDefaultValue<T>::GetValue (void)
-{
- return m_value;
-}
-template <typename T>
-void
-EnumDefaultValue<T>::SetValue (T value)
-{
- m_value = value;
-}
-template <typename T>
-bool
-EnumDefaultValue<T>::DoParseValue (const std::string &value)
-{
- for (typename PossibleValues::iterator i = m_possibleValues.begin ();
- i != m_possibleValues.end (); i++)
- {
- if (value == i->second)
- {
- m_value = i->first;
- return true;
- }
- }
- return false;
-}
-template <typename T>
-std::string
-EnumDefaultValue<T>::DoGetType (void) const
-{
- std::string retval;
- retval += "(";
- for (typename PossibleValues::const_iterator i = m_possibleValues.begin ();
- i != m_possibleValues.end (); i++)
- {
- if (i != m_possibleValues.begin ())
- {
- retval += "|";
- }
- retval += i->second;
- }
- retval += ")";
- return retval;
-}
-template <typename T>
-std::string
-EnumDefaultValue<T>::DoGetDefaultValue (void) const
-{
- for (typename PossibleValues::const_iterator i = m_possibleValues.begin ();
- i != m_possibleValues.end (); i++)
- {
- if (i->first == m_defaultValue)
- {
- return i->second;
- }
- }
- // cannot happen theoretically.
- NS_ASSERT (false);
- return ""; // quiet compiler
-}
-
-}//namespace ns3
-
-#endif /* DEFAULT_VALUE_H */
--- a/src/core/random-variable-default-value.cc Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-/* -*- 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
- * 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 "random-variable-default-value.h"
-#include "log.h"
-
-NS_LOG_COMPONENT_DEFINE ("RandomVariableDefaultValue");
-
-namespace ns3 {
-
-RandomVariableDefaultValue::RandomVariableDefaultValue (std::string name,
- std::string help,
- std::string defaultValue)
- : DefaultValueBase (name, help),
- m_defaultValue (defaultValue),
- m_value (defaultValue)
-{
- if (!Parse (defaultValue, false, 0))
- {
- NS_FATAL_ERROR ("Invalid Random Variable specification: " << defaultValue);
- }
- DefaultValueList::Add (this);
-}
-
-RandomVariable
-RandomVariableDefaultValue::Get (void) const
-{
- RandomVariable variable;
- bool ok;
- ok = Parse (m_value, true, &variable);
- NS_ASSERT (ok);
- return variable;
-}
-double
-RandomVariableDefaultValue::ReadAsDouble (std::string value, bool &ok) const
-{
- double v;
- std::istringstream iss;
- iss.str (value);
- iss >> v;
- ok = !iss.bad () && !iss.fail ();
- return v;
-}
-bool
-RandomVariableDefaultValue::Parse (const std::string &value,
- bool mustCreate, RandomVariable *pVariable) const
-{
- std::string::size_type pos = value.find_first_of(":");
- if (pos == std::string::npos)
- {
- return false;
- }
- bool ok;
- std::string type = value.substr (0, pos);
- std::string v = value.substr (pos+1, std::string::npos);
- if (type == "Constant")
- {
- double constant = ReadAsDouble (v, ok);
- if (mustCreate)
- {
- NS_LOG_LOGIC ("create Constant constant=" << constant);
- *pVariable = ConstantVariable (constant);
- }
- else
- {
- NS_LOG_LOGIC ("parse Constant constant=" << constant);
- }
- return ok;
- }
- else if (type == "Uniform")
- {
- std::string::size_type maxPos = v.find_first_of(":");
- if (maxPos == std::string::npos)
- {
- return false;
- }
- std::string min = v.substr (0, maxPos);
- std::string max = v.substr (maxPos + 1, std::string::npos);
- double minVal;
- double maxVal;
- minVal = ReadAsDouble (min, ok);
- maxVal = ReadAsDouble (max, ok);
- if (mustCreate)
- {
- NS_LOG_LOGIC ("create Uniform min=" << min << ", max=" << max);
- *pVariable = UniformVariable (minVal, maxVal);
- }
- else
- {
- NS_LOG_LOGIC ("parse Uniform min=" << min << ", max=" << max);
- }
- return ok;
- }
- else
- {
- // XXX parse other types of distributions.
- return false;
- }
-}
-bool
-RandomVariableDefaultValue::DoParseValue (const std::string &value)
-{
- bool ok = Parse (value, false, 0);
- if (ok)
- {
- m_value = value;
- }
- return ok;
-}
-std::string
-RandomVariableDefaultValue::DoGetType (void) const
-{
- return "(Uniform:min:max|Constant:cst)";
-}
-std::string
-RandomVariableDefaultValue::DoGetDefaultValue (void) const
-{
- return m_defaultValue;
-}
-
-} // namespace ns3
--- a/src/core/random-variable-default-value.h Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/* -*- 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
- * 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 RANDOM_VARIABLE_DEFAULT_VALUE_H
-#define RANDOM_VARIABLE_DEFAULT_VALUE_H
-
-#include "random-variable.h"
-#include "default-value.h"
-
-namespace ns3 {
-
-class RandomVariableDefaultValue : public DefaultValueBase
-{
- public:
- RandomVariableDefaultValue (std::string name,
- std::string help,
- std::string defaultValue);
-
- RandomVariable Get (void) const;
-private:
- bool Parse (const std::string &value, bool mustCreate, RandomVariable *pVariable) const;
- double ReadAsDouble (const std::string value, bool &ok) const;
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
-
- std::string m_defaultValue;
- std::string m_value;
-};
-
-} // namespace ns3
-
-#endif /* RANDOM_VARIABLE_DEFAULT_VALUE_H */
--- a/src/core/type-id-default-value.cc Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-#include "type-id-default-value.h"
-
-namespace ns3 {
-
-TypeIdDefaultValue::TypeIdDefaultValue (std::string name,
- std::string help,
- TypeId tid,
- std::string defaultValue)
- : DefaultValueBase (name, help),
- m_defaultName (defaultValue),
- m_name (defaultValue),
- m_interfaceId (tid)
-{
- DefaultValueList::Add (this);
-}
-TypeId
-TypeIdDefaultValue::GetValue (void) const
-{
- return TypeId::LookupByName (m_name);
-}
-void
-TypeIdDefaultValue::SetValue (TypeId interfaceId)
-{
- m_name = interfaceId.GetName ();
-}
-void
-TypeIdDefaultValue::SetValue (std::string name)
-{
- m_name = name;
-}
-bool
-TypeIdDefaultValue::DoParseValue (const std::string &value)
-{
- for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
- {
- TypeId tid = TypeId::GetRegistered (i);
- do {
- if (tid.GetName () == value &&
- tid.HasConstructor ())
- {
- // check that it really supports the requested interface.
- TypeId tmp = tid;
- do {
- if (tmp == m_interfaceId)
- {
- m_name = value;
- return true;
- }
- tmp = tmp.GetParent ();
- } while (tmp != Object::GetTypeId ());
- }
- tid = tid.GetParent ();
- } while (tid != Object::GetTypeId ());
- }
- return false;
-}
-
-std::string
-TypeIdDefaultValue::DoGetType (void) const
-{
- std::ostringstream oss;
- oss << "(";
- bool first = true;
- for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
- {
- TypeId tid = TypeId::GetRegistered (i);
- // can this interface id be used to create objects ?
- if (tid.HasConstructor ())
- {
- TypeId tmp = tid;
- // does this interface id supports the requested interface id ?
- do {
- if (tmp == m_interfaceId)
- {
- if (!first)
- {
- oss << "|";
- first = false;
- }
- oss << tid.GetName ();
- }
- tmp = tmp.GetParent ();
- } while (tmp != Object::GetTypeId ());
- }
- }
- oss << ")";
- return oss.str ();
-}
-
-std::string
-TypeIdDefaultValue::DoGetDefaultValue (void) const
-{
- return m_name;
-}
-
-} // namespace ns3
--- a/src/core/type-id-default-value.h Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-#ifndef INTERFACE_ID_DEFAULT_VALUE_H
-#define INTERFACE_ID_DEFAULT_VALUE_H
-
-#include "default-value.h"
-#include "object.h"
-
-namespace ns3 {
-
-class TypeIdDefaultValue : public DefaultValueBase
-{
-public:
- /**
- * \param name the name of this default value.
- * \param help the help text associated to this default value
- * \param tid the interface id which all objects created
- * through this "default value" must support.
- * \param defaultValue the name of the object to create
- * by default.
- */
- TypeIdDefaultValue (std::string name,
- std::string help,
- TypeId tid,
- std::string defaultValue);
- /**
- * \returns the TypeId of the object selected by the user.
- */
- TypeId GetValue (void) const;
- /**
- * \param interfaceId the new ClassId selected.
- *
- * Override the currently-selected value.
- */
- void SetValue (TypeId interfaceId);
- /**
- * \param name the new object selected.
- *
- * Override the currently-selected value.
- */
- void SetValue (std::string name);
-private:
- virtual bool DoParseValue (const std::string &value);
- virtual std::string DoGetType (void) const;
- virtual std::string DoGetDefaultValue (void) const;
- std::string m_defaultName;
- std::string m_name;
- TypeId m_interfaceId;
-};
-
-} // namespace ns3
-
-#endif /* INTERFACE_ID_DEFAULT_VALUE_H */
--- a/src/core/wscript Mon Mar 10 00:26:54 2008 +0100
+++ b/src/core/wscript Mon Mar 10 00:27:53 2008 +0100
@@ -38,12 +38,9 @@
'random-variable.cc',
'rng-stream.cc',
'uid-manager.cc',
- 'default-value.cc',
'command-line.cc',
'type-name.cc',
- 'random-variable-default-value.cc',
'type-traits-test.cc',
- 'type-id-default-value.cc',
'attribute.cc',
'boolean.cc',
'attribute-test.cc',
@@ -84,13 +81,10 @@
'test.h',
'random-variable.h',
'rng-stream.h',
- 'default-value.h',
'command-line.h',
'type-name.h',
'type-traits.h',
- 'random-variable-default-value.h',
'int-to-type.h',
- 'type-id-default-value.h',
'attribute.h',
'attribute-accessor-helper.h',
'boolean.h',
--- a/src/internet-node/rtt-estimator.h Mon Mar 10 00:26:54 2008 +0100
+++ b/src/internet-node/rtt-estimator.h Mon Mar 10 00:27:53 2008 +0100
@@ -30,7 +30,6 @@
#include "sequence-number.h"
#include "ns3/nstime.h"
#include "ns3/object.h"
-#include "ns3/type-id-default-value.h"
namespace ns3 {
--- a/src/simulator/scheduler-factory.cc Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,102 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 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 "scheduler-factory.h"
-#include "ns3/assert.h"
-#include "ns3/fatal-error.h"
-#include "ns3/default-value.h"
-
-namespace ns3 {
-
-SchedulerFactory::~SchedulerFactory ()
-{}
-
-Scheduler *
-SchedulerFactory::Create (void) const
-{
- return DoCreate ();
-}
-
-Scheduler *
-SchedulerFactory::CreateDefault (void)
-{
- NS_ASSERT_MSG (!GetList ()->empty (), "No Scheduler factory registered");
- std::string defaultValue = GetDefault ()->GetValue ();
- for (List::const_iterator i = GetList ()->begin ();
- i != GetList ()->end (); i++)
- {
- if (i->second == defaultValue)
- {
- return i->first->Create ();
- }
- }
- NS_ASSERT (false);
- // quiet compiler
- return 0;
-}
-
-Scheduler *
-SchedulerFactory::Create (const std::string &name)
-{
- for (List::iterator i = GetList ()->begin ();
- i != GetList ()->end (); i++)
- {
- if (i->second == name)
- {
- return i->first->Create ();
- }
- }
- NS_ASSERT_MSG (false, "Tried to create non-existant scheduler: " << name);
- // quiet compiler.
- return 0;
-}
-
-void
-SchedulerFactory::AddDefault (const SchedulerFactory *factory,
- const std::string &name)
-{
- GetDefault ()->AddDefaultValue (name);
- GetList ()->push_back (std::make_pair (factory, name));
-}
-
-
-void
-SchedulerFactory::Add (const SchedulerFactory *factory,
- const std::string &name)
-{
- GetDefault ()->AddPossibleValue (name);
- GetList ()->push_back (std::make_pair (factory, name));
-}
-
-StringEnumDefaultValue *
-SchedulerFactory::GetDefault (void)
-{
- static StringEnumDefaultValue value ("Scheduler", "Event Scheduler algorithm");
- return &value;
-}
-
-SchedulerFactory::List *
-SchedulerFactory::GetList (void)
-{
- static SchedulerFactory::List list;
- return &list;
-}
-
-
-}; // namespace ns3
--- a/src/simulator/scheduler-factory.h Mon Mar 10 00:26:54 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 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 SCHEDULER_FACTORY_H
-#define SCHEDULER_FACTORY_H
-
-#include <list>
-
-namespace ns3 {
-
-class Scheduler;
-class StringEnumDefaultValue;
-
-/**
- * \brief a base class to create event schedulers
- *
- * If you want to make the core simulation engine use a new
- * event scheduler without editing the code of the simulator,
- * you need to create a subclass of this base class and implement
- * the ns3::SchedulerFactory::realCreate method.
- */
-class SchedulerFactory {
-public:
- virtual ~SchedulerFactory ();
- /**
- * \returns a newly-created scheduler.
- */
- Scheduler *Create (void) const;
- /**
- * \returns a newly-created scheduler.
- *
- * Return a "default" scheduler.
- */
- static Scheduler *CreateDefault (void);
- /**
- * \param name of scheduler to create.
- * \returns a newly-created scheduler.
- *
- * Create a scheduler registered under the specified name.
- */
- static Scheduler *Create (const std::string &name);
-protected:
- static void Add (const SchedulerFactory *factory,
- const std::string &name);
- static void AddDefault (const SchedulerFactory *factory,
- const std::string &name);
-private:
- typedef std::list<std::pair<const SchedulerFactory *, std::string> > List;
- static SchedulerFactory::List *GetList (void);
- static StringEnumDefaultValue *GetDefault (void);
- /**
- * \returns a newly-created scheduler. The caller takes
- * ownership of the returned pointer.
- *
- * This method must be implemented by subclasses.
- */
- virtual Scheduler *DoCreate (void) const = 0;
-};
-
-}; // namespace ns3
-
-#endif /* SCHEDULER_FACTORY_H */
--- a/src/simulator/scheduler-heap.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/src/simulator/scheduler-heap.cc Mon Mar 10 00:27:53 2008 +0100
@@ -32,7 +32,6 @@
*/
#include "scheduler-heap.h"
-#include "scheduler-factory.h"
#include "event-impl.h"
#include "ns3/assert.h"
@@ -52,20 +51,6 @@
namespace ns3 {
-static class SchedulerHeapFactory : public SchedulerFactory
-{
-public:
- SchedulerHeapFactory ()
- {
- SchedulerFactory::Add (this, "BinaryHeap");
- }
-private:
- virtual Scheduler *DoCreate (void) const
- {
- return new SchedulerHeap ();
- }
-} g_schedulerHeapFactory;
-
SchedulerHeap::SchedulerHeap ()
{
--- a/src/simulator/scheduler-list.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/src/simulator/scheduler-list.cc Mon Mar 10 00:27:53 2008 +0100
@@ -19,7 +19,6 @@
*/
#include "scheduler-list.h"
-#include "scheduler-factory.h"
#include "event-impl.h"
#include <utility>
#include <string>
@@ -27,20 +26,6 @@
namespace ns3 {
-static class SchedulerListFactory : public SchedulerFactory
-{
-public:
- SchedulerListFactory ()
- {
- SchedulerFactory::Add (this, "List");
- }
-private:
- virtual Scheduler *DoCreate (void) const
- {
- return new SchedulerList ();
- }
-} g_schedulerListFactory;
-
SchedulerList::SchedulerList ()
{}
--- a/src/simulator/scheduler-map.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/src/simulator/scheduler-map.cc Mon Mar 10 00:27:53 2008 +0100
@@ -20,7 +20,6 @@
*/
#include "scheduler-map.h"
-#include "scheduler-factory.h"
#include "event-impl.h"
#include "ns3/assert.h"
#include <string>
@@ -38,21 +37,6 @@
namespace ns3 {
-static class SchedulerMapFactory : public SchedulerFactory
-{
-public:
- SchedulerMapFactory ()
- {
- SchedulerFactory::AddDefault (this, "Map");
- }
-private:
- virtual Scheduler *DoCreate (void) const
- {
- return new SchedulerMap ();
- }
-} g_schedulerMapFactory;
-
-
SchedulerMap::SchedulerMap ()
{}
SchedulerMap::~SchedulerMap ()
--- a/src/simulator/simulator.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/src/simulator/simulator.cc Mon Mar 10 00:27:53 2008 +0100
@@ -390,7 +390,6 @@
#include "scheduler-list.h"
#include "scheduler-heap.h"
#include "scheduler-map.h"
-#include "scheduler-factory.h"
namespace ns3 {
--- a/src/simulator/time.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/src/simulator/time.cc Mon Mar 10 00:27:53 2008 +0100
@@ -21,8 +21,11 @@
*/
#include "nstime.h"
#include "ns3/fatal-error.h"
-#include "ns3/default-value.h"
+#include "ns3/global-value.h"
+#include "ns3/enum.h"
+#include "ns3/string.h"
#include "ns3/object.h"
+#include "ns3/config.h"
#include <math.h>
namespace ns3 {
@@ -36,26 +39,28 @@
static const uint64_t FS_FACTOR = (uint64_t)pow(10,15);
static uint64_t g_tsPrecFactor = NS_FACTOR;
-static EnumDefaultValue<enum precision_t> g_precisionDefaultValue ("TimeStepPrecision",
- "The time unit of the internal 64 bit integer time.",
- NS, "NS",
- S, "S",
- MS, "MS",
- US, "US",
- PS, "PS",
- FS, "FS",
- 0, (void *)0);
+static GlobalValue g_precisionDefaultValue ("TimeStepPrecision",
+ "The time unit of the internal 64 bit integer time.",
+ Enum (NS),
+ MakeEnumChecker (NS, "NS",
+ S, "S",
+ MS, "MS",
+ US, "US",
+ PS, "PS",
+ FS, "FS")
+ );
precision_t
Get (void)
{
- return g_precisionDefaultValue.GetValue ();
+ Enum v = g_precisionDefaultValue.GetValue ();
+ return (precision_t) v.Get ();
}
void
Set (precision_t precision)
{
- g_precisionDefaultValue.SetValue (precision);
+ g_precisionDefaultValue.SetValue (Enum (precision));
g_tsPrecFactor = (uint64_t)pow(10, precision);
}
@@ -486,12 +491,12 @@
TimeStepPrecision::Set (TimeStepPrecision::NS);
- DefaultValue::Bind ("TimeStepPrecision", "S");
- DefaultValue::Bind ("TimeStepPrecision", "MS");
- DefaultValue::Bind ("TimeStepPrecision", "US");
- DefaultValue::Bind ("TimeStepPrecision", "NS");
- DefaultValue::Bind ("TimeStepPrecision", "PS");
- DefaultValue::Bind ("TimeStepPrecision", "FS");
+ Config::SetGlobal ("TimeStepPrecision", String ("S"));
+ Config::SetGlobal ("TimeStepPrecision", String ("MS"));
+ Config::SetGlobal ("TimeStepPrecision", String ("US"));
+ Config::SetGlobal ("TimeStepPrecision", String ("NS"));
+ Config::SetGlobal ("TimeStepPrecision", String ("PS"));
+ Config::SetGlobal ("TimeStepPrecision", String ("FS"));
Time tooBig = TimeStep (0x8000000000000000LL);
--- a/src/simulator/wscript Mon Mar 10 00:26:54 2008 +0100
+++ b/src/simulator/wscript Mon Mar 10 00:27:53 2008 +0100
@@ -53,7 +53,6 @@
'time.cc',
'event-id.cc',
'scheduler.cc',
- 'scheduler-factory.cc',
'scheduler-list.cc',
'scheduler-heap.cc',
'scheduler-map.cc',
--- a/utils/print-introspected-doxygen.cc Mon Mar 10 00:26:54 2008 +0100
+++ b/utils/print-introspected-doxygen.cc Mon Mar 10 00:27:53 2008 +0100
@@ -6,43 +6,11 @@
#include "ns3/queue.h"
#include "ns3/drop-tail-queue.h"
#include "ns3/mobility-model-notifier.h"
-#include "ns3/default-value.h"
#include "ns3/string.h"
using namespace ns3;
-static void
-PrintOneDefaultValue (DefaultValueBase *value, std::ostream &os)
-{
- os << "/// <li> \\anchor DefaultValue" << value->GetName ()
- << " " << value->GetName () << std::endl;
- os << "/// <ul>" << std::endl;
- os << "/// <li>Type: " << value->GetType () << "</td></tr>" << std::endl;
- os << "/// <li>Default value: " << value->GetDefaultValue () << "</td></tr>" << std::endl;
- os << "/// <li>Description: " << value->GetHelp () << "</td></tr>" << std::endl;
- os << "/// </ul>" << std::endl;
- os << "/// </li>" << std::endl;
-}
-
-static void
-PrintDefaultValuesDoxygen (std::ostream &os)
-{
- os << "/// \\page ListOfDefaultValues The list of default values" << std::endl;
- os << "/// \\defgroup ListOfDefaultValuesGroup The list of default values" << std::endl;
- os << "/// <ul>" << std::endl;
- for (DefaultValueList::Iterator i = DefaultValueList::Begin ();
- i != DefaultValueList::End (); i++)
- {
- if ((*i)->GetName () == "help")
- {
- continue;
- }
- PrintOneDefaultValue (*i, os);
- }
- os << "/// </ul>" << std::endl;
-}
-
int main (int argc, char *argv[])
{
@@ -60,7 +28,5 @@
csma->AddQueue (CreateObject<DropTailQueue> ());
- PrintDefaultValuesDoxygen (std::cout);
-
return 0;
}