mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-07 10:20:26 +00:00
45 lines
901 B
Go
45 lines
901 B
Go
package hyphae
|
|
|
|
import "sync"
|
|
|
|
type HyphaKind int
|
|
|
|
const (
|
|
HyphaEmpty HyphaKind = iota
|
|
HyphaText
|
|
HyphaMedia
|
|
)
|
|
|
|
// Hypher is a temporary name for this interface. The name will become Hypha, once the struct with the said name is deprecated for good.
|
|
type Hypher interface {
|
|
sync.Locker
|
|
|
|
CanonicalName() string
|
|
Kind() HyphaKind
|
|
DoesExist() bool
|
|
|
|
HasTextPart() bool
|
|
TextPartPath() string
|
|
}
|
|
|
|
// DeleteHypha deletes the hypha from the storage.
|
|
func DeleteHypha(h Hypher) {
|
|
byNamesMutex.Lock()
|
|
h.Lock()
|
|
delete(byNames, h.CanonicalName())
|
|
decrementCount()
|
|
byNamesMutex.Unlock()
|
|
h.Unlock()
|
|
}
|
|
|
|
// RenameHyphaTo renames a hypha and performs respective changes in the storage.
|
|
func RenameHyphaTo(h Hypher, newName string) {
|
|
byNamesMutex.Lock()
|
|
h.Lock()
|
|
delete(byNames, h.CanonicalName())
|
|
h.(*Hypha).SetName(newName)
|
|
byNames[h.CanonicalName()] = h.(*Hypha)
|
|
byNamesMutex.Unlock()
|
|
h.Unlock()
|
|
}
|