TraceStudio-dev/web/src/core/model/PortModel.ts

28 lines
731 B
TypeScript
Raw Normal View History

2026-01-12 03:32:51 +08:00
export const typeDimMap = new Map<string, { type: string; dim: number }>()
export class PortModel {
name: string
type?: string
constructor(name:string, type?:string){
this.name = name
this.type = type
}
getTypeInfo(): {type: string; dim: number } {
const type = this.type
if (!type) return {type: '', dim: 0 }
const str = String(type).trim()
if (typeDimMap.has(str)) return typeDimMap.get(str)!
let dim = 0
let base = str
let match: RegExpMatchArray | null
const regex = /^(List|Array)\s*<(.+)>$/
while ((match = base.match(regex))) {
dim++
base = match[2].trim()
}
const result = {type: base, dim }
typeDimMap.set(str, result)
return result
}
}