Config: Add support for a Self.all proxy object
This commit is contained in:
parent
83f91db2cc
commit
9751a1d3e7
3 changed files with 30 additions and 1 deletions
|
@ -746,6 +746,21 @@ class SimObject(object):
|
||||||
found_obj = match_obj
|
found_obj = match_obj
|
||||||
return found_obj, found_obj != None
|
return found_obj, found_obj != None
|
||||||
|
|
||||||
|
def find_all(self, ptype):
|
||||||
|
all = {}
|
||||||
|
# search children
|
||||||
|
for child in self._children.itervalues():
|
||||||
|
if isinstance(child, ptype) and not isproxy(child) and \
|
||||||
|
not isNullPointer(child):
|
||||||
|
all[child] = True
|
||||||
|
# search param space
|
||||||
|
for pname,pdesc in self._params.iteritems():
|
||||||
|
if issubclass(pdesc.ptype, ptype):
|
||||||
|
match_obj = self._values[pname]
|
||||||
|
if not isproxy(match_obj) and not isNullPointer(match_obj):
|
||||||
|
all[match_obj] = True
|
||||||
|
return all.keys(), True
|
||||||
|
|
||||||
def unproxy(self, base):
|
def unproxy(self, base):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,10 @@ class VectorParamValue(list):
|
||||||
return [ v.getValue() for v in self ]
|
return [ v.getValue() for v in self ]
|
||||||
|
|
||||||
def unproxy(self, base):
|
def unproxy(self, base):
|
||||||
return [v.unproxy(base) for v in self]
|
if len(self) == 1 and isinstance(self[0], AllProxy):
|
||||||
|
return self[0].unproxy(base)
|
||||||
|
else:
|
||||||
|
return [v.unproxy(base) for v in self]
|
||||||
|
|
||||||
class SimObjectVector(VectorParamValue):
|
class SimObjectVector(VectorParamValue):
|
||||||
# support clone operation
|
# support clone operation
|
||||||
|
|
|
@ -184,6 +184,13 @@ class AnyProxy(BaseProxy):
|
||||||
def path(self):
|
def path(self):
|
||||||
return 'any'
|
return 'any'
|
||||||
|
|
||||||
|
class AllProxy(BaseProxy):
|
||||||
|
def find(self, obj):
|
||||||
|
return obj.find_all(self._pdesc.ptype)
|
||||||
|
|
||||||
|
def path(self):
|
||||||
|
return 'all'
|
||||||
|
|
||||||
def isproxy(obj):
|
def isproxy(obj):
|
||||||
if isinstance(obj, (BaseProxy, params.EthernetAddr)):
|
if isinstance(obj, (BaseProxy, params.EthernetAddr)):
|
||||||
return True
|
return True
|
||||||
|
@ -201,6 +208,10 @@ class ProxyFactory(object):
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if attr == 'any':
|
if attr == 'any':
|
||||||
return AnyProxy(self.search_self, self.search_up)
|
return AnyProxy(self.search_self, self.search_up)
|
||||||
|
elif attr == 'all':
|
||||||
|
if self.search_up:
|
||||||
|
assert("Parant.all is not supported")
|
||||||
|
return AllProxy(self.search_self, self.search_up)
|
||||||
else:
|
else:
|
||||||
return AttrProxy(self.search_self, self.search_up, attr)
|
return AttrProxy(self.search_self, self.search_up, attr)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue