Source code

Revision control

Copy as Markdown

Other Tools

// generated by diplomat-tool
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";
/**
* Mode used in a rounding operation for signed numbers.
*
* See the [Rust documentation for `SignedRoundingMode`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignedRoundingMode.html) for more information.
*/
export class DecimalSignedRoundingMode {
#value = undefined;
static #values = new Map([
["Expand", 0],
["Trunc", 1],
["HalfExpand", 2],
["HalfTrunc", 3],
["HalfEven", 4],
["Ceil", 5],
["Floor", 6],
["HalfCeil", 7],
["HalfFloor", 8]
]);
static getAllEntries() {
return DecimalSignedRoundingMode.#values.entries();
}
#internalConstructor(value) {
if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
// We pass in two internalConstructor arguments to create *new*
// instances of this type, otherwise the enums are treated as singletons.
if (arguments[1] === diplomatRuntime.internalConstructor ) {
this.#value = arguments[2];
return this;
}
return DecimalSignedRoundingMode.#objectValues[arguments[1]];
}
if (value instanceof DecimalSignedRoundingMode) {
return value;
}
let intVal = DecimalSignedRoundingMode.#values.get(value);
// Nullish check, checks for null or undefined
if (intVal != null) {
return DecimalSignedRoundingMode.#objectValues[intVal];
}
throw TypeError(value + " is not a DecimalSignedRoundingMode and does not correspond to any of its enumerator values.");
}
static fromValue(value) {
return new DecimalSignedRoundingMode(value);
}
get value(){
return [...DecimalSignedRoundingMode.#values.keys()][this.#value];
}
get ffiValue(){
return this.#value;
}
static #objectValues = [
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
];
static Expand = DecimalSignedRoundingMode.#objectValues[0];
static Trunc = DecimalSignedRoundingMode.#objectValues[1];
static HalfExpand = DecimalSignedRoundingMode.#objectValues[2];
static HalfTrunc = DecimalSignedRoundingMode.#objectValues[3];
static HalfEven = DecimalSignedRoundingMode.#objectValues[4];
static Ceil = DecimalSignedRoundingMode.#objectValues[5];
static Floor = DecimalSignedRoundingMode.#objectValues[6];
static HalfCeil = DecimalSignedRoundingMode.#objectValues[7];
static HalfFloor = DecimalSignedRoundingMode.#objectValues[8];
constructor(value) {
return this.#internalConstructor(...arguments)
}
}