modelRT/diagram/topologic_set.go

50 lines
1.3 KiB
Go
Raw Normal View History

package diagram
import (
"errors"
"fmt"
"sync"
)
2024-12-18 16:25:49 +08:00
// graphOverview define struct of storage all circuit diagram topologic data
var graphOverview sync.Map
// PrintGrapMap define func of print circuit diagram topologic info data
func PrintGrapMap() {
graphOverview.Range(func(key, value interface{}) bool {
fmt.Println(key, value)
return true
})
}
2024-11-27 15:41:22 +08:00
// GetGraphMap define func of get circuit diagram topologic data by pageID
func GetGraphMap(pageID int64) (*Graph, error) {
value, ok := graphOverview.Load(pageID)
if !ok {
2024-11-27 15:41:22 +08:00
return nil, fmt.Errorf("can not find graph by pageID:%d", pageID)
}
graph, ok := value.(*Graph)
if !ok {
return nil, errors.New("convert to graph struct failed")
}
return graph, nil
}
// UpdateGrapMap define func of update circuit diagram data by pageID and topologic info
func UpdateGrapMap(pageID int64, graphInfo *Graph) bool {
_, result := graphOverview.Swap(pageID, graphInfo)
return result
}
// StoreGraphMap define func of store circuit diagram topologic data with pageID and topologic info
func StoreGraphMap(pageID int64, graphInfo *Graph) {
graphOverview.Store(pageID, graphInfo)
return
}
// DeleteGraphMap define func of delete circuit diagram topologic data with pageID
func DeleteGraphMap(pageID int64) {
graphOverview.Delete(pageID)
return
}