UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

116 lines (115 loc) 6.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IfcExpressionFunctions = void 0; const IfcExpressionUtils_js_1 = require("../../util/IfcExpressionUtils.js"); const MAP_js_1 = require("./impl/MAP.js"); const ROUND_js_1 = require("./impl/ROUND.js"); const AttributeAccessorFunction_js_1 = require("./impl/AttributeAccessorFunction.js"); const PROPERTYSET_js_1 = require("./impl/PROPERTYSET.js"); const PROPERTY_js_1 = require("./impl/PROPERTY.js"); const TYPE_js_1 = require("./impl/TYPE.js"); const FuncBooleanBinary_js_1 = require("./impl/FuncBooleanBinary.js"); const NOT_js_1 = require("./impl/NOT.js"); const CHOOSE_js_1 = require("./impl/CHOOSE.js"); const MatchesPattern_js_1 = require("./impl/MatchesPattern.js"); const Types_js_1 = require("../../type/Types.js"); const TOSTRING_js_1 = require("./impl/TOSTRING.js"); const EXISTS_js_1 = require("./impl/EXISTS.js"); const EQUALS_js_1 = require("./impl/EQUALS.js"); const CompareMagnitudes_js_1 = require("./impl/CompareMagnitudes.js"); const ReplacePattern_js_1 = require("./impl/ReplacePattern.js"); const IF_js_1 = require("./impl/IF.js"); const TONUMERIC_js_1 = require("./impl/TONUMERIC.js"); const IfcExpressionFunctionConfigException_js_1 = require("../../error/IfcExpressionFunctionConfigException.js"); const TOBOOLEAN_js_1 = require("./impl/TOBOOLEAN.js"); const TOLOGICAL_js_1 = require("./impl/TOLOGICAL.js"); const TOLOWERCASE_js_1 = require("./impl/TOLOWERCASE.js"); const TOUPPERCASE_js_1 = require("./impl/TOUPPERCASE.js"); const SUBSTRING_js_1 = require("./impl/SUBSTRING.js"); const SPLIT_js_1 = require("./impl/SPLIT.js"); const AT_js_1 = require("./impl/AT.js"); const TOIFCDATE_js_1 = require("./impl/TOIFCDATE.js"); const TOIFCDATETIME_js_1 = require("./impl/TOIFCDATETIME.js"); const TOIFCTIME_js_1 = require("./impl/TOIFCTIME.js"); const TOIFCDURATION_js_1 = require("./impl/TOIFCDURATION.js"); const TOIFCTIMESTAMP_js_1 = require("./impl/TOIFCTIMESTAMP.js"); const ADDDURATION_js_1 = require("./impl/ADDDURATION.js"); const builtinFunctions = new Map(); function registerOrDie(fnKey, func) { if (builtinFunctions.has(fnKey)) { throw new IfcExpressionFunctionConfigException_js_1.IfcExpressionFunctionConfigException(`cannot register function with name '${fnKey}': name already in use`); } builtinFunctions.set(fnKey, func); } function registerFunc(func, ...aliases) { const fnKey = func.getName(); const keys = [...aliases]; keys.unshift(fnKey); keys.forEach((key) => registerOrDie(IfcExpressionFunctions.normalizeName(key), func)); } class IfcExpressionFunctions { static normalizeName(name) { if ((0, IfcExpressionUtils_js_1.isNullish)(name)) { return undefined; } return name.toUpperCase(); } static isBuiltinFunction(name) { if ((0, IfcExpressionUtils_js_1.isNullish)(name)) { return false; } return builtinFunctions.has(this.normalizeName(name)); } static getFunction(name) { if ((0, IfcExpressionUtils_js_1.isNullish)(name)) { return undefined; } return builtinFunctions.get(this.normalizeName(name)); } } exports.IfcExpressionFunctions = IfcExpressionFunctions; registerFunc(new MAP_js_1.MAP()); registerFunc(new CHOOSE_js_1.CHOOSE()); registerFunc(new AT_js_1.AT()); registerFunc(new IF_js_1.IF()); registerFunc(new ROUND_js_1.ROUND()); registerFunc(new AttributeAccessorFunction_js_1.AttributeAccessorFunction("name", Types_js_1.Type.STRING)); registerFunc(new AttributeAccessorFunction_js_1.AttributeAccessorFunction("guid", Types_js_1.Type.STRING)); registerFunc(new AttributeAccessorFunction_js_1.AttributeAccessorFunction("ifcClass", Types_js_1.Type.STRING)); registerFunc(new AttributeAccessorFunction_js_1.AttributeAccessorFunction("description", Types_js_1.Type.STRING)); registerFunc(new AttributeAccessorFunction_js_1.AttributeAccessorFunction("value", Types_js_1.Types.or(Types_js_1.Type.STRING, Types_js_1.Type.NUMERIC, Types_js_1.Type.BOOLEAN, Types_js_1.Type.ARRAY))); registerFunc(new PROPERTYSET_js_1.PROPERTYSET()); registerFunc(new PROPERTY_js_1.PROPERTY()); registerFunc(new TYPE_js_1.TYPE()); registerFunc(new NOT_js_1.NOT()); registerFunc(new TOSTRING_js_1.TOSTRING()); registerFunc(new TONUMERIC_js_1.TONUMERIC(), "TONUMBER"); registerFunc(new TOBOOLEAN_js_1.TOBOOLEAN()); registerFunc(new TOLOGICAL_js_1.TOLOGICAL(), "NOTFOUNDASUNKNOWN"); registerFunc(new TOIFCDATE_js_1.TOIFCDATE()); registerFunc(new TOIFCTIME_js_1.TOIFCTIME()); registerFunc(new TOIFCDATETIME_js_1.TOIFCDATETIME()); registerFunc(new TOIFCDURATION_js_1.TOIFCDURATION()); registerFunc(new TOIFCTIMESTAMP_js_1.TOIFCTIMESTAMP()); registerFunc(new ADDDURATION_js_1.ADDDURATION()); registerFunc(new TOLOWERCASE_js_1.TOLOWERCASE()); registerFunc(new TOUPPERCASE_js_1.TOUPPERCASE()); registerFunc(new SUBSTRING_js_1.SUBSTRING()); registerFunc(new SPLIT_js_1.SPLIT()); registerFunc(new EXISTS_js_1.EXISTS()); registerFunc(new FuncBooleanBinary_js_1.FuncBooleanBinary("AND", "and")); registerFunc(new FuncBooleanBinary_js_1.FuncBooleanBinary("OR", "or")); registerFunc(new FuncBooleanBinary_js_1.FuncBooleanBinary("XOR", "xor")); registerFunc(new FuncBooleanBinary_js_1.FuncBooleanBinary("IMPLIES", "implies")); registerFunc(new EQUALS_js_1.EQUALS()); registerFunc(new CompareMagnitudes_js_1.CompareMagnitudes("GREATERTHAN", (cmp) => cmp > 0)); registerFunc(new CompareMagnitudes_js_1.CompareMagnitudes("GREATERTHANOREQUAL", (cmp) => cmp >= 0)); registerFunc(new CompareMagnitudes_js_1.CompareMagnitudes("LESSTHAN", (cmp) => cmp < 0)); registerFunc(new CompareMagnitudes_js_1.CompareMagnitudes("LESSTHANOREQUAL", (cmp) => cmp <= 0)); registerFunc(new MatchesPattern_js_1.MatchesPattern("CONTAINS", true, false)); registerFunc(new MatchesPattern_js_1.MatchesPattern("MATCHES", true, true)); registerFunc(new MatchesPattern_js_1.MatchesPattern("REGEXCONTAINS", false, false)); registerFunc(new MatchesPattern_js_1.MatchesPattern("REGEXMATCHES", false, true)); registerFunc(new ReplacePattern_js_1.ReplacePattern("REPLACE", true)); registerFunc(new ReplacePattern_js_1.ReplacePattern("REGEXREPLACE", false)); //# sourceMappingURL=IfcExpressionFunctions.js.map