params.py (7526:4bb5f5207617) | params.py (7528:6efc3672733b) |
---|---|
1# Copyright (c) 2004-2006 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 35 unchanged lines hidden (view full) --- 44# 45##################################################################### 46 47import copy 48import datetime 49import re 50import sys 51import time | 1# Copyright (c) 2004-2006 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 35 unchanged lines hidden (view full) --- 44# 45##################################################################### 46 47import copy 48import datetime 49import re 50import sys 51import time |
52import math |
|
52 53import proxy 54import ticks 55from util import * 56 57def isSimObject(*args, **kwargs): 58 return SimObject.isSimObject(*args, **kwargs) 59 --- 113 unchanged lines hidden (view full) --- 173 return ' '.join([v.ini_str() for v in self]) 174 175 def getValue(self): 176 return [ v.getValue() for v in self ] 177 178 def unproxy(self, base): 179 return [v.unproxy(base) for v in self] 180 | 53 54import proxy 55import ticks 56from util import * 57 58def isSimObject(*args, **kwargs): 59 return SimObject.isSimObject(*args, **kwargs) 60 --- 113 unchanged lines hidden (view full) --- 174 return ' '.join([v.ini_str() for v in self]) 175 176 def getValue(self): 177 return [ v.getValue() for v in self ] 178 179 def unproxy(self, base): 180 return [v.unproxy(base) for v in self] 181 |
181class SimObjVector(VectorParamValue): 182 def print_ini(self, ini_file): | 182class SimObjectVector(VectorParamValue): 183 # support clone operation 184 def __call__(self, **kwargs): 185 return SimObjectVector([v(**kwargs) for v in self]) 186 187 def clear_parent(self, old_parent): |
183 for v in self: | 188 for v in self: |
184 v.print_ini(ini_file) | 189 v.clear_parent(old_parent) |
185 | 190 |
191 def set_parent(self, parent, name): 192 if len(self) == 1: 193 self[0].set_parent(parent, name) 194 else: 195 width = int(math.ceil(math.log(len(self))/math.log(10))) 196 for i,v in enumerate(self): 197 v.set_parent(parent, "%s%0*d" % (name, width, i)) 198 199 def get_parent(self): 200 parent_set = set(v._parent for v in self) 201 if len(parent_set) != 1: 202 raise RuntimeError, \ 203 "SimObjectVector elements have inconsistent parent value." 204 return parent_set.pop() 205 206 # return 'cpu0 cpu1' etc. for print_ini() 207 def get_name(self): 208 return ' '.join([v._name for v in self]) 209 210 # By iterating through the constituent members of the vector here 211 # we can nicely handle iterating over all a SimObject's children 212 # without having to provide lots of special functions on 213 # SimObjectVector directly. 214 def descendants(self): 215 for v in self: 216 for obj in v.descendants(): 217 yield obj 218 |
|
186class VectorParamDesc(ParamDesc): 187 file_ext = 'vptype' 188 189 # Convert assigned value to appropriate type. If the RHS is not a 190 # list or tuple, it generates a single-element list. 191 def convert(self, value): 192 if isinstance(value, (list, tuple)): 193 # list: coerce each element into new list 194 tmp_list = [ ParamDesc.convert(self, v) for v in value ] 195 else: 196 # singleton: coerce to a single-element list 197 tmp_list = [ ParamDesc.convert(self, value) ] 198 199 if isSimObjectSequence(tmp_list): | 219class VectorParamDesc(ParamDesc): 220 file_ext = 'vptype' 221 222 # Convert assigned value to appropriate type. If the RHS is not a 223 # list or tuple, it generates a single-element list. 224 def convert(self, value): 225 if isinstance(value, (list, tuple)): 226 # list: coerce each element into new list 227 tmp_list = [ ParamDesc.convert(self, v) for v in value ] 228 else: 229 # singleton: coerce to a single-element list 230 tmp_list = [ ParamDesc.convert(self, value) ] 231 232 if isSimObjectSequence(tmp_list): |
200 return SimObjVector(tmp_list) | 233 return SimObjectVector(tmp_list) |
201 else: 202 return VectorParamValue(tmp_list) 203 204 def swig_predecls(self): 205 return ['%%include "%s_vptype.i"' % self.ptype_str] 206 207 def swig_decl(self): 208 cxx_type = re.sub('std::', '', self.ptype.cxx_type) --- 995 unchanged lines hidden --- | 234 else: 235 return VectorParamValue(tmp_list) 236 237 def swig_predecls(self): 238 return ['%%include "%s_vptype.i"' % self.ptype_str] 239 240 def swig_decl(self): 241 cxx_type = re.sub('std::', '', self.ptype.cxx_type) --- 995 unchanged lines hidden --- |