packageDocumentation module import { Id64String } from "@itwin/core-bentley" ; import { VariableValue , VariableValueTypes } from "@itwin/presentation-common" ; import { NativePlatformDefinition } from "./NativePlatform" ; public export interface RulesetVariablesManager { /** Gets a value of the specified type and ID */ getValue ( variableId , type ) : VariableValue ; /** Sets a value of the specified type */ setValue ( variableId , type , value ) : void ; /** Unsets variable with given id. */ unset ( variableId ) : void ; /**
     * Retrieves `string` variable value.
     * Returns empty string if variable does not exist or does not convert to string.
     */ getString ( variableId ) : string ; /**
     * Sets `string` variable value
     */ setString ( variableId , value ) : void ; /**
     * Retrieves `boolean` variable value.
     * Returns `false` if variable does not exist or does not convert to boolean.
     */ getBool ( variableId ) : boolean ; /**
     * Sets `boolean` variable value
     */ setBool ( variableId , value ) : void ; /**
     * Retrieves `number` variable value.
     * Returns `0` if variable does not exist or does not convert to integer.
     */ getInt ( variableId ) : number ; /**
     * Sets `number` variable value
     */ setInt ( variableId , value ) : void ; /**
     * Retrieves `number[]` variable value.
     * Returns empty array if variable does not exist or does not convert to integer array.
     */ getInts ( variableId ) : number [ ] ; /**
     * Sets `number[]` variable value
     */ setInts ( variableId , value ) : void ; /**
     * Retrieves `Id64String` variable value.
     * Returns invalid Id64String if variable does not exist or does not convert to Id64String.
     */ getId64 ( variableId ) : Id64String ; /**
     * Sets `Id64String` variable value
     */ setId64 ( variableId , value ) : void ; /**
     * Retrieves `Id64String[]` variable value.
     * Returns empty array if variable does not exist or does not convert to Id64String array.
     */ getId64s ( variableId ) : Id64String [ ] ; /**
     * Sets `Id64String[]` variable value
     */ setId64s ( variableId , value ) : void ; } internal export class RulesetVariablesManagerImpl implements RulesetVariablesManager { private _getNativePlatform : ( ) => NativePlatformDefinition ; private _rulesetId : string ; constructor ( getNativeAddon , rulesetId ) { this . _getNativePlatform = getNativeAddon ; this . _rulesetId = rulesetId ; } public setValueInternal ( variableId , type , value ) { this . _getNativePlatform ( ) . setRulesetVariableValue ( this . _rulesetId , variableId , type , value ) ; } public getValueInternal ( variableId , type ) { return this . _getNativePlatform ( ) . getRulesetVariableValue ( this . _rulesetId , variableId , type ) . result ; } public setValue ( variableId , type , value ) { switch ( type ) { case VariableValueTypes . Bool : return this . setBool ( variableId , value as boolean ) ; case VariableValueTypes . Id64 : return this . setId64 ( variableId , value as Id64String ) ; case VariableValueTypes . Id64Array : return this . setId64s ( variableId , value as Id64String [ ] ) ; case VariableValueTypes . Int : return this . setInt ( variableId , value as number ) ; case VariableValueTypes . IntArray : return this . setInts ( variableId , value as number [ ] ) ; case VariableValueTypes . String : return this . setString ( variableId , value as string ) ; } } public unset ( variableId ) { this . _getNativePlatform ( ) . unsetRulesetVariableValue ( this . _rulesetId , variableId ) ; } public getValue ( variableId , type ) { switch ( type ) { case VariableValueTypes . Bool : return this . getBool ( variableId ) ; case VariableValueTypes . Id64 : return this . getId64 ( variableId ) ; case VariableValueTypes . Id64Array : return this . getId64s ( variableId ) ; case VariableValueTypes . Int : return this . getInt ( variableId ) ; case VariableValueTypes . IntArray : return this . getInts ( variableId ) ; case VariableValueTypes . String : return this . getString ( variableId ) ; } } /**
     * Retrieves `string` variable value.
     * Returns empty string if variable does not exist or does not convert to string.
     */ public getString ( variableId ) { return ( this . getValueInternal ( variableId , VariableValueTypes . String ) ) as string ; } /**
     * Sets `string` variable value
     */ public setString ( variableId , value ) { this . setValueInternal ( variableId , VariableValueTypes . String , value ) ; } /**
     * Retrieves `boolean` variable value.
     * Returns `false` if variable does not exist or does not convert to boolean.
     */ public getBool ( variableId ) { return ( this . getValueInternal ( variableId , VariableValueTypes . Bool ) ) as boolean ; } /**
     * Sets `boolean` variable value
     */ public setBool ( variableId , value ) { this . setValueInternal ( variableId , VariableValueTypes . Bool , value ) ; } /**
     * Retrieves `number` variable value.
     * Returns `0` if variable does not exist or does not convert to integer.
     */ public getInt ( variableId ) { return ( this . getValueInternal ( variableId , VariableValueTypes . Int ) ) as number ; } /**
     * Sets `number` variable value
     */ public setInt ( variableId , value ) { this . setValueInternal ( variableId , VariableValueTypes . Int , value ) ; } /**
     * Retrieves `number[]` variable value.
     * Returns empty array if variable does not exist or does not convert to integer array.
     */ public getInts ( variableId ) { return ( this . getValueInternal ( variableId , VariableValueTypes . IntArray ) ) as number [ ] ; } /**
     * Sets `number[]` variable value
     */ public setInts ( variableId , value ) { this . setValueInternal ( variableId , VariableValueTypes . IntArray , value ) ; } /**
     * Retrieves `Id64String` variable value.
     * Returns invalid Id64String if variable does not exist or does not convert to Id64String.
     */ public getId64 ( variableId ) { return ( this . getValueInternal ( variableId , VariableValueTypes . Id64 ) ) as Id64String ; } /**
     * Sets `Id64String` variable value
     */ public setId64 ( variableId , value ) { this . setValueInternal ( variableId , VariableValueTypes . Id64 , value ) ; } /**
     * Retrieves `Id64String[]` variable value.
     * Returns empty array if variable does not exist or does not convert to Id64String array.
     */ public getId64s ( variableId ) { return ( this . getValueInternal ( variableId , VariableValueTypes . Id64Array ) ) as Id64String [ ] ; } /**
     * Sets `Id64String[]` variable value
     */ public setId64s ( variableId , value ) { this . setValueInternal ( variableId , VariableValueTypes . Id64Array , value ) ; } }