BACnet.Protocol.BACnetArray (bacstack v0.0.1)

View Source

A BACnet Array is a structured datatype in ordered sequences. A BACnet Array consists of data elements each having the same datatype.

The components of a BACnet Array may be individually accessed for read and write, using an array index. An array index of zero specifies the size of the array. The index zero can not be directly written to using set_item/3, use truncate/1 instead.

When a BACnet Array has a fixed size, the array can not be resized and any attempts will fail to do so. The BACnet array of fixed size will contain elements with the default value, which will be returned upon call to to_list/1 or inside reduce_while/3.

Summary

Types

Implementation detail and thus private API. Changes to it do not count towards Semantic Versioning.

t()

Base type for the BACnet array.

Base type with subtype for the BACnet array.

Representative type for the BACnet array.

Functions

Fetch an item from the array.

Check whether the BACnet array has a fixed size.

Create a new BACnet array from the given index list.

Create a new BACnet array from the given list.

Get the default value for the BACnet array.

Get the item from the specified position.

Get the size of the array.

Creates a new array. When specifying a fixed size, the array can not grow or shrink.

Reduce the array items to an accumulator. See Enum.reduce_while/3.

Remove an item from the array. This function ignores positions greater than its capacity.

Inserts an item at the specified position into the array.

Get all items as a list.

Truncates the array to size zero.

Validates whether the given BACnet array is in form valid. A type can be given to be verified, so that each entry is either the default value or of that type (see Internal.check_type/2).

Types

items(subtype)

@opaque items(subtype)

Implementation detail and thus private API. Changes to it do not count towards Semantic Versioning.

t()

@type t() :: t(term())

Base type for the BACnet array.

t(subtype)

@type t(subtype) :: t(subtype, nil)

Base type with subtype for the BACnet array.

t(subtype, fixed_size)

@type t(subtype, fixed_size) :: %BACnet.Protocol.BACnetArray{
  fixed_size: fixed_size,
  items: items(subtype),
  size: non_neg_integer()
}

Representative type for the BACnet array.

The items get typed as subtype. fixed_size is either a number in the range of non_neg_integer or nil.

A fixed size array can not change its size.

Functions

fetch(array, position)

@spec fetch(t(subtype), non_neg_integer()) :: {:ok, subtype} | :error
when subtype: var

Fetch an item from the array.

This is implemented for the Access module.

fixed_size?(array)

@spec fixed_size?(t()) :: boolean()

Check whether the BACnet array has a fixed size.

from_indexed_list(collection, fixed_size \\ false, default_value \\ :undefined)

@spec from_indexed_list(Enumerable.t(subtype), boolean(), default) ::
  t(subtype | default) | no_return()
when default: term()

Create a new BACnet array from the given index list.

The indexed list is a list of {index, item}, where index is a positive integer. The indexes do not need to be consecutively or sequentially ordered. Note however that interleaved values leave the default value at the "holes", which you will get upon calling get_item/2. See also get_item/2.

The list will be iterated once to insert them into the array. Optionally the resulting array can have a fixed size (derived from the list length).

from_list(collection, fixed_size \\ false, default_value \\ :undefined)

@spec from_list(Enumerable.t(subtype), boolean(), default) ::
  t(subtype | default) | no_return()
when default: var

Create a new BACnet array from the given list.

Optionally the resulting array can have a fixed size (derived from the list length).

get_default(array)

@spec get_default(t()) :: term()

Get the default value for the BACnet array.

get_item(array, position)

@spec get_item(t(subtype), non_neg_integer()) :: {:ok, subtype} | :error
when subtype: var

Get the item from the specified position.

Arrays with interleaved values will typically use the default value, as such when getting interleave positions, you will get the default value. However :undefined is handled special and will return :error instead.

Position 0 conveniently returns the size (as specified by ASHRAE 135).

get_size(array)

@spec get_size(t()) :: non_neg_integer()

Get the size of the array.

new(fixed_size \\ nil, default_value \\ :undefined)

@spec new(non_neg_integer() | nil, term()) :: t()

Creates a new array. When specifying a fixed size, the array can not grow or shrink.

There's no distinction between an unset value (an empty position) or an explicitely set value to the default value.

reduce_while(array, accumulator, callback)

@spec reduce_while(
  t(subtype),
  term(),
  (item :: subtype, accumulator :: term() -> {:cont, term()} | {:halt, term()})
) :: term()

Reduce the array items to an accumulator. See Enum.reduce_while/3.

remove_item(array, position)

@spec remove_item(t(subtype), non_neg_integer()) ::
  {:ok, t(subtype)} | {:error, term()}

Remove an item from the array. This function ignores positions greater than its capacity.

Non-fixed size arrays get resized. Fixed size arrays will have the position reset to the default value.

set_item(array, position, item)

@spec set_item(t(subtype), non_neg_integer() | nil, subtype) ::
  {:ok, t(subtype)} | {:error, term()}
when subtype: var

Inserts an item at the specified position into the array.

Position nil can be used to append to the end of the array. Positions greater than the size of the array + 1 can not be used.

to_list(array)

@spec to_list(t(subtype)) :: [subtype] when subtype: var

Get all items as a list.

truncate(array)

@spec truncate(t(subtype)) :: t(subtype)

Truncates the array to size zero.

valid?(t, type \\ :any)

@spec valid?(t(), BACnet.Internal.typechecker_types()) :: boolean()

Validates whether the given BACnet array is in form valid. A type can be given to be verified, so that each entry is either the default value or of that type (see Internal.check_type/2).

If none or :any is given, no particular validation occurs.