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