UNPKG

@itwin/presentation-backend

Version:

Backend of iTwin.js Presentation library

144 lines 5.83 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Core */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RulesetVariablesManagerImpl = void 0; const presentation_common_1 = require("@itwin/presentation-common"); /** * Presentation ruleset variables registry implementation. * @internal */ class RulesetVariablesManagerImpl { _getNativePlatform; _rulesetId; constructor(getNativeAddon, rulesetId) { this._getNativePlatform = getNativeAddon; this._rulesetId = rulesetId; } setValueInternal(variableId, type, value) { this._getNativePlatform().setRulesetVariableValue(this._rulesetId, variableId, type, value); } getValueInternal(variableId, type) { return this._getNativePlatform().getRulesetVariableValue(this._rulesetId, variableId, type).result; } setValue(variableId, type, value) { switch (type) { case presentation_common_1.VariableValueTypes.Bool: return this.setBool(variableId, value); case presentation_common_1.VariableValueTypes.Id64: return this.setId64(variableId, value); case presentation_common_1.VariableValueTypes.Id64Array: return this.setId64s(variableId, value); case presentation_common_1.VariableValueTypes.Int: return this.setInt(variableId, value); case presentation_common_1.VariableValueTypes.IntArray: return this.setInts(variableId, value); case presentation_common_1.VariableValueTypes.String: return this.setString(variableId, value); } } unset(variableId) { this._getNativePlatform().unsetRulesetVariableValue(this._rulesetId, variableId); } getValue(variableId, type) { switch (type) { case presentation_common_1.VariableValueTypes.Bool: return this.getBool(variableId); case presentation_common_1.VariableValueTypes.Id64: return this.getId64(variableId); case presentation_common_1.VariableValueTypes.Id64Array: return this.getId64s(variableId); case presentation_common_1.VariableValueTypes.Int: return this.getInt(variableId); case presentation_common_1.VariableValueTypes.IntArray: return this.getInts(variableId); case presentation_common_1.VariableValueTypes.String: return this.getString(variableId); } } /** * Retrieves `string` variable value. * Returns empty string if variable does not exist or does not convert to string. */ getString(variableId) { return this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.String); } /** * Sets `string` variable value */ setString(variableId, value) { this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.String, value); } /** * Retrieves `boolean` variable value. * Returns `false` if variable does not exist or does not convert to boolean. */ getBool(variableId) { return this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Bool); } /** * Sets `boolean` variable value */ setBool(variableId, value) { this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Bool, value); } /** * Retrieves `number` variable value. * Returns `0` if variable does not exist or does not convert to integer. */ getInt(variableId) { return this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Int); } /** * Sets `number` variable value */ setInt(variableId, value) { this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Int, value); } /** * Retrieves `number[]` variable value. * Returns empty array if variable does not exist or does not convert to integer array. */ getInts(variableId) { return this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.IntArray); } /** * Sets `number[]` variable value */ setInts(variableId, value) { this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.IntArray, value); } /** * Retrieves `Id64String` variable value. * Returns invalid Id64String if variable does not exist or does not convert to Id64String. */ getId64(variableId) { return this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64); } /** * Sets `Id64String` variable value */ setId64(variableId, value) { this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64, value); } /** * Retrieves `Id64String[]` variable value. * Returns empty array if variable does not exist or does not convert to Id64String array. */ getId64s(variableId) { return this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64Array); } /** * Sets `Id64String[]` variable value */ setId64s(variableId, value) { this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64Array, value); } } exports.RulesetVariablesManagerImpl = RulesetVariablesManagerImpl; //# sourceMappingURL=RulesetVariablesManager.js.map