ready to tackle AppendBy()
This commit is contained in:
parent
47d2a95bc5
commit
c956babe1b
77
generate.go
77
generate.go
|
@ -156,10 +156,39 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("\n")
|
||||
|
||||
// add All()
|
||||
for _, s := range pf.ToSort {
|
||||
PARENT := s.MsgName
|
||||
CHILD := s.VarType
|
||||
VARNAME := s.VarName
|
||||
|
||||
if PARENT == VARNAME {
|
||||
funcdef := addAllFunc(wSort, PARENT, CHILD, VARNAME)
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "done", "", funcdef)
|
||||
}
|
||||
|
||||
/*
|
||||
// todo: figure out how to do more All() functions correction
|
||||
var FUNCTYPE string
|
||||
if PARENT == VARNAME {
|
||||
FUNCTYPE = PARENT
|
||||
} else {
|
||||
FUNCTYPE = VARNAME
|
||||
}
|
||||
|
||||
if s.VarType+"s" == s.VarName {
|
||||
funcname = "func (x *" + FUNCTYPE + ") All() *[]iter" + s.VarType
|
||||
} else {
|
||||
funcname = "func (x *" + FUNCTYPE + ") all" + s.VarName + "() *[]iter" + s.VarType
|
||||
}
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
*/
|
||||
}
|
||||
|
||||
// add Find() Delete() Append() Insert()
|
||||
log.Printf(" %-2s %20s %20s %20s %20s\n", "", "PARENT STRUCT", "VAR STRUCT TYPE", "VAR NAME", "LOCK")
|
||||
// for i, s := range slices.Backward(pf.ToSort) {
|
||||
for i, s := range pf.ToSort {
|
||||
var funcname string
|
||||
PARENT := s.MsgName
|
||||
|
@ -169,65 +198,33 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
|
||||
log.Printf("SORT: %-2d %20s %20s %20s %20s %s\n", i, PARENT, CHILD, VARNAME, LOCK, "")
|
||||
|
||||
var FUNCTYPE string
|
||||
if PARENT == VARNAME {
|
||||
FUNCTYPE = PARENT
|
||||
} else {
|
||||
FUNCTYPE = VARNAME
|
||||
}
|
||||
|
||||
if PARENT == VARNAME {
|
||||
funcname := addAllFunc(wSort, PARENT, CHILD, VARNAME)
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "done", "", funcname)
|
||||
}
|
||||
if s.VarType+"s" == s.VarName {
|
||||
funcname = "func (x *" + FUNCTYPE + ") All() *[]iter" + s.VarType
|
||||
} else {
|
||||
funcname = "func (x *" + FUNCTYPE + ") all" + s.VarName + "() *[]iter" + s.VarType
|
||||
}
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
msg := pf.findMsg(s.VarType)
|
||||
if msg == nil {
|
||||
return fmt.Errorf("failed to find struct %s", s.VarType)
|
||||
}
|
||||
for _, v := range msg.Vars {
|
||||
if v.HasSort {
|
||||
funcname := "func (x *" + FUNCTYPE + ") SortBy" + v.VarName + "(" + v.VarType + ") *[]iter" + s.VarType
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
// funcdef := "func (x *"+FRUIT+") SortBy"+COLOR+"() *"+APPLE+"Iterator"
|
||||
|
||||
if v.VarType == "string" {
|
||||
// funcdef := newSortBy(wSort, FUNCTYPE, CHILD, VARNAME, v.VarName)
|
||||
// log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcdef)
|
||||
} else {
|
||||
funcname := "func (x *" + FUNCTYPE + ") SortBy" + v.VarName + "(" + v.VarType + ") *[]iter" + s.VarType + " # can not do this yet"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ucount int
|
||||
for _, v := range msg.Vars {
|
||||
if v.HasUnique {
|
||||
ucount += 1
|
||||
funcname := "func (x *" + FUNCTYPE + ") AppendUnique" + v.VarName + "(" + v.VarType + ")"
|
||||
funcname := "func (x *" + PARENT + ") Append" + VARNAME + "By" + v.VarName + "(" + v.VarType + ")"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
}
|
||||
}
|
||||
for _, v := range msg.Vars {
|
||||
if v.HasUnique {
|
||||
funcname := "func (x *" + FUNCTYPE + ") DeleteBy" + v.VarName + "(" + v.VarType + ") bool"
|
||||
funcname := "func (x *" + PARENT + ") Delete" + VARNAME + "By" + v.VarName + "(" + v.VarType + ") bool"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range msg.Vars {
|
||||
if v.HasUnique {
|
||||
funcname = "func (x *" + FUNCTYPE + ") FindBy" + v.VarName + "(a " + v.VarType + ") *" + s.VarType + "(using" + v.VarName + ")"
|
||||
funcname = "func (x *" + PARENT + ") Find" + VARNAME + "By" + v.VarName + "(a " + v.VarType + ") *" + s.VarType + "(using" + v.VarName + ")"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
} else {
|
||||
if v.VarType == "string" {
|
||||
funcname = "func (x *" + FUNCTYPE + ") FindBy" + v.VarName + "(a string) []*" + s.VarType + " ???"
|
||||
funcname = "func (x *" + PARENT + ") Find" + VARNAME + "By" + v.VarName + "(a string) []*" + s.VarType + " ???"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
}
|
||||
}
|
||||
|
@ -237,12 +234,12 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
if !v.HasUnique {
|
||||
continue
|
||||
}
|
||||
funcname = "func (x *" + FUNCTYPE + ") Insert(a *" + v.VarType + ") (*" + CHILD + ", isNew bool)"
|
||||
funcname = "func (x *" + PARENT + ") Insert(a *" + v.VarType + ") (*" + CHILD + ", isNew bool)"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
}
|
||||
}
|
||||
if ucount > 1 {
|
||||
funcname = "func (x *" + FUNCTYPE + ") Insert(a *" + CHILD + ") (*" + CHILD + ", isNew bool)"
|
||||
funcname = "func (x *" + PARENT + ") Insert(a *" + CHILD + ") (*" + CHILD + ", isNew bool)"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue