config.py (2711:2cbc3999ec58) config.py (2712:aa0891b4a110)
1# Copyright (c) 2004-2005 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

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

206 def __init__(cls, name, bases, dict):
207 # calls type.__init__()... I think that's a no-op, but leave
208 # it here just in case it's not.
209 super(MetaSimObject, cls).__init__(name, bases, dict)
210
211 # initialize required attributes
212 cls._params = multidict()
213 cls._values = multidict()
1# Copyright (c) 2004-2005 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

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

206 def __init__(cls, name, bases, dict):
207 # calls type.__init__()... I think that's a no-op, but leave
208 # it here just in case it's not.
209 super(MetaSimObject, cls).__init__(name, bases, dict)
210
211 # initialize required attributes
212 cls._params = multidict()
213 cls._values = multidict()
214 cls._instantiated = False # really instantiated or subclassed
214 cls._anon_subclass_counter = 0
215
216 # We don't support multiple inheritance. If you want to, you
217 # must fix multidict to deal with it properly.
218 if len(bases) > 1:
219 raise TypeError, "SimObjects do not support multiple inheritance"
220
221 base = bases[0]
222
223 # the only time the following is not true is when we define
224 # the SimObject class itself
225 if isinstance(base, MetaSimObject):
226 cls._params.parent = base._params
227 cls._values.parent = base._values
215 cls._anon_subclass_counter = 0
216
217 # We don't support multiple inheritance. If you want to, you
218 # must fix multidict to deal with it properly.
219 if len(bases) > 1:
220 raise TypeError, "SimObjects do not support multiple inheritance"
221
222 base = bases[0]
223
224 # the only time the following is not true is when we define
225 # the SimObject class itself
226 if isinstance(base, MetaSimObject):
227 cls._params.parent = base._params
228 cls._values.parent = base._values
229 base._instantiated = True
228
229 # now process the _init_dict items
230 for key,val in cls._init_dict.items():
231 if isinstance(val, (types.FunctionType, types.TypeType)):
232 type.__setattr__(cls, key, val)
233
234 # param descriptions
235 elif isinstance(val, ParamDesc):

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

294 if cls.keywords.has_key(attr):
295 cls._set_keyword(attr, value, cls.keywords[attr])
296 return
297
298 # must be SimObject param
299 param = cls._params.get(attr, None)
300 if param:
301 # It's ok: set attribute by delegating to 'object' class.
230
231 # now process the _init_dict items
232 for key,val in cls._init_dict.items():
233 if isinstance(val, (types.FunctionType, types.TypeType)):
234 type.__setattr__(cls, key, val)
235
236 # param descriptions
237 elif isinstance(val, ParamDesc):

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

296 if cls.keywords.has_key(attr):
297 cls._set_keyword(attr, value, cls.keywords[attr])
298 return
299
300 # must be SimObject param
301 param = cls._params.get(attr, None)
302 if param:
303 # It's ok: set attribute by delegating to 'object' class.
304 if (isSimObject(value) or isSimObjSequence(value)) \
305 and cls._instantiated:
306 raise AttributeError, \
307 "Cannot set SimObject parameter '%s' after\n" \
308 " class %s has been instantiated or subclassed" \
309 % (attr, cls.__name__)
302 try:
303 cls._values[attr] = param.convert(value)
304 except Exception, e:
305 msg = "%s\nError setting param %s.%s to %s\n" % \
306 (e, cls.__name__, attr, value)
307 e.args = (msg, )
308 raise
309 # I would love to get rid of this

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

381 # no pre-existing object, so remember this one here
382 _memo[self.__class__] = self
383 else:
384 # This is a new top-level instantiation... don't memoize
385 # this objcet, but prepare to memoize any recursively
386 # instantiated objects.
387 _memo = {}
388
310 try:
311 cls._values[attr] = param.convert(value)
312 except Exception, e:
313 msg = "%s\nError setting param %s.%s to %s\n" % \
314 (e, cls.__name__, attr, value)
315 e.args = (msg, )
316 raise
317 # I would love to get rid of this

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

389 # no pre-existing object, so remember this one here
390 _memo[self.__class__] = self
391 else:
392 # This is a new top-level instantiation... don't memoize
393 # this objcet, but prepare to memoize any recursively
394 # instantiated objects.
395 _memo = {}
396
397 self.__class__._instantiated = True
398
389 self._children = {}
390 # Inherit parameter values from class using multidict so
391 # individual value settings can be overridden.
392 self._values = multidict(self.__class__._values)
393 # For SimObject-valued parameters, the class should have
394 # classes (not instances) for the values. We need to
395 # instantiate these classes rather than just inheriting the
396 # class object.

--- 1019 unchanged lines hidden ---
399 self._children = {}
400 # Inherit parameter values from class using multidict so
401 # individual value settings can be overridden.
402 self._values = multidict(self.__class__._values)
403 # For SimObject-valued parameters, the class should have
404 # classes (not instances) for the values. We need to
405 # instantiate these classes rather than just inheriting the
406 # class object.

--- 1019 unchanged lines hidden ---