import { UANodeSet } from "./UANodeSet"; import { UABaseNode } from "./UABaseNode"; import { NamespaceTable } from "./NameSpaceTable"; import { type IAddressSpace, type IMappingValue } from "./IAddressSpace"; export class AddressSpace implements IAddressSpace{ nodeMap: Map; nst: NamespaceTable; nodesets: UANodeSet[]; mapping: Map; constructor(nodesets: UANodeSet[]) { this.nst=new NamespaceTable(); this.nodeMap=new Map(); this.nodesets=[]; this.mapping=new Map(); for(const nodeset of nodesets) { this.addNodeset(nodeset); } } getNodeSets(): UANodeSet[]{ return this.nodesets; } public findNode(nodeId: string):UABaseNode|undefined { return this.nodeMap.get(nodeId) } public getSubTreeAsList(nodeId: string): UABaseNode[] { const node=this.findNode(nodeId); if(!node) return []; const nlist:UABaseNode[]=[node]; for(const n of node.getChildren()) { const list=this.getSubTreeAsList(n.nodeId.toString()); nlist.push(...list); } return nlist; } public addNodeset(nodeset: UANodeSet) { nodeset.reIndex(this.nst); for(const node of nodeset.nodes) { this.nodeMap.set(node.nodeId.toString(), node); } nodeset.resolveReferences(this.nodeMap); this.nodesets.push(nodeset); } static async load(files: string[]) { const as=new AddressSpace([]); const promises:Promise[] = [] for(const file of files) { promises.push(UANodeSet.load(file, as)); } for(const p of promises) { as.addNodeset(await p); } return as; } }