GlobalFactory.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
18 
19 
20 import OpenRTM_aist
21 
22 
23 class Factory:
24 
25  FACTORY_OK = 0
26  FACTORY_ERROR = 1
27  ALREADY_EXISTS = 2
28  NOT_FOUND = 3
29  INVALID_ARG = 4
30  UNKNOWN_ERROR = 5
31 
32 
33  def __init__(self):
34  self._creators = {}
35 
36 
37  ## bool hasFactory(const Identifier& id)
38  def hasFactory(self, id):
39  if not self._creators.has_key(id):
40  return False
41  return True
42 
43 
44  ## std::vector<Identifier> getIdentifiers()
45  def getIdentifiers(self):
46  idlist = []
47 
48  for id in self._creators.keys():
49  idlist.append(id)
50  idlist.sort()
51  return idlist
52 
53 
54  ## ReturnCode addFactory(const Identifier& id,
55  ## Creator creator,
56  ## Destructor destructor)
57  def addFactory(self, id, creator, destructor):
58  if not creator:
59  return self.INVALID_ARG
60 
61  if self._creators.has_key(id):
62  return self.ALREADY_EXISTS
63 
64  self._creators[id] = creator
65  return self.FACTORY_OK
66 
67 
68  ## ReturnCode removeFactory(const Identifier& id)
69  def removeFactory(self, id):
70  if not self._creators.has_key(id):
71  return self.NOT_FOUND
72 
73  del self._creators[id]
74  return self.FACTORY_OK
75 
76 
77  ## AbstractClass* createObject(const Identifier& id)
78  def createObject(self, id):
79  if not self._creators.has_key(id):
80  print "Factory.createObject return None id: ", id
81  return None
82  return self._creators[id]()
83 
84 
85  ## void deleteObject(const Identifier& id, AbstractClass*& obj)
86  def deleteObject(self, obj, id=None):
87  if id:
88  if not self._creators.has_key(id):
89  return
90 
91  del obj
92  return
93 
94 
95 gfactory = None
96 
98  def __init__(self):
99  Factory.__init__(self)
100  pass
101 
102 
103  def instance():
104  global gfactory
105 
106  if gfactory is None:
107  gfactory = GlobalFactory()
108 
109  return gfactory
110 
111  instance = staticmethod(instance)
112 
113 
114  def __del__(self):
115  pass
def hasFactory(self, id)
bool hasFactory(const Identifier& id)
def deleteObject(self, obj, id=None)
void deleteObject(const Identifier& id, AbstractClass*& obj)
def createObject(self, id)
AbstractClass* createObject(const Identifier& id)
def removeFactory(self, id)
ReturnCode removeFactory(const Identifier& id)
def addFactory(self, id, creator, destructor)
ReturnCode addFactory(const Identifier& id, Creator creator, Destructor destructor) ...
def getIdentifiers(self)
std::vector<Identifier> getIdentifiers()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34