modelRT/diagram/component_map.go

44 lines
1.3 KiB
Go
Raw Normal View History

package diagram
import (
"errors"
"fmt"
"sync"
cmap "github.com/orcaman/concurrent-map/v2"
)
2024-11-27 15:41:22 +08:00
// DiagramsOverview define struct of storage all circuit diagram data
var diagramsOverview sync.Map
2024-11-27 15:41:22 +08:00
// GetComponentMap define func of get circuit diagram data by global uuid
func GetComponentMap(uuid string) (*cmap.ConcurrentMap[string, any], error) {
value, ok := diagramsOverview.Load(uuid)
if !ok {
2024-11-27 15:41:22 +08:00
return nil, fmt.Errorf("can not find graph by global uuid:%s", uuid)
}
paramsMap, ok := value.(*cmap.ConcurrentMap[string, any])
if !ok {
return nil, errors.New("convert to component map struct failed")
}
return paramsMap, nil
}
// UpdateComponentMap define func of update circuit diagram data by global uuid and component info
func UpdateComponentMap(uuid string, componentInfo *cmap.ConcurrentMap[string, any]) bool {
_, result := diagramsOverview.Swap(uuid, componentInfo)
return result
}
// StoreComponentMap define func of store circuit diagram data with global uuid and component info
func StoreComponentMap(uuid string, componentInfo *cmap.ConcurrentMap[string, any]) {
diagramsOverview.Store(uuid, componentInfo)
return
}
// DeleteComponentMap define func of delete circuit diagram data with global uuid
func DeleteComponentMap(uuid string) {
diagramsOverview.Delete(uuid)
return
}