Class: EnumeratorMap

PD. EnumeratorMap

Extends the PD.Enumerator class to allow non-ordinal and/or non-sequential values.

This class takes a set of enum definition objects and creates matching properties that can be used to directly reference the ordinal index of each enumeration. Each enum definition object must contain as least a name, index and description field. It may also optionally include a key field which will be used as the property name instead of the enum name.

For example, { name: 'Door', index: 27, description: '...' } will create a new 'DOOR' property with a value of 27, whereas { key: 'TYPE1', name: 'Type 1', index: 41, description: '...' } will create a new TYPE1 property with a value of 41.

Non-Ordinal/Non-Sequential Values

In this class, the value assigned to each newly created property is the value given by the index field of the corresponding entry in the enumeration list. The enum definition objects are stored in a Map keyed by index value. Thus, access to the name and/or description of each item is via these map keys, which is a little slower than using direct array indices, but is still reasonably efficient when dealing with non-ordinal and/or non-sequential values.


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]}.

Author:
  • drajmarsh
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 className property with the name of the component class in the PD.Registry.

Parameters:
Name Type Description
type object

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 className property with the name of the component class in the PD.Registry.

Parameters:
Name Type Argument Description
types Array.<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
name string

The textual name of a enumeration.

default_value number <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.ParamType options 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.ParamType from 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
nameOrValue string | 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 name argument is a string, and then convert it to its associated enumeration index/value. If name is already a number, it is returned immediately.

This is typically used by UI methods where '