Delete() is working again
This commit is contained in:
parent
fb8e44d36c
commit
8ac4d90c22
44
generate.go
44
generate.go
|
@ -200,8 +200,8 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
FRUIT := PARENT
|
||||
APPLES := msg.Name
|
||||
APPLE := v.VarName
|
||||
COLOR := v.VarType
|
||||
APPLE := msg.VarName
|
||||
COLOR := v.VarName
|
||||
FUNCNAME := "Delete" + msg.Name + "By" + v.VarName
|
||||
|
||||
var funcdef string
|
||||
|
@ -250,25 +250,29 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "done", "", funcdef)
|
||||
}
|
||||
|
||||
/*
|
||||
// delete() functions
|
||||
for _, v := range msg.Vars {
|
||||
if !v.HasUnique {
|
||||
continue
|
||||
}
|
||||
funcname := "func (x *" + PARENT + ") Delete" + VARNAME + "By" + v.VarName + "(" + v.VarType + ") bool"
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
FRUIT := PARENT
|
||||
APPLES := VARNAME
|
||||
APPLE := v.VarName
|
||||
COLOR := s.VarType
|
||||
if argv.Delete {
|
||||
msg.deleteByWithCopy(wSort, FRUIT, APPLES, APPLE, COLOR)
|
||||
} else {
|
||||
msg.deleteBy(wSort, FRUIT, APPLES, APPLE, COLOR)
|
||||
}
|
||||
// delete() functions
|
||||
for _, v := range msg.Vars {
|
||||
if v.IsRepeated {
|
||||
continue
|
||||
}
|
||||
*/
|
||||
if !v.HasUnique {
|
||||
continue
|
||||
}
|
||||
// funcname := "func (x *" + PARENT + ") Delete" + VARNAME + "By" + v.VarName + "(" + v.VarType + ") bool"
|
||||
// log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "", "", funcname)
|
||||
FRUIT := PARENT
|
||||
APPLES := VARNAME
|
||||
APPLE := v.VarName
|
||||
COLOR := v.VarType
|
||||
FUNCNAME := "Delete" + VARNAME + "By" + v.VarName
|
||||
var funcdef string
|
||||
if argv.Delete {
|
||||
funcdef = msg.deleteByWithCopy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName)
|
||||
} else {
|
||||
funcdef = msg.deleteBy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName)
|
||||
}
|
||||
log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "done", "", funcdef)
|
||||
}
|
||||
|
||||
for _, v := range msg.Vars {
|
||||
if v.HasUnique {
|
||||
|
|
|
@ -38,15 +38,16 @@ func generateFindBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, LOCK string) {
|
|||
fmt.Fprintln(w, "")
|
||||
}
|
||||
|
||||
func (msg *MsgName) deleteBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FUNCNAME string) string {
|
||||
func (msg *MsgName) deleteBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, VARNAME string) string {
|
||||
LOCK := msg.getLockname("x")
|
||||
funcdef := "func (x *" + FRUIT + ") " + FUNCNAME + "(s string) bool"
|
||||
|
||||
fmt.Fprintln(w, "func (x *"+FRUIT+") "+FUNCNAME+"(s string) bool {")
|
||||
fmt.Fprintln(w, funcdef, "{")
|
||||
fmt.Fprintln(w, " "+LOCK+".Lock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " for i, _ := range x."+APPLES+" {")
|
||||
fmt.Fprintln(w, " if x."+APPLES+"[i]."+COLOR+" == s {")
|
||||
fmt.Fprintln(w, " if x."+APPLES+"[i]."+VARNAME+" == s {")
|
||||
fmt.Fprintln(w, " x."+APPLES+"[i] = x."+APPLES+"[len(x."+APPLES+")-1]")
|
||||
fmt.Fprintln(w, " x."+APPLES+" = x."+APPLES+"[:len(x."+APPLES+")-1]")
|
||||
fmt.Fprintln(w, " return true")
|
||||
|
@ -56,22 +57,24 @@ func (msg *MsgName) deleteBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FUNCNAME
|
|||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
|
||||
return "func (x *" + FRUIT + ") DeleteBy" + COLOR + "(s string) bool {"
|
||||
return funcdef
|
||||
}
|
||||
|
||||
// this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct
|
||||
func (msg *MsgName) deleteByWithCopy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FUNCNAME string) string {
|
||||
func (msg *MsgName) deleteByWithCopy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, VARNAME string) string {
|
||||
LOCK := msg.getLockname("x")
|
||||
|
||||
funcdef := "func (x *" + FRUIT + ") " + FUNCNAME + "(s string) *" + APPLE
|
||||
|
||||
fmt.Fprintln(w, "// TESTING fails with 'go vet' warning")
|
||||
fmt.Fprintln(w, "func (x *"+FRUIT+") "+FUNCNAME+"(s string) *"+APPLE+" {")
|
||||
fmt.Fprintln(w, funcdef, "{")
|
||||
fmt.Fprintln(w, " "+LOCK+".Lock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " var newr "+APPLE)
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " for i, _ := range x."+APPLES+" {")
|
||||
fmt.Fprintln(w, " if x."+APPLES+"[i]."+COLOR+" == s {")
|
||||
fmt.Fprintln(w, " if x."+APPLES+"[i]."+VARNAME+" == s {")
|
||||
fmt.Fprintln(w, " newr = *x."+APPLES+"[i]")
|
||||
fmt.Fprintln(w, " x."+APPLES+"[i] = x."+APPLES+"[len(x."+APPLES+")-1]")
|
||||
fmt.Fprintln(w, " x."+APPLES+" = x."+APPLES+"[:len(x."+APPLES+")-1]")
|
||||
|
@ -82,7 +85,7 @@ func (msg *MsgName) deleteByWithCopy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, F
|
|||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
|
||||
return "func (x *" + FRUIT + ") DeleteBy" + COLOR + "(s string) *" + APPLE + " {"
|
||||
return funcdef
|
||||
}
|
||||
|
||||
// new 2025 idea. useful? TODO: look at this again in 1y
|
||||
|
|
Loading…
Reference in New Issue