new EnumeratorMap( [name] [, types])
Creates a new Map-based enumeration type.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
name |
string |
<optional> |
A unique name for this enumerator, typically the class name in all capitals. |
types |
Array.<object> |
<optional> |
An array of objects of the form {name, index, description[, key]}. |
Example
BIM.SENSOR = new PD.EnumeratorMap('BIM.SENSOR', [
{ key: 'UNKNOWN', index: 0, name: 'Unknown', description: 'Defines an unknown sensor type.' },
{ key: 'CO2', index: 1, name: 'CO2', description: 'Measures the concentration of carbon dioxide (CO2) gas in the air.' },
{ key: 'FIRE', index: 2, name: 'Fire', description: 'Senses the presence of fire and/or flame.' },
{ key: 'GAS', index: 4, name: 'Gas', description: 'Senses the presence of gas in the air.' },
{ key: 'HEAT', index: 8, name: 'Heat', description: 'Senses the presence of excessive heat.' },
{ key: 'HUMIDITY', index: 16, name: 'Humidity', description: 'Measures the percentage of humidity in the air.' },
{ key: 'LIGHT', index: 32, name: 'Light', description: 'Senses the amount of light striking the sensor.' },
{ key: 'MOVEMENT', index: 64, name: 'Movement', description: 'Senses movement within a prescribed area in front of the sensor.' },
{ key: 'PRESSURE', index: 128, name: 'Pressure', description: 'Measures air pressure.' },
{ key: 'SMOKE', index: 256, name: 'Smoke', description: 'Senses the presence of smoke in the air.' },
{ key: 'SOUND', index: 512, name: 'Sound', description: 'Measures sound levels around the sensor.' },
{ key: 'TEMPERATURE', index: 1024, name: 'Temperature', description: 'Measures air and/or globe temperature.' },
{ key: 'CUSTOM', index: 32768, name: 'Custom', description: 'A user-defined custom sensor.' }
]);
Extends
Members
-
:string
name
-
The unique name of this enumerator, typically the class name in all uppercase.
Type
- string
- Inherited From:
- Overrides:
Methods
-
addNewType(type)
-
Adds a new enumeration value to the list.
Each entry in the array should be an object of the form {name, description[, key]}. For enumerations of component types, each entry may also contain a
classNameproperty with the name of the component class in thePD.Registry.Parameters:
Name Type Description typeobject An object of the form {name, description[, key, className, etc]}.
- Inherited From:
- Overrides:
Throws:
-
Throws an error if the type key already exists.
- Type
- Error
Returns:
Returns the number of new enumerations added.
- Type
- number
Example
AJM.MY_TYPE.addNewType( { key: 'TYPE4', name: 'Type 4', description: 'This is the fourth subtype' } ); -
addNewTypes( [types])
-
Adds an array of new enumeration to the list.
Each entry in the array should be an object of the form {name, description[, key]}. For enumerations of component types, each entry may also contain a
classNameproperty with the name of the component class in thePD.Registry.Parameters:
Name Type Argument Description typesArray.<object> <optional>
An array of sub-type definitions.
- Inherited From:
- Overrides:
Returns:
Returns the number of new types added.
- Type
- number
Example
AJM.MY_TYPE.addNewTypes([ { key: 'TYPE4', name: 'Type 4', index: 763, className: 'AJM.MyTypes.Type4', description: 'This is the fourth subtype' }, { key: 'TYPE5', name: 'Type 5', index: 367, className: 'AJM.MyTypes.Type5', description: 'This is the fifth subtype' }, { key: 'TYPE6', name: 'Type 6', index: 637, className: 'AJM.MyTypes.Type6', description: 'This is the sixth subtype' } ]); -
fromString(name [, default_value])
-
Converts an enumeration name string to an ordinal enumeration index/value.
Parameters:
Name Type Argument Description namestring The textual name of a enumeration.
default_valuenumber <optional>
An optional index/value to use if the name is unmatched.
- Inherited From:
- Overrides:
Returns:
Returns the ordinal enumeration index/value of the given name.
- Type
- number
-
getAsOptionList()
-
Retrieve enumerators as an array of {name, value} objects compatible with a
PD.ParamTypeoptions list.- Inherited From:
- Overrides:
Returns:
Returns a formatted {name, value} options list.
- Type
- Array
-
getMaxTypeIndex()
-
Retrieve the maximum allowable index value for this enumerator.
Unlike array-based enumerators that store index values, map-based enumerators can store any numeric value, so the maximum is essentially the system's largest safe integer.
- Inherited From:
- Overrides:
Returns:
Returns the maximum type value.
- Type
- number
-
getParamType()
-
Retrieve a selectable enumerator list as a
PD.ParamTypefrom global cache.- Inherited From:
- Overrides:
Returns:
Returns a cached selectable parameter type.
- Type
- PD.ParamType
-
getType(nameOrValue)
-
Retrieve the type definition with the given value/name.
Parameters:
Name Type Description nameOrValuestring | number A string or integer index/value.
- Inherited From:
- Overrides:
Returns:
Returns a type definition if found, or null.
- Type
- object | null
-
getValue(nameOrValue)
-
Returns the numeric integer index/value from the given string or number.
The aim of this method is to check if the
nameargument is a string, and then convert it to its associated enumeration index/value. Ifnameis already a number, it is returned immediately.This is typically used by UI methods where '
Parameters:
Name Type Description nameOrValuestring | number A string or integer index/value.
- Inherited From:
- Overrides:
Returns:
Returns a numeric index/value.
- Type
- number
-
hasType(nameOrValue)
-
Retrieves whether or not there is a type definition for the given value/name.
Parameters:
Name Type Description nameOrValuestring | number A string or integer index/value.
- Inherited From:
- Overrides:
Returns:
Returns true if a definition was found.
- Type
- boolean
-
toString(index)
-
Converts an ordinal type index to a type name string.
Parameters:
Name Type Description indexnumber The numeric type enumerator index.
- Inherited From:
- Overrides:
Returns:
Returns the textual name.
- Type
- string