NameSpaceTable.ts 856 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { BiMap } from "@/util/bi-map";
  2. export class NamespaceTable {
  3. OPC_UA = "http://opcfoundation.org/UA/";
  4. nsMap = new BiMap<number, string>();
  5. constructor() {
  6. this.nsMap.set(0, this.OPC_UA)
  7. }
  8. addUri(uri: string):number|undefined {
  9. if(this.nsMap.hasValue(uri)) {
  10. return this.nsMap.getFromValue(uri);
  11. } else {
  12. let index=1;
  13. while (this.nsMap.hasKey(index)) {
  14. index = index + 1;
  15. }
  16. this.nsMap.set(index, uri);
  17. return index;
  18. }
  19. }
  20. putUri(uri: string, index: number): void {
  21. this.nsMap.set(index, uri);
  22. }
  23. getUri(index: number): string|undefined {
  24. return this.nsMap.get(index);
  25. }
  26. getIndex(uri: string) : number|undefined {
  27. return this.nsMap.getFromValue(uri);
  28. }
  29. }