mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化代码
This commit is contained in:
@@ -24,8 +24,9 @@ type Output struct {
|
|||||||
func (em *Output) GetName() string {
|
func (em *Output) GetName() string {
|
||||||
return "Output"
|
return "Output"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em *Output) Exec() (int, error) {
|
func (em *Output) Exec() (int, error) {
|
||||||
val, ok := em.GetInPortInt(0)
|
val, ok := em.GetInPortInt(1)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("Output Exec inParam not found")
|
return 0, fmt.Errorf("Output Exec inParam not found")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ type IInnerExecNode interface {
|
|||||||
|
|
||||||
GetInPort(index int) IPort
|
GetInPort(index int) IPort
|
||||||
GetOutPort(index int) IPort
|
GetOutPort(index int) IPort
|
||||||
|
|
||||||
|
GetInPortParamStartIndex() int
|
||||||
|
GetOutPortParamStartIndex() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type IExecNode interface {
|
type IExecNode interface {
|
||||||
@@ -36,6 +39,9 @@ type innerExecNode struct {
|
|||||||
|
|
||||||
InPort []IPort
|
InPort []IPort
|
||||||
OutPort []IPort
|
OutPort []IPort
|
||||||
|
|
||||||
|
inPortParamStartIndex int // 输入参数的起始索引,用于排除执行入口
|
||||||
|
outPortParamStartIndex int // 输出参数的起始索引,用于排除执行出口
|
||||||
IExecNode
|
IExecNode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,11 +80,29 @@ type BaseExecConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (em *innerExecNode) AppendInPort(port ...IPort) {
|
func (em *innerExecNode) AppendInPort(port ...IPort) {
|
||||||
em.InPort = append(em.InPort, port...)
|
if len(em.InPort) == 0 {
|
||||||
|
em.inPortParamStartIndex = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(port); i++ {
|
||||||
|
if !port[i].IsPortExec() && em.inPortParamStartIndex < 0 {
|
||||||
|
em.inPortParamStartIndex = len(em.InPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
em.InPort = append(em.InPort, port[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em *innerExecNode) AppendOutPort(port ...IPort) {
|
func (em *innerExecNode) AppendOutPort(port ...IPort) {
|
||||||
em.OutPort = append(em.OutPort, port...)
|
if len(em.OutPort) == 0 {
|
||||||
|
em.outPortParamStartIndex = -1
|
||||||
|
}
|
||||||
|
for i := 0; i < len(port); i++ {
|
||||||
|
if !port[i].IsPortExec() && em.outPortParamStartIndex < 0 {
|
||||||
|
em.outPortParamStartIndex = len(em.OutPort)
|
||||||
|
}
|
||||||
|
em.OutPort = append(em.OutPort, port[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (em *innerExecNode) GetName() string {
|
func (em *innerExecNode) GetName() string {
|
||||||
@@ -93,6 +117,8 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) {
|
|||||||
inPorts := make([]IPort, 0, 2)
|
inPorts := make([]IPort, 0, 2)
|
||||||
for _, port := range em.InPort {
|
for _, port := range em.InPort {
|
||||||
if port.IsPortExec() {
|
if port.IsPortExec() {
|
||||||
|
// 执行入口, 不需要克隆,占位处理
|
||||||
|
inPorts = append(inPorts, nil)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +128,7 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) {
|
|||||||
|
|
||||||
for _, port := range em.OutPort {
|
for _, port := range em.OutPort {
|
||||||
if port.IsPortExec() {
|
if port.IsPortExec() {
|
||||||
|
outPorts = append(outPorts, nil)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
outPorts = append(outPorts, port.Clone())
|
outPorts = append(outPorts, port.Clone())
|
||||||
@@ -147,6 +174,14 @@ func (em *innerExecNode) GetOutPort(index int) IPort {
|
|||||||
return em.OutPort[index]
|
return em.OutPort[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (em *innerExecNode) GetInPortParamStartIndex() int {
|
||||||
|
return em.inPortParamStartIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (em *innerExecNode) GetOutPortParamStartIndex() int {
|
||||||
|
return em.outPortParamStartIndex
|
||||||
|
}
|
||||||
|
|
||||||
func (en *BaseExecNode) initInnerExecNode(innerNode *innerExecNode) {
|
func (en *BaseExecNode) initInnerExecNode(innerNode *innerExecNode) {
|
||||||
en.innerExecNode = innerNode
|
en.innerExecNode = innerNode
|
||||||
}
|
}
|
||||||
@@ -197,6 +232,7 @@ func (en *BaseExecNode) GetInPortInt(index int) (Port_Int, bool) {
|
|||||||
if port == nil {
|
if port == nil {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return port.GetInt()
|
return port.GetInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,12 +90,13 @@ func (en *execNode) Do(gr *Graph, outPortArgs ...any) error {
|
|||||||
OutputPorts: outPorts,
|
OutputPorts: outPorts,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startOutIdx := en.execNode.GetOutPortParamStartIndex()
|
||||||
for i := 0; i < len(outPortArgs); i++ {
|
for i := 0; i < len(outPortArgs); i++ {
|
||||||
if i >= len(outPorts) {
|
if i >= len(outPorts) {
|
||||||
return fmt.Errorf("args %d not found in node %s", i, en.execNode.GetName())
|
return fmt.Errorf("args %d not found in node %s", i, en.execNode.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := outPorts[i].setAnyVale(outPortArgs[i]); err != nil {
|
if err := outPorts[i+startOutIdx].setAnyVale(outPortArgs[i]); err != nil {
|
||||||
return fmt.Errorf("args %d set value error: %w", i, err)
|
return fmt.Errorf("args %d set value error: %w", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user