FIX THINGS. THIS IS BETTER!
This commit is contained in:
parent
b5002b158b
commit
9cb5064906
|
@ -21,11 +21,23 @@ message Apple {
|
|||
google.protobuf.Timestamp ctime = 3; // when the apple was born
|
||||
}
|
||||
|
||||
message Apples {
|
||||
string name = 1; // `autogenpb:unique` // generates SortByxxx() and AppendUnique() functions
|
||||
string genus = 2; // `autogenpb:unique` // generates same thing here but SortByGenus()
|
||||
repeated Apple apples = 3;
|
||||
}
|
||||
|
||||
message Pear { // `autogenpb:nomutex`
|
||||
string name = 1; // `autogenpb:sort`
|
||||
string favorite = 2; // `autogenpb:sort` `autogenpb:unique`
|
||||
}
|
||||
|
||||
message Pears { // `autogenpb:nomutex`
|
||||
string name = 1; // `autogenpb:sort`
|
||||
string favorite = 2; // `autogenpb:sort` `autogenpb:unique`
|
||||
repeated Pear pears = 3;
|
||||
}
|
||||
|
||||
message Banana { // `autogenpb:nomutex`
|
||||
repeated string name = 1; // `autogenpb:sort`
|
||||
string favorite = 2; // `autogenpb:sort` `autogenpb:unique`
|
||||
|
@ -44,12 +56,12 @@ message Basket { // `autogenpb:nomutex`
|
|||
// "Fruit" must exist. you can put anything in it
|
||||
message Fruit {
|
||||
string brand = 1; // `autogenpb:unique` `autogenpb:sort`
|
||||
repeated Apple apples = 2;
|
||||
Apple apples = 2;
|
||||
repeated Pear pears = 3;
|
||||
string UPC = 4; // `autogenpb:sort` `autogenpb:unique`
|
||||
string city = 5; // `autogenpb:sort`
|
||||
repeated Pear notpears = 6;
|
||||
repeated Pear fakepears = 7;
|
||||
Pears notpears = 6;
|
||||
Pears fakepears = 7;
|
||||
repeated Basket gifts = 8;
|
||||
}
|
||||
|
||||
|
|
38
generate.go
38
generate.go
|
@ -107,13 +107,14 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
// func newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT string) string {
|
||||
if PARENT == VARNAME {
|
||||
sortby = "SortBy" + v.VarName
|
||||
} else {
|
||||
sortby = "Sort" + VARNAME + "By" + v.VarName
|
||||
}
|
||||
sortname := s.VarType + v.VarName
|
||||
selectName := "selectAll" + VARNAME
|
||||
funcdef := newSortBy(wSort, PARENT, s.VarType, sortname, sortby, selectName, v.VarName)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
} else {
|
||||
// deprecate this THIS DOES NOT MAKE SENSE TO DO
|
||||
sortby = "Sort" + VARNAME + "By" + v.VarName
|
||||
}
|
||||
} else {
|
||||
// funcdef := "func (x *" + FUNCTYPE + ") SortBy" + v.VarName + "(" + v.VarType + ") *[]iter" + s.VarType + " # can not do this yet"
|
||||
}
|
||||
|
@ -124,7 +125,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
fmt.Fprintf(wSort, "\n")
|
||||
fmt.Fprintf(wSort, "// END SORT\n")
|
||||
|
||||
// make Len()
|
||||
// make Len() and Append()
|
||||
for _, msg := range pf.allMsg() {
|
||||
PARENT := msg.Name
|
||||
LOCK := msg.Lockname
|
||||
|
@ -142,14 +143,14 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
}
|
||||
if PARENT == VARNAME {
|
||||
// FUNCNAME := "Append"
|
||||
msg.simpleAppend(wSort, PARENT, v.VarName, v.VarType)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Printf("\n")
|
||||
|
||||
// add All()
|
||||
for _, s := range pf.ToSort {
|
||||
|
@ -202,13 +203,14 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
if PARENT == VARNAME {
|
||||
// special case because of the enforced .proto format
|
||||
FUNCNAME = "FindBy" + v.VarName
|
||||
} else {
|
||||
FUNCNAME = "Find" + VARNAME + "By" + v.VarName
|
||||
}
|
||||
|
||||
funcdef := msg.generateFindBy(wSort, FUNCNAME, PARENT, VARNAME, s.VarType, v.VarName)
|
||||
// func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string {
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
} else {
|
||||
// deprecate these
|
||||
FUNCNAME = "Find" + VARNAME + "By" + v.VarName
|
||||
}
|
||||
|
||||
} else {
|
||||
if v.VarType == "string" {
|
||||
// probably dumb. move to a database if you need this
|
||||
|
@ -234,11 +236,8 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
COLOR := v.VarType
|
||||
var FUNCNAME string
|
||||
if PARENT == VARNAME {
|
||||
// special case because of the enforced .proto format
|
||||
// special case because of the enforced .proto format // ONLY USE CASE THAT MAKES SENSE
|
||||
FUNCNAME = "DeleteBy" + v.VarName
|
||||
} else {
|
||||
FUNCNAME = "Delete" + VARNAME + "By" + v.VarName
|
||||
}
|
||||
var funcdef string
|
||||
if argv.Delete {
|
||||
funcdef = msg.deleteByWithCopy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName)
|
||||
|
@ -246,6 +245,10 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
funcdef = msg.deleteBy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName)
|
||||
}
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
} else {
|
||||
// deprecate these
|
||||
FUNCNAME = "Delete" + VARNAME + "By" + v.VarName
|
||||
}
|
||||
}
|
||||
|
||||
// AppendBy() functions. todo: fix these so Append() is for simple things and Insert() is for unique keys
|
||||
|
@ -260,12 +263,17 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
ucount += 1
|
||||
var FUNCNAME string
|
||||
if PARENT == VARNAME {
|
||||
// special case because of the enforced .proto format
|
||||
// special case because of the enforced .proto format // ONLY SUPPORT THIS
|
||||
FUNCNAME = "AppendBy" + v.VarName
|
||||
funcdef := msg.addAppendBy(wSort, PARENT, FUNCNAME, VARNAME, v.VarName, s.VarType)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
} else {
|
||||
// deprecate this
|
||||
/*
|
||||
FUNCNAME = "Append" + VARNAME + "By" + v.VarName
|
||||
funcdef := msg.addAppendBy(wSort, PARENT, FUNCNAME, VARNAME, v.VarName, s.VarType)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,26 +3,28 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// generates Append()
|
||||
|
||||
// I like these functions the best.
|
||||
func (msg *MsgName) simpleAppend(w io.Writer, FRUIT, APPLES, APPLE string) {
|
||||
func (msg *MsgName) simpleAppend(w io.Writer, FRUIT, APPLES, APPLE string) string {
|
||||
LOCK := msg.getLockname("x")
|
||||
|
||||
log.Printf("\t\t(x %s) APPEND(%s)\n", FRUIT, APPLE)
|
||||
funcdef := "func (x *" + FRUIT + ") Append(y *" + APPLE + ")"
|
||||
|
||||
// log.Printf("\t\t(x %s) APPEND(%s)\n", FRUIT, APPLE)
|
||||
// append -- no check at all
|
||||
fmt.Fprintln(w, "// just a simple Append() shortcut (but still uses the mutex lock)")
|
||||
fmt.Fprintln(w, "func (x *"+FRUIT+") Append(y *"+APPLE+") {")
|
||||
fmt.Fprintln(w, funcdef, "{")
|
||||
fmt.Fprintln(w, " "+LOCK+".Lock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " x."+APPLES+" = append(x."+APPLES+", y)")
|
||||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
|
||||
return funcdef
|
||||
}
|
||||
|
||||
/* FIX THSE as Import()
|
||||
|
|
Loading…
Reference in New Issue