Commit eb823da0 authored by cdelort's avatar cdelort
Browse files

apply changes from ROOT-10349: boost_shared_ptr and shared_ptr

parent c5b3abc0
......@@ -37,7 +37,7 @@ def all():
###cool_FieldSelection()
filterwarnings()
boost_shared_ptr() # this is better at the end
std_shared_ptr() # this is better at the end
#std_shared_ptr() # this is better at the end
#######################################################################
# #
......@@ -113,37 +113,39 @@ def boost_shared_ptr():
This function find all the classes starting with 'boost::shared_ptr<'.
The added function allows to emulate the 'smart pointer ' behaviour.
"""
# add the new function to all boost::shared_ptr<> classes
for c in getAllClasses():
if c.startswith("boost::shared_ptr"):
cls = getattr(gbl,c)
# use the conversion to string of the wrapped object.
cls.__str__ = lambda self: str(self.get())
# do not overload the __repr__ operator (will show the true type)
# define a pythonizor function (ROOT-10349)
def boost_shared_ptr_pythonizor(klass, name):
if name.startswith("boost::shared_ptr"):
# use the conversion to string of the wrapped object.
klass.__str__ = lambda self: str(self.get())
# way to add a pythonization lazily
cppyy.py.add_pythonization(boost_shared_ptr_pythonizor)
########################################################################
### std::shared_ptr
def std_shared_ptr():
"""
Instrument std::shared_ptr<T>.
This function find all the classes starting with 'std::shared_ptr<'.
The added function allows to emulate the 'smart pointer ' behaviour.
"""
# 1. Dynamic implementation - but getAllClasses is no good (bug #103318)
# add the new function to all std::shared_ptr<> classes
#for c in getAllClasses():
# if c.startswith("std::shared_ptr"):
# cls = getattr(gbl,c)
# # use the conversion to string of the wrapped object.
# cls.__str__ = lambda self: str(self.get())
# # do not overload the __repr__ operator (will show the true type)
# 2. Static implementation - workaround for bug #103318
for c in ['IDatabase','IFolder','IFolderSet','IObject','IObjectIterator','IObjectVector ','IRecord','IRecordVector','ITransaction']:
if hasattr(gbl,"std::shared_ptr<cool::"+c+">"):
cls = getattr(gbl,"std::shared_ptr<cool::"+c+">")
# use the conversion to string of the wrapped object.
cls.__str__ = lambda self: str(self.get())
# do not overload the __repr__ operator (will show the true type)
# Not necessary (ROOT-10349)
# ### std::shared_ptr
# def std_shared_ptr():
# """
# Instrument std::shared_ptr<T>.
# This function find all the classes starting with 'std::shared_ptr<'.
# The added function allows to emulate the 'smart pointer ' behaviour.
# """
# # 1. Dynamic implementation - but getAllClasses is no good (bug #103318)
# # add the new function to all std::shared_ptr<> classes
# #for c in getAllClasses():
# # if c.startswith("std::shared_ptr"):
# # cls = getattr(gbl,c)
# # # use the conversion to string of the wrapped object.
# # cls.__str__ = lambda self: str(self.get())
# # # do not overload the __repr__ operator (will show the true type)
# # 2. Static implementation - workaround for bug #103318
# for c in ['IDatabase','IFolder','IFolderSet','IObject','IObjectIterator','IObjectVector ','IRecord','IRecordVector','ITransaction']:
# if hasattr(gbl,"std::shared_ptr<cool::"+c+">"):
# cls = getattr(gbl,"std::shared_ptr<cool::"+c+">")
# # use the conversion to string of the wrapped object.
# cls.__str__ = lambda self: str(self.get())
# # do not overload the __repr__ operator (will show the true type)
########################################################################
### cool::Time
......
......@@ -37,7 +37,7 @@ def all():
###cool_FieldSelection()
filterwarnings()
boost_shared_ptr() # this is better at the end
std_shared_ptr() # this is better at the end
#std_shared_ptr() # this is better at the end
#######################################################################
# #
......@@ -113,37 +113,39 @@ def boost_shared_ptr():
This function find all the classes starting with 'boost::shared_ptr<'.
The added function allows to emulate the 'smart pointer ' behaviour.
"""
# add the new function to all boost::shared_ptr<> classes
for c in getAllClasses():
if c.startswith("boost::shared_ptr"):
cls = getattr(gbl,c)
# use the conversion to string of the wrapped object.
cls.__str__ = lambda self: str(self.get())
# do not overload the __repr__ operator (will show the true type)
# define a pythonizor function (ROOT-10349)
def boost_shared_ptr_pythonizor(klass, name):
if name.startswith("boost::shared_ptr"):
# use the conversion to string of the wrapped object.
klass.__str__ = lambda self: str(self.get())
# way to add a pythonization lazily
cppyy.py.add_pythonization(boost_shared_ptr_pythonizor)
########################################################################
### std::shared_ptr
def std_shared_ptr():
"""
Instrument std::shared_ptr<T>.
This function find all the classes starting with 'std::shared_ptr<'.
The added function allows to emulate the 'smart pointer ' behaviour.
"""
# 1. Dynamic implementation - but getAllClasses is no good (bug #103318)
# add the new function to all std::shared_ptr<> classes
#for c in getAllClasses():
# if c.startswith("std::shared_ptr"):
# cls = getattr(gbl,c)
# # use the conversion to string of the wrapped object.
# cls.__str__ = lambda self: str(self.get())
# # do not overload the __repr__ operator (will show the true type)
# 2. Static implementation - workaround for bug #103318
for c in ['IDatabase','IFolder','IFolderSet','IObject','IObjectIterator','IObjectVector ','IRecord','IRecordVector','ITransaction']:
if hasattr(gbl,"std::shared_ptr<cool::"+c+">"):
cls = getattr(gbl,"std::shared_ptr<cool::"+c+">")
# use the conversion to string of the wrapped object.
cls.__str__ = lambda self: str(self.get())
# do not overload the __repr__ operator (will show the true type)
# Not necessary (ROOT-10349)
# ### std::shared_ptr
# def std_shared_ptr():
# """
# Instrument std::shared_ptr<T>.
# This function find all the classes starting with 'std::shared_ptr<'.
# The added function allows to emulate the 'smart pointer ' behaviour.
# """
# # 1. Dynamic implementation - but getAllClasses is no good (bug #103318)
# # add the new function to all std::shared_ptr<> classes
# #for c in getAllClasses():
# # if c.startswith("std::shared_ptr"):
# # cls = getattr(gbl,c)
# # # use the conversion to string of the wrapped object.
# # cls.__str__ = lambda self: str(self.get())
# # # do not overload the __repr__ operator (will show the true type)
# # 2. Static implementation - workaround for bug #103318
# for c in ['IDatabase','IFolder','IFolderSet','IObject','IObjectIterator','IObjectVector ','IRecord','IRecordVector','ITransaction']:
# if hasattr(gbl,"std::shared_ptr<cool::"+c+">"):
# cls = getattr(gbl,"std::shared_ptr<cool::"+c+">")
# # use the conversion to string of the wrapped object.
# cls.__str__ = lambda self: str(self.get())
# # do not overload the __repr__ operator (will show the true type)
########################################################################
### cool::Time
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment