bindings: Remove CreateObject/GetObject tricks
This commit is contained in:
@@ -560,81 +560,6 @@ def load_modules():
|
||||
)
|
||||
setattr(cppyy.gbl.ns3, "LookupByNameFailSafe", cppyy.gbl.LookupByNameFailSafe)
|
||||
|
||||
def CreateObject(className):
|
||||
try:
|
||||
try:
|
||||
func = "CreateObject%s" % re.sub("[<|>]", "_", className)
|
||||
return getattr(cppyy.gbl, func)()
|
||||
except AttributeError:
|
||||
pass
|
||||
try:
|
||||
func = "Create%s" % re.sub("[<|>]", "_", className)
|
||||
return getattr(cppyy.gbl, func)()
|
||||
except AttributeError:
|
||||
pass
|
||||
raise AttributeError
|
||||
except AttributeError:
|
||||
try:
|
||||
func = "CreateObject%s" % re.sub("[<|>]", "_", className)
|
||||
cppyy.cppdef(
|
||||
"""
|
||||
using namespace ns3;
|
||||
Ptr<%s> %s(){
|
||||
Ptr<%s> object = CreateObject<%s>();
|
||||
return object;
|
||||
}
|
||||
"""
|
||||
% (className, func, className, className)
|
||||
)
|
||||
except Exception as e:
|
||||
try:
|
||||
func = "Create%s" % re.sub("[<|>]", "_", className)
|
||||
cppyy.cppdef(
|
||||
"""
|
||||
using namespace ns3;
|
||||
%s %s(){
|
||||
%s object = %s();
|
||||
return object;
|
||||
}
|
||||
"""
|
||||
% (className, func, className, className)
|
||||
)
|
||||
except Exception as e:
|
||||
exit(-1)
|
||||
return getattr(cppyy.gbl, func)()
|
||||
|
||||
setattr(cppyy.gbl.ns3, "CreateObject", CreateObject)
|
||||
|
||||
def GetObject(parentObject, aggregatedObject):
|
||||
# Objects have __cpp_name__ attributes, so parentObject
|
||||
# should not have it while aggregatedObject can
|
||||
if hasattr(parentObject, "__cpp_name__"):
|
||||
raise Exception("Class was passed instead of an instance in parentObject")
|
||||
|
||||
aggregatedIsClass = hasattr(aggregatedObject, "__cpp_name__")
|
||||
aggregatedIsString = type(aggregatedObject) == str
|
||||
aggregatedIsInstance = not aggregatedIsClass and not aggregatedIsString
|
||||
|
||||
if aggregatedIsClass:
|
||||
aggregatedType = aggregatedObject.__cpp_name__
|
||||
if aggregatedIsInstance:
|
||||
aggregatedType = aggregatedObject.__class__.__cpp_name__
|
||||
if aggregatedIsString:
|
||||
aggregatedType = aggregatedObject
|
||||
|
||||
cppyy.cppdef(
|
||||
"""using namespace ns3; template <> Ptr<%s> getAggregatedObject<%s>(Ptr<Object> parentPtr, %s param)
|
||||
{
|
||||
return parentPtr->GetObject<%s>();
|
||||
}
|
||||
"""
|
||||
% (aggregatedType, aggregatedType, aggregatedType, aggregatedType)
|
||||
)
|
||||
return cppyy.gbl.getAggregatedObject(
|
||||
parentObject, aggregatedObject if aggregatedIsClass else aggregatedObject.__class__
|
||||
)
|
||||
|
||||
setattr(cppyy.gbl.ns3, "GetObject", GetObject)
|
||||
return cppyy.gbl.ns3
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user