modelRT/diagram/component_set.go

38 lines
1.3 KiB
Go

// Package diagram provide diagram data structure and operation
package diagram
import (
"fmt"
"modelRT/orm"
"modelRT/util"
)
// diagramsOverview define struct of storage all circuit diagram data keyed by component uuid
var diagramsOverview util.TypedMap[string, *orm.Component]
// GetComponentMap define func of get circuit diagram data by component uuid
func GetComponentMap(componentUUID string) (*orm.Component, error) {
componentInfo, ok := diagramsOverview.Load(componentUUID)
if !ok {
return nil, fmt.Errorf("can not find graph by global uuid:%s", componentUUID)
}
return componentInfo, nil
}
// UpdateComponentMap define func of update circuit diagram data by component uuid and component info
func UpdateComponentMap(componentUUID string, componentInfo *orm.Component) bool {
_, result := diagramsOverview.Swap(componentUUID, componentInfo)
return result
}
// StoreComponentMap define func of store circuit diagram data with component uuid and component info
func StoreComponentMap(componentUUID string, componentInfo *orm.Component) {
diagramsOverview.Store(componentUUID, componentInfo)
}
// DeleteComponentMap define func of delete circuit diagram data with component uuid
func DeleteComponentMap(componentUUID string) {
diagramsOverview.Delete(componentUUID)
}