From ae29d5cc674e0465c5861c1d261421bbe2725043 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 26 Mar 2025 04:57:29 -0500 Subject: [PATCH] names corrected for 'scanner' & 'iterator' --- generate.go | 4 ++-- generateSort.go | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/generate.go b/generate.go index b10ebcc..e0d8bea 100644 --- a/generate.go +++ b/generate.go @@ -30,7 +30,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { // add iterators for all the structs to be used for _, msg := range pf.allMsg() { - funcdef := newIter(wSort, msg) + funcdef := newScannerDefines(wSort, msg) log.Printf("Adding %s\n", funcdef) } @@ -67,7 +67,7 @@ func (pb *Files) makeNewSortfile(pf *File) error { return fmt.Errorf("failed to find struct %s", s.VarType) } - funcdef := msg.newIterAll(wSort, FRUIT, APPLE, APPLES, LOCK) + funcdef := msg.newScannerAll(wSort, FRUIT, APPLE, APPLES, LOCK) log.Printf("Adding %s\n", funcdef) } diff --git a/generateSort.go b/generateSort.go index 7319812..bf72795 100644 --- a/generateSort.go +++ b/generateSort.go @@ -8,7 +8,7 @@ import ( "io" ) -func (msg *MsgName) newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCKold string) string { +func (msg *MsgName) newScannerAll(w io.Writer, FRUIT, APPLE, APPLES, LOCKold string) string { LOCK := msg.getLockname("x") funcdef := "func (x *" + FRUIT + ") all" + APPLES + "() []*" + APPLE + " {" @@ -33,7 +33,7 @@ func (msg *MsgName) newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCKold string } // only make one of these for each message in the protobuf file -func newIter(w io.Writer, msg *MsgName) string { +func newScannerDefines(w io.Writer, msg *MsgName) string { if !msg.NeedIter { return "iter already done for " + msg.Name } @@ -42,22 +42,22 @@ func newIter(w io.Writer, msg *MsgName) string { // should this be 'new' or 'New' ? Does it matter? I think it's totally internal here // in this file where it is "new or "New". I changed it to lower case 2025.01.12 - funcdef := "func new" + APPLE + "Iterator(things []*" + APPLE + ") *" + APPLE + "Iterator" + funcdef := "func new" + APPLE + "Scanner(things []*" + APPLE + ") *" + APPLE + "Scanner" fmt.Fprintln(w, "// DEFINE THE", APPLE, "SCANNER.") fmt.Fprintln(w, "// itializes a new scanner.") fmt.Fprintln(w, funcdef, "{") - fmt.Fprintln(w, " return &"+APPLE+"Iterator{things: things}") + fmt.Fprintln(w, " return &"+APPLE+"Scanner{things: things}") fmt.Fprintln(w, "}") fmt.Fprintln(w, "") - fmt.Fprintln(w, "type "+APPLE+"Iterator struct {") + fmt.Fprintln(w, "type "+APPLE+"Scanner struct {") fmt.Fprintln(w, " sync.Mutex") fmt.Fprintln(w, "") fmt.Fprintln(w, " things []*"+APPLE+"") fmt.Fprintln(w, " index int") fmt.Fprintln(w, "}") fmt.Fprintln(w, "") - fmt.Fprintln(w, "func (it *"+APPLE+"Iterator) Scan() bool {") + fmt.Fprintln(w, "func (it *"+APPLE+"Scanner) Scan() bool {") fmt.Fprintln(w, " if it.index >= len(it.things) {") fmt.Fprintln(w, " return false") fmt.Fprintln(w, " }") @@ -68,9 +68,9 @@ func newIter(w io.Writer, msg *MsgName) string { fmt.Fprintln(w, "}") fmt.Fprintln(w, "") fmt.Fprintln(w, "// Next() returns the next thing in the array") - fmt.Fprintln(w, "func (it *"+APPLE+"Iterator) Next() *"+APPLE+" {") + fmt.Fprintln(w, "func (it *"+APPLE+"Scanner) Next() *"+APPLE+" {") fmt.Fprintln(w, " if it.things[it.index-1] == nil {") - fmt.Fprintln(w, " fmt.Println(\"Next() error in "+APPLE+"Iterator\", it.index)") + fmt.Fprintln(w, " fmt.Println(\"Next() error in "+APPLE+"Scanner\", it.index)") fmt.Fprintln(w, " }") fmt.Fprintln(w, " return it.things[it.index-1]") fmt.Fprintln(w, "}") @@ -100,7 +100,7 @@ func (msg *MsgName) newSortType(w io.Writer, STRUCT, VARNAME string) string { } func (msg *MsgName) newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT, VARNAME string) string { - funcdef := "func (x *" + STRUCT + ") " + SORTBY + "() *" + ITER + "Iterator" + funcdef := "func (x *" + STRUCT + ") " + SORTBY + "() *" + ITER + "Scanner" fmt.Fprintln(w, funcdef, "{") fmt.Fprintln(w, " // copy the pointers as fast as possible.") @@ -113,21 +113,21 @@ func (msg *MsgName) newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELEC fmt.Fprintln(w, "// })") // should this be 'new' or 'New' ? Does it matter? I think it's totally internal here // in this file where it is "new or "New". I changed it to lower case 2025.01.12 - fmt.Fprintln(w, " return new"+ITER+"Iterator(things)") + fmt.Fprintln(w, " return new"+ITER+"Scanner(things)") fmt.Fprintln(w, "}") return funcdef } func (msg *MsgName) addIterAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string { - funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Iterator {" + funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Scanner {" fmt.Fprintln(w, funcdef) fmt.Fprintln(w, " "+APPLE+"Pointers := x.selectAll"+APPLES+"()") fmt.Fprintln(w, "") // should this be 'new' or 'New' ? Does it matter? I think it's totally internal here. I think there are only 3 places // in this file where it is "new or "New". I changed it to lower case 2025.01.12 - fmt.Fprintln(w, " scanner := new"+APPLE+"Iterator("+APPLE+"Pointers)") + fmt.Fprintln(w, " scanner := new"+APPLE+"Scanner("+APPLE+"Pointers)") fmt.Fprintln(w, " return scanner") fmt.Fprintln(w, "}") fmt.Fprintln(w, "") @@ -155,7 +155,7 @@ func (msg *MsgName) addIterBy(w io.Writer, FRUITS, FRUIT, APPLE, SORTNAME string func (msg *MsgName) addIterAll(w io.Writer, FRUITS, FRUIT string) string { funcdef := "func (x *" + FRUITS + ") IterAll() iter.Seq[*" + FRUIT + "] {" - fmt.Fprintln(w, "// 'for x := range' syntax using the awesome golang 1.24 'iter'") + fmt.Fprintln(w, "// Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'") fmt.Fprintln(w, funcdef) fmt.Fprintln(w, " items := x.selectAll"+FRUITS+"()") fmt.Fprintln(w, " // log.Println(\"Made All() Iter.Seq[] with length\", len(items))") @@ -172,15 +172,15 @@ func (msg *MsgName) addIterAll(w io.Writer, FRUITS, FRUIT string) string { } func (msg *MsgName) addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string { - funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Iterator {" + funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Scanner {" fmt.Fprintln(w, funcdef) fmt.Fprintln(w, " "+APPLE+"Pointers := x.selectAll"+APPLES+"()") fmt.Fprintln(w, "") // should this be 'new' or 'New' ? Does it matter? I think it's totally internal here. I think there are only 3 places // in this file where it is "new or "New". I changed it to lower case 2025.01.12 - fmt.Fprintln(w, " scanneriterator := new"+APPLE+"Iterator("+APPLE+"Pointers)") - fmt.Fprintln(w, " return scanneriterator") + fmt.Fprintln(w, " scanner := new"+APPLE+"Scanner("+APPLE+"Pointers)") + fmt.Fprintln(w, " return scanner") fmt.Fprintln(w, "}") fmt.Fprintln(w, "")