rename Bind to DefaultValue::Bind. fix bug 62
--- a/examples/csma-cd-one-subnet.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/examples/csma-cd-one-subnet.cc Wed Aug 08 16:41:59 2007 +0200
@@ -82,7 +82,7 @@
// The below Bind command tells the queue factory which class to
// instantiate, when the queue factory is invoked in the topology code
- Bind ("Queue", "DropTailQueue");
+ DefaultValue::Bind ("Queue", "DropTailQueue");
// Allow the user to override any of the defaults and the above
// Bind()s at run-time, via command-line arguments
--- a/examples/simple-global-routing.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/examples/simple-global-routing.cc Wed Aug 08 16:41:59 2007 +0200
@@ -85,21 +85,21 @@
DebugComponentEnable ("GlobalRouteMaager");
#endif
- // Set up some default values for the simulation. Use the Bind ()
+ // Set up some default values for the simulation. Use the DefaultValue::Bind ()
// technique to tell the system what subclass of Queue to use,
// and what the queue limit is
// The below Bind command tells the queue factory which class to
// instantiate, when the queue factory is invoked in the topology code
- Bind ("Queue", "DropTailQueue");
+ DefaultValue::Bind ("Queue", "DropTailQueue");
- Bind ("OnOffApplicationPacketSize", "210");
- Bind ("OnOffApplicationDataRate", "448kb/s");
+ DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
+ DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
- //Bind ("DropTailQueue::m_maxPackets", 30);
+ //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
// Allow the user to override any of the defaults and the above
- // Bind ()s at run-time, via command-line arguments
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
CommandLine::Parse (argc, argv);
// Here, we will explicitly create four nodes. In more sophisticated
--- a/examples/simple-point-to-point.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/examples/simple-point-to-point.cc Wed Aug 08 16:41:59 2007 +0200
@@ -87,12 +87,12 @@
// The below Bind command tells the queue factory which class to
// instantiate, when the queue factory is invoked in the topology code
- Bind ("Queue", "DropTailQueue");
+ DefaultValue::Bind ("Queue", "DropTailQueue");
- Bind ("OnOffApplicationPacketSize", "210");
- Bind ("OnOffApplicationDataRate", "448kb/s");
+ DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
+ DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
- //Bind ("DropTailQueue::m_maxPackets", 30);
+ //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
// Allow the user to override any of the defaults and the above
// Bind()s at run-time, via command-line arguments
--- a/samples/main-default-value.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/samples/main-default-value.cc Wed Aug 08 16:41:59 2007 +0200
@@ -73,7 +73,7 @@
// global variable and value (string) to overwrite the default.
// Here, the default value of 33 for testInt1 is overwritten with 57
//
- Bind("testInt1", "57");
+ DefaultValue::Bind("testInt1", "57");
TestClass* testclass = new TestClass ();
NS_DEBUG_UNCOND("TestBool1 default value (" << testclass->m_testBool1 << ")");
--- a/samples/main-random-topology.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/samples/main-random-topology.cc Wed Aug 08 16:41:59 2007 +0200
@@ -24,12 +24,12 @@
int main (int argc, char *argv[])
{
- Bind ("RandomDiscPositionX", "100");
- Bind ("RandomDiscPositionY", "50");
- Bind ("RandomDiscPositionRho", "Uniform:0:30");
+ DefaultValue::Bind ("RandomDiscPositionX", "100");
+ DefaultValue::Bind ("RandomDiscPositionY", "50");
+ DefaultValue::Bind ("RandomDiscPositionRho", "Uniform:0:30");
- Bind ("RandomTopologyPositionType", "RandomDiscPosition");
- Bind ("RandomTopologyMobilityType", "StaticMobilityModel");
+ DefaultValue::Bind ("RandomTopologyPositionType", "RandomDiscPosition");
+ DefaultValue::Bind ("RandomTopologyMobilityType", "StaticMobilityModel");
CommandLine::Parse (argc, argv);
--- a/src/core/default-value.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/src/core/default-value.cc Wed Aug 08 16:41:59 2007 +0200
@@ -23,6 +23,52 @@
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),
@@ -112,48 +158,6 @@
return &list;
}
-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;
- }
-}
-
BooleanDefaultValue::BooleanDefaultValue (std::string name,
std::string help,
bool defaultValue)
@@ -345,36 +349,36 @@
BooleanDefaultValue a ("bool-a", "help a", true);
NS_TEST_ASSERT (a.GetValue ());
- Bind ("bool-a", "false");
+ DefaultValue::Bind ("bool-a", "false");
NS_TEST_ASSERT (!a.GetValue ());
BooleanDefaultValue b ("bool-b", "help b", false);
- Bind ("bool-b", "true");
+ DefaultValue::Bind ("bool-b", "true");
NS_TEST_ASSERT (b.GetValue ());
- Bind ("bool-b", "0");
+ DefaultValue::Bind ("bool-b", "0");
NS_TEST_ASSERT (!b.GetValue ());
- Bind ("bool-b", "1");
+ DefaultValue::Bind ("bool-b", "1");
NS_TEST_ASSERT (b.GetValue ());
- Bind ("bool-b", "f");
+ DefaultValue::Bind ("bool-b", "f");
NS_TEST_ASSERT (!b.GetValue ());
- Bind ("bool-b", "t");
+ DefaultValue::Bind ("bool-b", "t");
NS_TEST_ASSERT (b.GetValue ());
- Bind ("bool-b", "false");
+ DefaultValue::Bind ("bool-b", "false");
NS_TEST_ASSERT (!b.GetValue ());
- NS_TEST_ASSERT_EQUAL (BindSafe ("bool-b", "tr"), INVALID_VALUE)
+ 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);
- Bind ("test-i", "-2");
+ DefaultValue::Bind ("test-i", "-2");
NS_TEST_ASSERT_EQUAL (i.GetValue (), -2);
- Bind ("test-i", "+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);
- Bind ("test-c", "257");
+ DefaultValue::Bind ("test-c", "257");
NumericDefaultValue<float> x ("test-x", "help-x", 10.0);
NumericDefaultValue<double> y ("test-y", "help-y", 10.0);
@@ -385,9 +389,9 @@
MY_ENUM_B, "B",
0, (void*)0);
NS_TEST_ASSERT_EQUAL (e.GetValue (), MY_ENUM_C);
- Bind ("test-e", "B");
+ DefaultValue::Bind ("test-e", "B");
NS_TEST_ASSERT_EQUAL (e.GetValue (), MY_ENUM_B);
- NS_TEST_ASSERT_EQUAL (BindSafe ("test-e", "D"), INVALID_VALUE);
+ NS_TEST_ASSERT_EQUAL (DefaultValue::BindSafe ("test-e", "D"), DefaultValue::INVALID_VALUE);
class MyEnumSubclass : public EnumDefaultValue<enum MyEnum>
{
@@ -403,7 +407,7 @@
}
} e1 ;
NS_TEST_ASSERT_EQUAL (e1.GetValue (), MY_ENUM_B);
- Bind ("test-e1", "D");
+ DefaultValue::Bind ("test-e1", "D");
NS_TEST_ASSERT_EQUAL (e1.GetValue (), MY_ENUM_D);
DefaultValueList::Remove ("test-e1");
--- a/src/core/default-value.h Wed Aug 08 15:59:08 2007 +0200
+++ b/src/core/default-value.h Wed Aug 08 16:41:59 2007 +0200
@@ -31,6 +31,25 @@
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:
@@ -84,19 +103,6 @@
};
/**
- * \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);
-
-/**
* \brief A Boolean variable for ns3::Bind
* \ingroup config
*
--- a/src/simulator/simulator.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/src/simulator/simulator.cc Wed Aug 08 16:41:59 2007 +0200
@@ -337,20 +337,20 @@
void Simulator::SetLinkedList (void)
{
- Bind ("Scheduler", "List");
+ DefaultValue::Bind ("Scheduler", "List");
}
void Simulator::SetBinaryHeap (void)
{
- Bind ("Scheduler", "BinaryHeap");
+ DefaultValue::Bind ("Scheduler", "BinaryHeap");
}
void Simulator::SetStdMap (void)
{
- Bind ("Scheduler", "Map");
+ DefaultValue::Bind ("Scheduler", "Map");
}
void
Simulator::SetExternal (const std::string &external)
{
- Bind ("Scheduler", external);
+ DefaultValue::Bind ("Scheduler", external);
}
void Simulator::EnableLogTo (char const *filename)
{
--- a/src/simulator/time.cc Wed Aug 08 15:59:08 2007 +0200
+++ b/src/simulator/time.cc Wed Aug 08 16:41:59 2007 +0200
@@ -414,12 +414,12 @@
TimeStepPrecision::Set (TimeStepPrecision::NS);
- Bind ("TimeStepPrecision", "S");
- Bind ("TimeStepPrecision", "MS");
- Bind ("TimeStepPrecision", "US");
- Bind ("TimeStepPrecision", "NS");
- Bind ("TimeStepPrecision", "PS");
- Bind ("TimeStepPrecision", "FS");
+ DefaultValue::Bind ("TimeStepPrecision", "S");
+ DefaultValue::Bind ("TimeStepPrecision", "MS");
+ DefaultValue::Bind ("TimeStepPrecision", "US");
+ DefaultValue::Bind ("TimeStepPrecision", "NS");
+ DefaultValue::Bind ("TimeStepPrecision", "PS");
+ DefaultValue::Bind ("TimeStepPrecision", "FS");
return ok;
}