#####################################################################
from __future__ import print_function
+from six import add_metaclass
import six
if six.PY3:
long = int
class MetaParamValue(type):
def __new__(mcls, name, bases, dct):
cls = super(MetaParamValue, mcls).__new__(mcls, name, bases, dct)
- assert name not in allParams
+ if name in allParams:
+ warn("%s already exists in allParams. This may be caused by the " \
+ "Python 2.7 compatibility layer." % (name, ))
allParams[name] = cls
return cls
# Dummy base class to identify types that are legitimate for SimObject
# parameters.
+@add_metaclass(MetaParamValue)
class ParamValue(object):
- __metaclass__ = MetaParamValue
cmd_line_settable = False
# Generate the code needed as a prerequisite for declaring a C++
# that the value is a vector (list) of the specified type instead of a
# single value.
+@add_metaclass(MetaParamValue)
class VectorParamValue(list):
- __metaclass__ = MetaParamValue
def __setattr__(self, attr, value):
raise AttributeError("Not allowed to set %s on '%s'" % \
(attr, type(self).__name__))
# class is subclassed to generate parameter classes with specific
# bounds. Initialization of the min and max bounds is done in the
# metaclass CheckedIntType.__init__.
+@add_metaclass(CheckedIntType)
class CheckedInt(NumericParamValue):
- __metaclass__ = CheckedIntType
cmd_line_settable = True
def _check(self):
# Metaclass for Enum types
class MetaEnum(MetaParamValue):
def __new__(mcls, name, bases, dict):
- assert name not in allEnums
cls = super(MetaEnum, mcls).__new__(mcls, name, bases, dict)
allEnums[name] = cls
# Base class for enum types.
+@add_metaclass(MetaEnum)
class Enum(ParamValue):
- __metaclass__ = MetaEnum
vals = []
cmd_line_settable = True
return self.value
# This param will generate a scoped c++ enum and its python bindings.
+@add_metaclass(MetaEnum)
class ScopedEnum(Enum):
- __metaclass__ = MetaEnum
vals = []
cmd_line_settable = True
# make_param_value() above that lets these be assigned where a
# SimObject is required.
# only one copy of a particular node
+@add_metaclass(Singleton)
class NullSimObject(object):
- __metaclass__ = Singleton
_name = 'Null'
def __call__(cls):
# 'Fake' ParamDesc for Port references to assign to the _pdesc slot of
# proxy objects (via set_param_desc()) so that proxy error messages
# make sense.
+@add_metaclass(Singleton)
class PortParamDesc(object):
- __metaclass__ = Singleton
-
ptype_str = 'Port'
ptype = Port