new_valueset

CValueSet Class Description


The CValueSet class manages a collection (or set) of keyed values. Each set member consists of a string key and a value that may one of the following types: "number", "integer", "string", or "boolean" true/false. All values in the set have the same type. The values may be retrieved using key (a string) or by their index in the collection. Thus, each value must have a unique key. Note that the object can also be created using new_valueset.

For example, here is a CValueSet object with 3 members that are a string key and number value:

(member 1):

{ "measurement 1", 0.2564 }

(member 3):

{ "measurement 2", -278.223 }

(member 4):

{ "measurement 3", 45.8 }

These (key, value) pairs may be explicitly defined as a 2 element table for each member:

member = {}

-- create a master table, "member"

 

member[1] = {}

-- create a table for key-value pairs

 

member[1][1] = "measurement 1" ; member[1][2] = 0.2564

-- assign member[1] as a key-value pair

 

member[2] = {}

-- create a table for key-value pairs

 

member[2][1] = "measurement 2" ; member[2][2] = -278.223

-- assign member[2] as a key-value pair

member[3] = {}

-- create a table for key-value pairs

 

member[3][1] = "measurement 3" ; member[3][2] = 45.8

-- assign member[3] as a key-value pair

Here is a CValueSet object with 3 members that uses string values:

(member 1):

{ "Name 1", "Markus" }

(member 2):

{ "Name 2", "Rachel" }

(member 3):

{ "Name 3", "Cameron" }

Usage

Construction

Object = new_valueset()

Object = CValueSet:new()

Destruction

Object:delete()

Creation - Non-class Functions

This function is normally used to create a new CValueSet object as an alternative to the class-based new method.

new_valueset

Global function that creates a new CValueSet object.

Construction and Destruction - Class Methods

new

Creates a new instance of the CValueSet class

delete

Deletes the instance of the CValueSet object.

Operations

Add

Adds a (string key, value) pair at the end of the set.

Copy

Copies another CValueSet or a 1-dimensional array with values that are numbers. of keyed values to this CValueSet

Count

Returns the number of members in the set.

Empty

Removes all set members

Get

Returns the value for the specified key.

GetAt

Returns both the key and value at the specified index.

GetKeyAt

Returns the key at the specified index.

GetType

Returns the value type as "number", "integer", "string", or "boolean".

GetValueAt

Returns the value at the specified index.

InsertAt

Inserts a (string key, value) pair at the specified set index.

List

Lists the set contents of the CValueSet in a Mira Text window.

RemoveAt

Removes the (string key, value) pair at the specified set index.

Remove

Removes the (string key, value) pair by matching its key.

Set

Sets the value at the specified (existing) key.

SetAt

Sets the value at the specified (existing) index.

SetType

Sets the value type for the CValueSet. This empties the set so that new values can be added with the new value type.

Sort

Sorts the set into ascending order according to its values.

SortKey

Sorts the set into ascending order according to its keys.

ToTable

Creates a lua table of (string key, value) pairs.

Related Topics

Table and Array Functions

CSet class

 


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.