Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic-graph-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guilhem Saurel
dynamic-graph-python
Commits
e7fe252b
Commit
e7fe252b
authored
14 years ago
by
Nicolas Mansard
Committed by
Nicolas Mansard
14 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added a proper factory for pyEntities.
parent
5bee2872
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dynamic_graph/entity.py
+28
-15
28 additions, 15 deletions
src/dynamic_graph/entity.py
with
28 additions
and
15 deletions
src/dynamic_graph/entity.py
+
28
−
15
View file @
e7fe252b
...
...
@@ -31,25 +31,38 @@ def initEntity(self, name):
setattr
(
self
.
__class__
,
command
,
commandMethod
(
command
,
docstring
))
self
.
__class__
.
commandCreated
=
True
class
PyEntityFactoryClass
(
type
):
"""
The class build dynamically a new class type, and return the reference
on the class-type object. The class type is not added to any context.
"""
def
__new__
(
factory
,
className
):
EntityClass
=
type
.
__new__
(
factory
,
className
,
(
Entity
,),
{})
EntityClass
.
className
=
className
EntityClass
.
__init__
=
initEntity
EntityClass
.
commandCreated
=
False
return
EntityClass
def
PyEntityFactory
(
className
,
context
):
"""
Build a new class type by calling the factory, and add it
to the given context.
"""
EntityClass
=
PyEntityFactoryClass
(
className
)
context
[
className
]
=
EntityClass
return
EntityClass
def
updateEntityClasses
(
dictionary
):
"""
For all c++entity types that are not in the pyentity class list (entityClassNameList)
run the factory and store the new type in the given context (dictionary).
"""
cxx_entityList
=
wrap
.
factory_get_entity_class_list
()
for
e
in
filter
(
lambda
x
:
not
x
in
entityClassNameList
,
cxx_entityList
):
class
metacls
(
type
):
def
__new__
(
mcs
,
name
,
bases
,
dict
):
return
type
.
__new__
(
mcs
,
name
,
bases
,
dict
)
# Create new class
a
=
metacls
(
e
,
(
Entity
,),
{})
# Store class name in class member
a
.
className
=
e
# set class constructor
setattr
(
a
,
'
__init__
'
,
initEntity
)
# set class attribute to store whether command methods have been created
setattr
(
a
,
'
commandCreated
'
,
False
)
#
# Store new class in dictionary with class name
dictionary
[
e
]
=
a
PyEntityFactory
(
e
,
dictionary
)
# Store class name in local list
entityClassNameList
.
append
(
e
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment