graph

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TpNone = "none"
)

Variables

This section is empty.

Functions

func InitMsgProcessor

func InitMsgProcessor(m map[string]MsgToErr)

func LinkName

func LinkName(outNode, outPoint, inNode, inPoint string) string

func NewNode

func NewNode(g IGraph, name string) *node

Types

type Conf

type Conf struct {
	Name      string
	Comment   string
	Nodes     []NodeConf
	Links     []LinkConf
	SubGraphs []SubConf
}

type IGraph

type IGraph interface {
	Name() string
	Data() util.M
	SetData(m util.M)
	Plugin() IPlugin
	SetPlugin(plugin IPlugin)
	Start() *util.Err
	AddNode(name string) (INode, *util.Err)
	GetNode(name string) (INode, *util.Err)
	GetNodeByPath(names ...string) (INode, *util.Err)
	FindNode(name string) (INode, bool)
	FindNodes(name string, nodes *[]INode)
	IterNode(fn func(INode))
	AnyNode(fn func(INode) bool) bool
	Link(outNode, outPoint, inNode, inPoint string) (ILink, *util.Err)
	IterLink(fn func(ILink))
	AnyLink(fn func(ILink) bool) bool
	AddSubGraph(name string) (ISubGraph, *util.Err)
	GetSubGraph(graph string) (ISubGraph, *util.Err)
	IterSubGraph(fn func(ISubGraph))
	AnySubGraph(fn func(ISubGraph) bool) bool
}

func NewGraph

func NewGraph(name string, opts ...Option) IGraph

func NewGraphWithConf

func NewGraphWithConf(conf Conf, opts ...Option) IGraph

type IGraphElem

type IGraphElem interface {
	Name() string
	Path() string
	Comment() string
	SetComment(c string)
	Data() util.M
	SetData(data util.M)
	Start() *util.Err
	Enable() *util.Err               //即使已可用,也会重复执行
	Disable() *util.Err              //即使不可用,也会重复执行
	SetEnable(enable bool) *util.Err //已经是该状态不会重复执行
	Enabled() bool
	AddBeforeEnable(fn util.BoolToErr) //添加节点切换是否可用之前调用
	DelBeforeEnable(fn util.BoolToErr) //移除节点切换是否可用之前调用
	AddAfterEnable(fn util.FnBool)     //添加节点切换是否可用之后调用
	DelAfterEnable(fn util.FnBool)     //移除节点切换是否可用之后调用
	Graph() IGraph
	RootGraph() IGraph
}

type IGraphMarshall

type IGraphMarshall interface {
	IGraphMarshaller
	IGraphUnMarshaller
}

type IGraphMarshaller

type IGraphMarshaller interface {
	Marshall(g IGraph) []byte
}

type IGraphUnMarshaller

type IGraphUnMarshaller interface {
	Unmarshall(bytes []byte, g IGraph) *util.Err
}

type IIn

type IIn interface {
	IPoint
	Receive(msg IMsg) *util.Err
}
type ILink interface {
	IGraphElem
	In() IIn
	Out() IOut
	Transfer(msg IMsg) *util.Err
	AddFilter(fn func(IMsg) *util.Err)
}

func LinkWithConf

func LinkWithConf(g IGraph, conf LinkConf) (ILink, *util.Err)

type IMsg

type IMsg interface {
	Type() TPoint
	OutNode() string
	OutPoint() string
	InNode() INode
	SetInNode(inNode INode)
	InPoint() string
	SetInPoint(inPoint string)
	Data() any
	ToJson() ([]byte, *util.Err)
	ToM() util.M
}

type INode

type INode interface {
	IGraphElem
	HasIn(name string) bool
	HasOut(name string) bool
	AddIn(t TPoint, name string) *util.Err
	AddOut(t TPoint, name string) *util.Err
	GetIn(name string) (IIn, *util.Err)
	GetOut(name string) (IOut, *util.Err)
	Out(name string, m any) *util.Err
	ProcessData(msg IMsg) *util.Err
	BindFn(point string, fn MsgToErr)
}

func AddNodeWithConf

func AddNodeWithConf(g IGraph, conf NodeConf) (INode, *util.Err)

type IOut

type IOut interface {
	IPoint
	Send(msg IMsg) *util.Err
}

type IPlugin

type IPlugin interface {
	OnStart(g IGraph)
	OnAddNode(g IGraph, nd INode)
	OnAddSubGraph(g IGraph, sg ISubGraph)
	OnAddLink(g IGraph, lnk ILink)
	OnAddIn(in IIn)
	OnAddOut(out IOut)
}

type IPoint

type IPoint interface {
	IGraphElem
	Type() TPoint
	Node() INode
	AddLink(lnk ILink)
	GetLink(name string) (ILink, *util.Err)
	AddFilter(func(IMsg) *util.Err)
}

type ISubGraph

type ISubGraph interface {
	IGraph
	INode
	InNode() INode
	SetInNode(name string) *util.Err
	OutNode() INode
	SetOutNode(name string) *util.Err
}

func AddSubGraphWithConf

func AddSubGraphWithConf(g IGraph, conf SubConf) (ISubGraph, *util.Err)

type LinkConf

type LinkConf struct {
	OutNode  string
	OutPoint string
	InNode   string
	InPoint  string
}

type LinkToBool

type LinkToBool func(ILink) bool

type Msg

type Msg struct {
	// contains filtered or unexported fields
}

func (*Msg) Data

func (m *Msg) Data() any

func (*Msg) InNode

func (m *Msg) InNode() INode

func (*Msg) InPoint

func (m *Msg) InPoint() string

func (*Msg) OutNode

func (m *Msg) OutNode() string

func (*Msg) OutPoint

func (m *Msg) OutPoint() string

func (*Msg) SetInNode

func (m *Msg) SetInNode(inNode INode)

func (*Msg) SetInPoint

func (m *Msg) SetInPoint(inPoint string)

func (*Msg) ToJson

func (m *Msg) ToJson() ([]byte, *util.Err)

func (*Msg) ToM

func (m *Msg) ToM() util.M

func (*Msg) Type

func (m *Msg) Type() TPoint

type MsgToBoolErr

type MsgToBoolErr func(IMsg) (bool, *util.Err)

type MsgToErr

type MsgToErr func(IMsg) *util.Err

func GetMsgProcessor

func GetMsgProcessor(t string) MsgToErr

type NodeConf

type NodeConf struct {
	Name             string
	Comment          string
	M                util.M
	Ins              []PointConf
	Outs             []PointConf
	PointToProcessor map[string]string
}

type NodeStrToAnyErr

type NodeStrToAnyErr func(INode, string) (any, bool)

type NodeToAnyBool

type NodeToAnyBool func(INode) (any, bool)

type Option

type Option func(*option)

func Plugin

func Plugin(plugin IPlugin) Option

type PointConf

type PointConf struct {
	Type    TPoint
	Name    string
	Comment string
}

type StrLinkToBool

type StrLinkToBool func(string, ILink) bool

type SubConf

type SubConf struct {
	Name      string
	Comment   string
	Nodes     []NodeConf
	Links     []LinkConf
	SubGraphs []SubConf
	In        string
	Out       string
}

type TPoint

type TPoint string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL