Source code for pyasdm.enumerations.FieldCode

# ALMA - Atacama Large Millimeter Array
# (c) European Southern Observatory, 2002
# (c) Associated Universities Inc., 2002
# Copyright by ESO (in the framework of the ALMA collaboration),
# Copyright by AUI (in the framework of the ALMA collaboration),
# All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307  USA
#
# /////////////////////////////////////////////////////////////////
# // WARNING!  DO NOT MODIFY THIS FILE!                          //
# //  ---------------------------------------------------------  //
# // | This is generated code!  Do not modify this file.       | //
# // | Any changes will be lost when the file is re-generated. | //
# //  ---------------------------------------------------------  //
# /////////////////////////////////////////////////////////////////
#
# File FieldCode.py

# to keep track of the attributes added to this class for each value of this enumeration

_fieldCodeDict = {}

# the possible enumerations

_NONE = 0  #


# their names in a dictionary
_fieldCodeNames = {}

_fieldCodeNames[_NONE] = "NONE"


[docs]class FieldCode: """ A class for the FieldCode enumeration. """ # The value of this FieldCode, one of the possible enumerations. _value = None # its name _name = None def __init__(self, fieldCode): # construct a FieldCode from an integer, a string, or another FieldCode # if fieldCode is a string, convert it to an instance of this class using literal if isinstance(fieldCode, FieldCode): # copy constructor self._value = fieldCode.getValue() self._name = fieldCode.getName() elif isinstance(fieldCode, str): # convert it to an instance of this class using literal thisEnum = FieldCode.literal(fieldCode) self._value = thisEnum.getValue() self._name = thisEnum.getName() else: # it must be in the names dictionary if fieldCode not in _fieldCodeNames: raise ValueError("unrecognized FieldCode") self._value = fieldCode self._name = _fieldCodeNames[fieldCode] if self._name not in _fieldCodeDict: # add this FieldCode as an attribute to this class using its name setattr(FieldCode, self._name, self) _fieldCodeDict[self._name] = getattr(FieldCode, self._name)
[docs] def getValue(self): """ Return the integer value of this enumeration. """ return self._value
[docs] def getName(self): """ Return the name of this enumeration. """ return self._name
def __str__(self): """ Equivalent to getName() """ return self.getName() def __eq__(self, other): """ Returns True if other is a FieldCode and its value is the same as this one. """ return isinstance(other, FieldCode) and (other.getValue() == self.getValue()) def __ne__(self, other): """ Returns True if other is not equal to self """ return not (self == other) # by convention with the code in java and c++, these are all static methods
[docs] @staticmethod def revision(): """ revision as a string. """ return "-1"
[docs] @staticmethod def version(): """ the major version number as an int. """ return 1
[docs] @staticmethod def size(): """ the number of known enumerators in FieldCode """ return len(_fieldCodeNames)
[docs] @staticmethod def name(fieldCode): """ Returns the string form of fieldCode """ return str(fieldCode)
[docs] @staticmethod def names(): """ Return the list of all known FieldCode enumeration names """ return list(_fieldCodeNames.values())
[docs] @staticmethod def newFieldCode(name): """ Equivalent to the literal method """ return FieldCode.literal(name)
[docs] @staticmethod def literal(name): """ Return the FieldCode enumerator value given a string """ # it must be available as an attribute if not hasattr(FieldCode, name): raise ValueError("Unrecognized FieldCode name") return FieldCode(getattr(FieldCode, name).getValue())
[docs] @staticmethod def from_int(i): """ Return a FieldCode from an integration matching an enumeration. """ return FieldCode(i)
NONE = FieldCode(_NONE)