Make Names API return void not bool, rescan for Python Bindings

This commit is contained in:
Craig Dowell
2009-03-26 17:39:20 -07:00
parent b7ab01edef
commit 4d17b00ad4
5 changed files with 75 additions and 66 deletions

View File

@@ -479,34 +479,34 @@ def register_Ns3Names_methods(root_module, cls):
cls.add_constructor([param('ns3::Names const &', 'arg0')])
## names.h: ns3::Names::Names() [constructor]
cls.add_constructor([])
## names.h: static bool ns3::Names::Add(std::string name, ns3::Ptr<ns3::Object> obj) [member function]
## names.h: static void ns3::Names::Add(std::string name, ns3::Ptr<ns3::Object> obj) [member function]
cls.add_method('Add',
'bool',
'void',
[param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'obj')],
is_static=True)
## names.h: static bool ns3::Names::Add(std::string path, std::string name, ns3::Ptr<ns3::Object> object) [member function]
## names.h: static void ns3::Names::Add(std::string path, std::string name, ns3::Ptr<ns3::Object> object) [member function]
cls.add_method('Add',
'bool',
'void',
[param('std::string', 'path'), param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'object')],
is_static=True)
## names.h: static bool ns3::Names::Add(ns3::Ptr<ns3::Object> context, std::string name, ns3::Ptr<ns3::Object> object) [member function]
## names.h: static void ns3::Names::Add(ns3::Ptr<ns3::Object> context, std::string name, ns3::Ptr<ns3::Object> object) [member function]
cls.add_method('Add',
'bool',
'void',
[param('ns3::Ptr< ns3::Object >', 'context'), param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'object')],
is_static=True)
## names.h: static bool ns3::Names::Rename(std::string oldpath, std::string newname) [member function]
## names.h: static void ns3::Names::Rename(std::string oldpath, std::string newname) [member function]
cls.add_method('Rename',
'bool',
'void',
[param('std::string', 'oldpath'), param('std::string', 'newname')],
is_static=True)
## names.h: static bool ns3::Names::Rename(std::string path, std::string oldname, std::string newname) [member function]
## names.h: static void ns3::Names::Rename(std::string path, std::string oldname, std::string newname) [member function]
cls.add_method('Rename',
'bool',
'void',
[param('std::string', 'path'), param('std::string', 'oldname'), param('std::string', 'newname')],
is_static=True)
## names.h: static bool ns3::Names::Rename(ns3::Ptr<ns3::Object> context, std::string oldname, std::string newname) [member function]
## names.h: static void ns3::Names::Rename(ns3::Ptr<ns3::Object> context, std::string oldname, std::string newname) [member function]
cls.add_method('Rename',
'bool',
'void',
[param('ns3::Ptr< ns3::Object >', 'context'), param('std::string', 'oldname'), param('std::string', 'newname')],
is_static=True)
## names.h: static std::string ns3::Names::FindName(ns3::Ptr<ns3::Object> object) [member function]

View File

@@ -946,6 +946,8 @@ def register_Ns3StaticMulticastRouteHelper_methods(root_module, cls):
def register_Ns3TapBridgeHelper_methods(root_module, cls):
## tap-bridge-helper.h: ns3::TapBridgeHelper::TapBridgeHelper(ns3::TapBridgeHelper const & arg0) [copy constructor]
cls.add_constructor([param('ns3::TapBridgeHelper const &', 'arg0')])
## tap-bridge-helper.h: ns3::TapBridgeHelper::TapBridgeHelper() [constructor]
cls.add_constructor([])
## tap-bridge-helper.h: ns3::TapBridgeHelper::TapBridgeHelper(ns3::Ipv4Address gateway) [constructor]
cls.add_constructor([param('ns3::Ipv4Address', 'gateway')])
## tap-bridge-helper.h: void ns3::TapBridgeHelper::SetAttribute(std::string n1, ns3::AttributeValue const & v1) [member function]
@@ -968,6 +970,10 @@ def register_Ns3TapBridgeHelper_methods(root_module, cls):
cls.add_method('Install',
'ns3::Ptr< ns3::NetDevice >',
[param('std::string', 'nodeName'), param('std::string', 'ndName')])
## tap-bridge-helper.h: ns3::Ptr<ns3::NetDevice> ns3::TapBridgeHelper::Install(ns3::Ptr<ns3::Node> node, ns3::Ptr<ns3::NetDevice> nd, ns3::AttributeValue const & v1) [member function]
cls.add_method('Install',
'ns3::Ptr< ns3::NetDevice >',
[param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::NetDevice >', 'nd'), param('ns3::AttributeValue const &', 'v1')])
return
def register_Ns3UdpEchoClientHelper_methods(root_module, cls):

View File

@@ -5,6 +5,8 @@ def register_types(module):
## tap-bridge.h: ns3::TapBridge [class]
module.add_class('TapBridge', parent=root_module['ns3::NetDevice'])
## tap-bridge.h: ns3::TapBridge::Mode [enumeration]
module.add_enum('Mode', ['ILLEGAL', 'CONFIGURE_LOCAL', 'USE_LOCAL', 'USE_BRIDGE'], outer_class=root_module['ns3::TapBridge'])
## Register a nested module for the namespace Config
@@ -76,6 +78,14 @@ def register_Ns3TapBridge_methods(root_module, cls):
cls.add_method('Stop',
'void',
[param('ns3::Time', 'tStop')])
## tap-bridge.h: void ns3::TapBridge::SetMode(ns3::TapBridge::Mode mode) [member function]
cls.add_method('SetMode',
'void',
[param('ns3::TapBridge::Mode', 'mode')])
## tap-bridge.h: ns3::TapBridge::Mode ns3::TapBridge::GetMode() [member function]
cls.add_method('GetMode',
'ns3::TapBridge::Mode',
[])
## tap-bridge.h: void ns3::TapBridge::SetName(std::string const name) [member function]
cls.add_method('SetName',
'void',

View File

@@ -623,40 +623,47 @@ Names::Delete (void)
NamesPriv::Delete ();
}
bool
void
Names::Add (std::string name, Ptr<Object> object)
{
return NamesPriv::Get ()->Add (name, object);
bool result = NamesPriv::Get ()->Add (name, object);
NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding name " << name);
}
bool
void
Names::Rename (std::string oldpath, std::string newname)
{
return NamesPriv::Get ()->Rename (oldpath, newname);
bool result = NamesPriv::Get ()->Rename (oldpath, newname);
NS_ABORT_MSG_UNLESS (result, "Names::Rename(): Error renaming " << oldpath << " to " << newname);
}
bool
void
Names::Add (std::string path, std::string name, Ptr<Object> object)
{
return NamesPriv::Get ()->Add (path, name, object);
bool result = NamesPriv::Get ()->Add (path, name, object);
NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding " << path << " " << name);
}
bool
void
Names::Rename (std::string path, std::string oldname, std::string newname)
{
return NamesPriv::Get ()->Rename (path, oldname, newname);
bool result = NamesPriv::Get ()->Rename (path, oldname, newname);
NS_ABORT_MSG_UNLESS (result, "Names::Rename (): Error renaming " << path << " " << oldname << " to " << newname);
}
bool
void
Names::Add (Ptr<Object> context, std::string name, Ptr<Object> object)
{
return NamesPriv::Get ()->Add (context, name, object);
bool result = NamesPriv::Get ()->Add (context, name, object);
NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding name " << name << " under context " << &context);
}
bool
void
Names::Rename (Ptr<Object> context, std::string oldname, std::string newname)
{
return NamesPriv::Get ()->Rename (context, oldname, newname);
bool result = NamesPriv::Get ()->Rename (context, oldname, newname);
NS_ABORT_MSG_UNLESS (result, "Names::Rename (): Error renaming " << oldname << " to " << newname << " under context " <<
&context);
}
std::string
@@ -730,50 +737,53 @@ NamesTest::RunTests (void)
{
bool result = true;
//
// Names::Add and Names::Rename return void to align with the Config API.
// The private versions of these functions do return error codes so we
// can test to make sure errors are detected. Names::Add and
// Names::Rename check for these error codes and abort if an error was
// detected. So when we expect that an error should be detected, we
// have to call the private routine to avoid a fatal error popping.
//
// Name a couple of objects at the root level
//
Ptr<TestObject> client = CreateObject<TestObject> ();
result = Names::Add ("Client", client);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add ("Client", client);
Ptr<TestObject> server = CreateObject<TestObject> ();
result = Names::Add ("Server", server);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add ("Server", server);
//
// We shouldn't be able to add another name to a previously named object
//
result = Names::Add ("Not Client", client);
result = NamesPriv::Get ()->Add ("Not Client", client);
NS_TEST_ASSERT_EQUAL (result, false);
//
// We shouldn't be able to duplicate a name at the root level.
//
Ptr<TestObject> secondClient = CreateObject<TestObject> ();
result = Names::Add ("Client", secondClient);
result = NamesPriv::Get ()->Add ("Client", secondClient);
NS_TEST_ASSERT_EQUAL (result, false);
//
// We should be able to add a new name in the first object's context
//
Ptr<TestObject> clientEth0 = CreateObject<TestObject> ();
result = Names::Add (client, "eth0", clientEth0);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add (client, "eth0", clientEth0);
//
// We shouldn't be able to duplicate a name in that context.
//
Ptr<TestObject> secondClientEth0 = CreateObject<TestObject> ();
result = Names::Add (client, "eth0", secondClientEth0);
result = NamesPriv::Get ()->Add (client, "eth0", secondClientEth0);
NS_TEST_ASSERT_EQUAL (result, false);
//
// We should be able to add the same name in the second object's context
//
Ptr<TestObject> serverEth0 = CreateObject<TestObject> ();
result = Names::Add (server, "eth0", serverEth0);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add (server, "eth0", serverEth0);
//
// We should be able to find the short names for the objects we created
@@ -879,32 +889,28 @@ NamesTest::RunTests (void)
// in the name.
//
Ptr<TestObject> router1 = CreateObject<TestObject> ();
result = Names::Add ("/Names/Router1", router1);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add ("/Names/Router1", router1);
//
// We should be able to add objects while not including the root of the namespace
// in the name.
//
Ptr<TestObject> router2 = CreateObject<TestObject> ();
result = Names::Add ("Router2", router2);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add ("Router2", router2);
//
// We should be able to add sub-objects while including the root of the namespace
// in the name.
//
Ptr<TestObject> router1Eth0 = CreateObject<TestObject> ();
result = Names::Add ("/Names/Router1/eth0", router1Eth0);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add ("/Names/Router1/eth0", router1Eth0);
//
// We should be able to add sub-objects while not including the root of the namespace
// in the name.
//
Ptr<TestObject> router2Eth0 = CreateObject<TestObject> ();
result = Names::Add ("Router2/eth0", router2Eth0);
NS_TEST_ASSERT_EQUAL (result, true);
Names::Add ("Router2/eth0", router2Eth0);
//
// We should be able to find these objects in the same two ways
@@ -937,20 +943,17 @@ NamesTest::RunTests (void)
// We have a pile of names defined. We should be able to rename them in the
// usual ways.
//
result = Names::Rename ("/Names/Router1", "RouterX");
NS_TEST_ASSERT_EQUAL (result, true);
Names::Rename ("/Names/Router1", "RouterX");
foundObject = Names::Find<TestObject> ("/Names/RouterX");
NS_TEST_ASSERT_EQUAL (foundObject, router1);
result = Names::Rename ("Router2", "RouterY");
NS_TEST_ASSERT_EQUAL (result, true);
Names::Rename ("Router2", "RouterY");
foundObject = Names::Find<TestObject> ("RouterY");
NS_TEST_ASSERT_EQUAL (foundObject, router2);
result = Names::Rename ("/Names/RouterX/eth0", "ath0");
NS_TEST_ASSERT_EQUAL (result, true);
Names::Rename ("/Names/RouterX/eth0", "ath0");
foundObject = Names::Find<TestObject> ("/Names/RouterX/ath0");
NS_TEST_ASSERT_EQUAL (foundObject, router1Eth0);
@@ -963,7 +966,7 @@ NamesTest::RunTests (void)
// object.
//
result = Names::Rename ("/Names/RouterX", "RouterY");
result = NamesPriv::Get ()->Rename ("/Names/RouterX", "RouterY");
NS_TEST_ASSERT_EQUAL (result, false);
Names::Delete ();

View File

@@ -65,7 +65,7 @@ public:
* prepended with a path to that object.
* \param obj A smart pointer to the object itself.
*/
static bool Add (std::string name, Ptr<Object> obj);
static void Add (std::string name, Ptr<Object> obj);
/**
* \brief An intermediate form of Names::Add allowing you to provide a path to
@@ -96,11 +96,9 @@ public:
* \param name The name of the object you want to associate.
* \param obj A smart pointer to the object itself.
*
* \returns true if the association was successfully completed, false otherwise
*
* \see Names::Add (Ptr<Object> context, std::string name, Ptr<Object> object);
*/
static bool Add (std::string path, std::string name, Ptr<Object> object);
static void Add (std::string path, std::string name, Ptr<Object> object);
/**
* \brief A low-level form of Names::Add allowing you to specify the path to
@@ -148,10 +146,8 @@ public:
* under which you want this new name to be defined.
* \param name The name of the object you want to associate.
* \param obj A smart pointer to the object itself.
*
* \returns true if the association was successfully completed, false otherwise
*/
static bool Add (Ptr<Object> context, std::string name, Ptr<Object> object);
static void Add (Ptr<Object> context, std::string name, Ptr<Object> object);
/**
* \brief Rename a previously associated name.
@@ -178,11 +174,9 @@ public:
* \param oldpath The current path name to the object you want to change.
* \param newname The new name of the object you want to change.
*
* \returns true if the name change was successfully completed, false otherwise
*
* \see Names::Add (std::string name, Ptr<Object> obj)
*/
static bool Rename (std::string oldpath, std::string newname);
static void Rename (std::string oldpath, std::string newname);
/**
* \brief An intermediate form of Names::Rename allowing you to provide a path to
@@ -203,10 +197,8 @@ public:
* you want this name change to occur (cf. directory).
* \param oldname The currently defined name of the object.
* \param newname The new name you want the object to have.
*
* \returns true if the name change was successfully completed, false otherwise
*/
static bool Rename (std::string path, std::string oldname, std::string newname);
static void Rename (std::string path, std::string oldname, std::string newname);
/**
* \brief A low-level form of Names::Rename allowing you to specify the path to
@@ -244,10 +236,8 @@ public:
* under which you want this new name to be defined.
* \param oldname The current shortname of the object you want to change.
* \param newname The new shortname of the object you want to change.
*
* \returns true if the name change was successfully completed, false otherwise
*/
static bool Rename (Ptr<Object> context, std::string oldname, std::string newname);
static void Rename (Ptr<Object> context, std::string oldname, std::string newname);
/**
* Given a pointer to an object, look to see if that object has a name