params.py (6654:4c84e771cca7) params.py (6656:69714e675ee2)
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

--- 79 unchanged lines hidden (view full) ---

88
89 # allows us to blithely call unproxy() on things without checking
90 # if they're really proxies or not
91 def unproxy(self, base):
92 return self
93
94# Regular parameter description.
95class ParamDesc(object):
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

--- 79 unchanged lines hidden (view full) ---

88
89 # allows us to blithely call unproxy() on things without checking
90 # if they're really proxies or not
91 def unproxy(self, base):
92 return self
93
94# Regular parameter description.
95class ParamDesc(object):
96 file_ext = 'ptype'
97
96 def __init__(self, ptype_str, ptype, *args, **kwargs):
97 self.ptype_str = ptype_str
98 # remember ptype only if it is provided
99 if ptype != None:
100 self.ptype = ptype
101
102 if args:
103 if len(args) == 1:

--- 18 unchanged lines hidden (view full) ---

122 raise TypeError, 'extra unknown kwargs %s' % kwargs
123
124 if not hasattr(self, 'desc'):
125 raise TypeError, 'desc attribute missing'
126
127 def __getattr__(self, attr):
128 if attr == 'ptype':
129 ptype = SimObject.allClasses[self.ptype_str]
98 def __init__(self, ptype_str, ptype, *args, **kwargs):
99 self.ptype_str = ptype_str
100 # remember ptype only if it is provided
101 if ptype != None:
102 self.ptype = ptype
103
104 if args:
105 if len(args) == 1:

--- 18 unchanged lines hidden (view full) ---

124 raise TypeError, 'extra unknown kwargs %s' % kwargs
125
126 if not hasattr(self, 'desc'):
127 raise TypeError, 'desc attribute missing'
128
129 def __getattr__(self, attr):
130 if attr == 'ptype':
131 ptype = SimObject.allClasses[self.ptype_str]
130 assert issubclass(ptype, SimObject.SimObject)
132 assert isSimObjectClass(ptype)
131 self.ptype = ptype
132 return ptype
133
134 raise AttributeError, "'%s' object has no attribute '%s'" % \
135 (type(self).__name__, attr)
136
137 def convert(self, value):
138 if isinstance(value, proxy.BaseProxy):

--- 38 unchanged lines hidden (view full) ---

177 return [v.unproxy(base) for v in self]
178
179class SimObjVector(VectorParamValue):
180 def print_ini(self, ini_file):
181 for v in self:
182 v.print_ini(ini_file)
183
184class VectorParamDesc(ParamDesc):
133 self.ptype = ptype
134 return ptype
135
136 raise AttributeError, "'%s' object has no attribute '%s'" % \
137 (type(self).__name__, attr)
138
139 def convert(self, value):
140 if isinstance(value, proxy.BaseProxy):

--- 38 unchanged lines hidden (view full) ---

179 return [v.unproxy(base) for v in self]
180
181class SimObjVector(VectorParamValue):
182 def print_ini(self, ini_file):
183 for v in self:
184 v.print_ini(ini_file)
185
186class VectorParamDesc(ParamDesc):
187 file_ext = 'vptype'
188
185 # Convert assigned value to appropriate type. If the RHS is not a
186 # list or tuple, it generates a single-element list.
187 def convert(self, value):
188 if isinstance(value, (list, tuple)):
189 # list: coerce each element into new list
190 tmp_list = [ ParamDesc.convert(self, v) for v in value ]
191 else:
192 # singleton: coerce to a single-element list

--- 1001 unchanged lines hidden ---
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

--- 1001 unchanged lines hidden ---