1 """ Dynamic C++ bindings generator.
10 stat, output = commands.getstatusoutput(
"root-config --version")
19 if 'cppyy' in sys.builtin_module_names:
23 sys.modules[ __name__ ] = \
24 imp.load_module(
'cppyy', *(
None,
'cppyy', (
'',
'', imp.C_BUILTIN) ) )
27 _thismodule = sys.modules[ __name__ ]
28 _backend = _thismodule.gbl
32 return getattr( self, name )
33 type(_backend).CreateScopeProxy = _CreateScopeProxy
36 return getattr( self, name )
37 type(_backend).LookupCppEntity = _LookupCppEntity
40 type(_backend).Double = _Double
44 return array.array(
'L', [_thismodule.addressof( obj )] )
45 type(_backend).AddressOf = _AddressOf
47 del _AddressOf, _Double, _LookupCppEntity, _CreateScopeProxy
50 _builtin_cppyy =
False
53 needsGlobal = ( 0 <= sys.platform.find(
'linux' ) )
or\
54 ( 0 <= sys.platform.find(
'sunos' ) )
57 dlflags = sys.getdlopenflags()
58 sys.setdlopenflags( 0x100 | 0x2 )
60 import libPyROOT
as _backend
64 sys.setdlopenflags( dlflags )
68 sys.modules[ __name__ ].libPyROOT = _backend
70 if not _builtin_cppyy:
71 _backend.SetMemoryPolicy( _backend.kMemoryStrict )
74 try: _backend.gInterpreter.EnableAutoLoading()
102 """Create a base class with a metaclass."""
106 class metaclass(meta):
108 def __new__(cls, name, this_bases, d):
109 return meta(name, bases, d)
110 return type.__new__(metaclass,
'temporary_class', (), {})
115 if not _builtin_cppyy:
121 return "<cppyy.Template '%s' object at %s>" % (self.
__name__,
hex(
id(self)))
124 newargs = [ self.
__name__[ 0 <= self.__name__.find(
'std::' )
and 5
or 0:] ]
127 arg =
','.join( map(
lambda x: x.strip(), arg.split(
',') ) )
128 newargs.append( arg )
129 result = _backend.MakeRootTemplateClass( *newargs )
132 if 'push_back' in result.__dict__:
133 def iadd( self, ll ):
134 [ self.push_back(x)
for x
in ll ]
137 result.__iadd__ = iadd
141 _backend.Template = Template
147 if sys.platform !=
'win32' and name[:3] !=
'lib':
149 sc = _backend.gSystem.Load(name)
150 if sc == -1:
raise RuntimeError(
"Error Loading dictionary")
151 loadDict = loadDictionary
154 sc = _backend.gSystem.Load(name)
158 if not _builtin_cppyy:
162 attr = _backend.LookupCppEntity( name )
163 except TypeError
as e:
164 raise AttributeError(str(e))
165 if type(attr)
is _backend.PropertyProxy:
166 setattr( cls.__class__, name, attr )
167 return attr.__get__(cls)
168 setattr( cls, name, attr )
174 klass = _backend.CreateScopeProxy( name, cls )
175 except TypeError
as e:
176 raise AttributeError(str(e))
177 setattr( cls, name, klass )
182 stlclasses = (
'complex',
'pair', \
183 'deque',
'list',
'queue',
'stack',
'vector',
'map',
'multimap',
'set',
'multiset' )
185 for name
in stlclasses:
186 locals()[ name ] =
Template(
'std::%s' % name )
188 string = _backend.CreateScopeProxy(
'string' )
191 _global_cpp = _backend
197 return _backend.LookupCppEntity( name )
198 except AttributeError:
201 _backend.gInterpreter.Declare(
'namespace %s {}' % name )
202 return _backend.LookupCppEntity( name )
203 makeNamespace = Namespace
206 return _backend.CreateScopeProxy( name )
209 return _backend.AddressOf( obj )[0]
210 addressof = _backend.addressof
218 if c : classes.append( c )
223 """Add a smart pointer to the list of known smart pointer types.
225 _backend.AddSmartPtrType(typename)
229 sys.modules[
'cppyy.gbl'] = gbl
241 if name[0] !=
'_': setattr( _thismodule, name, eval(name) )
244 if not _builtin_cppyy:
245 bind_object = _backend.BindObject
248 import _pythonization
250 from _pythonization
import *
def with_metaclass
– metaclass helper from six ------------------------------------------—— – https://bitbucket.org/gutworth/six/src/8a545f4e906f6f479a6eb8837f31d03731597687/six.py?at=default#cl-800
def get_version
helper to get the version number from root-config
static char * Next()
Returns next class from sorted class table.