summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generate.go14
-rw-r--r--generateAppend.go48
2 files changed, 55 insertions, 7 deletions
diff --git a/generate.go b/generate.go
index 738e507..739e87e 100644
--- a/generate.go
+++ b/generate.go
@@ -5,12 +5,9 @@ package main
import (
"fmt"
- "io"
"os"
"go.wit.com/log"
- "golang.org/x/text/cases"
- "golang.org/x/text/language"
)
// this file is named poorly. It has more than Sort()
@@ -172,8 +169,9 @@ func (pb *Files) makeNewSortfile(pf *File) error {
// FUNCNAME := "Append"
funcdef := msg.simpleAppend(wSort, PARENT, v.VarName, v.VarType)
log.Printf("Adding %s\n", funcdef)
- // funcdef := msg.addAppendBy(wSort, PARENT, FUNCNAME, VARNAME, PARENT, s.VarType)
- // log.Printf(" %-2s %20s %20s %20s %s %s\n", "", "", "", "done", "", funcdef)
+
+ funcdef = msg.simpleClone(wSort, PARENT, v.VarName, v.VarType)
+ log.Printf("Adding %s\n", funcdef)
}
}
}
@@ -347,6 +345,10 @@ func (pb *Files) makeNewSortfile(pf *File) error {
FUNCNAME = "AppendBy" + v.VarName
funcdef := pmsg.simpleAppendBy(wSort, PARENT, FUNCNAME, VARNAME, v.VarName, s.VarType)
log.Printf("Adding %s\n", funcdef)
+
+ FUNCNAME = "CloneBy" + v.VarName
+ funcdef = pmsg.simpleCloneBy(wSort, PARENT, FUNCNAME, VARNAME, v.VarName, s.VarType)
+ log.Printf("Adding %s\n", funcdef)
}
}
@@ -393,6 +395,7 @@ func (pf *File) allMsg() []*MsgName {
return all
}
+/*
func (pf *File) specialBases(wFind io.Writer) {
var FRUIT string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name)
var APPLES string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name)
@@ -401,3 +404,4 @@ func (pf *File) specialBases(wFind io.Writer) {
pf.Bases.simpleAppend(wFind, FRUIT, APPLES, APPLE)
}
+*/
diff --git a/generateAppend.go b/generateAppend.go
index 8aee819..4c2dda6 100644
--- a/generateAppend.go
+++ b/generateAppend.go
@@ -63,7 +63,7 @@ func (msg *MsgName) simpleAppendBy(w io.Writer, STRUCT, FUNCNAME, STRUCTVAR, VAR
func (msg *MsgName) simpleClone(w io.Writer, FRUIT, APPLES, APPLE string) string {
LOCK := msg.getLockname("x")
- funcdef := "func (x *" + FRUIT + ") Append(y *" + APPLE + ") *" + APPLE
+ funcdef := "func (x *" + FRUIT + ") Clone(y *" + APPLE + ") *" + APPLE
// log.Printf("\t\t(x %s) CLONE(%s)\n", FRUIT, APPLE)
// append -- no check at all
@@ -85,7 +85,7 @@ func (msg *MsgName) simpleClone(w io.Writer, FRUIT, APPLES, APPLE string) string
// Unique Append. rejects Append() if value is already defined
// compares the field 'COLOR' in the STRUCT with VARNAME
// that's not the right description above, but whatever, you get the idea
-func (msg *MsgName) addCloneBy(w io.Writer, STRUCT, FUNCNAME, STRUCTVAR, VARNAME, VARTYPE string) string {
+func (msg *MsgName) simpleCloneBy(w io.Writer, STRUCT, FUNCNAME, STRUCTVAR, VARNAME, VARTYPE string) string {
LOCK := msg.getLockname("x")
funcdef := "func (x *" + STRUCT + ") " + FUNCNAME + "(y *" + VARTYPE + ") bool"
@@ -107,3 +107,47 @@ func (msg *MsgName) addCloneBy(w io.Writer, STRUCT, FUNCNAME, STRUCTVAR, VARNAME
return funcdef
}
+
+/* FIX THSE and call them Import() ?
+func (msg *MsgName) appendUnique(w io.Writer, FRUIT, APPLES, APPLE string, COLORS []string) {
+ LOCK := msg.getLockname("x")
+
+ fmt.Fprintln(w, "// enforces "+APPLE+" is unique in "+FRUIT+"."+APPLES)
+ fmt.Fprintln(w, "func (x *"+FRUIT+") AppendUnique(newP *"+APPLE+") bool {")
+ fmt.Fprintln(w, " "+LOCK+".Lock()")
+ fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " for _, p := range x."+APPLES+" {")
+ for _, COLOR := range COLORS {
+ fmt.Fprintln(w, " if p."+COLOR+" == newP."+COLOR+" {")
+ fmt.Fprintln(w, " return false")
+ fmt.Fprintln(w, " }")
+ }
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " x."+APPLES+" = append(x."+APPLES+", newP)")
+ fmt.Fprintln(w, " return true")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "")
+}
+
+func (msg *MsgName) appendUniqueCOLOR(w io.Writer, FRUIT, APPLES, APPLE, COLOR string) {
+ LOCK := msg.getLockname("x")
+
+ fmt.Fprintln(w, "// enforces "+APPLE+"."+COLOR+" is unique in "+FRUIT+"."+APPLES)
+ fmt.Fprintln(w, "func (x *"+FRUIT+") AppendUnique"+COLOR+"(newP *"+APPLE+") bool {")
+ fmt.Fprintln(w, " "+LOCK+".Lock()")
+ fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " for _, p := range x."+APPLES+" {")
+ fmt.Fprintln(w, " if p."+COLOR+" == newP."+COLOR+" {")
+ fmt.Fprintln(w, " return false")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " x."+APPLES+" = append(x."+APPLES+", newP)")
+ fmt.Fprintln(w, " return true")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "")
+}
+*/