diff options
| author | Jeff Carr <[email protected]> | 2025-09-27 20:38:37 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-27 20:38:37 -0500 |
| commit | 23dfd379aa0c0f07e4b621e5b6fa4a04e2167856 (patch) | |
| tree | 045c108628f63c2b0a134c2a124b33afd04bb6aa /auto.sort.pb.go | |
| parent | 4cc8acab35deca0edbf2cc56ebe649b680d7e36f (diff) | |
moved to cgitv0.0.17
Diffstat (limited to 'auto.sort.pb.go')
| -rw-r--r-- | auto.sort.pb.go | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/auto.sort.pb.go b/auto.sort.pb.go new file mode 100644 index 0000000..bf0c4b4 --- /dev/null +++ b/auto.sort.pb.go @@ -0,0 +1,191 @@ +// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. +// This file was autogenerated with autogenpb v0.5.14 2025-09-28_00:11:07_UTC +// go install go.wit.com/apps/autogenpb@latest +// +// define which structs (messages) you want to use in the .proto file +// Then sort.pb.go and marshal.pb.go files are autogenerated +// +// autogenpb uses it and has an example .proto file with instructions +// + +package prep + +import ( + "fmt" + "iter" + "sync" + + "google.golang.org/protobuf/proto" +) + +// a simple global lock +var autoMu sync.RWMutex + +func (x *Autos) fixUuid() { + if x == nil { + return + } + if x.Uuid == "94210ebf-a534-4b33-aadd-2f5e1f56ae38" { + return + } + x.Uuid = "94210ebf-a534-4b33-aadd-2f5e1f56ae38" + x.Version = "v0.0.1 go.wit.com/lib/gui/prep" +} + +func NewAutos() *Autos { + x := new(Autos) + x.Uuid = "94210ebf-a534-4b33-aadd-2f5e1f56ae38" + x.Version = "v0.0.1 go.wit.com/lib/gui/prep" + return x +} + +// START SORT + +// DEFINE THE Autos SCANNER. +// itializes a new scanner. +func newAutosScanner(things []*Autos) *AutosScanner { + return &AutosScanner{things: things} +} + +type AutosScanner struct { + sync.Mutex + + things []*Autos + index int +} + +func (it *AutosScanner) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.Lock() + it.index++ + it.Unlock() + return true +} + +// Next() returns the next thing in the array +func (it *AutosScanner) Next() *Autos { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in AutosScanner", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE SCANNER + +// DEFINE THE Auto SCANNER. +// itializes a new scanner. +func newAutoScanner(things []*Auto) *AutoScanner { + return &AutoScanner{things: things} +} + +type AutoScanner struct { + sync.Mutex + + things []*Auto + index int +} + +func (it *AutoScanner) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.Lock() + it.index++ + it.Unlock() + return true +} + +// Next() returns the next thing in the array +func (it *AutoScanner) Next() *Auto { + if it.things[it.index-1] == nil { + fmt.Println("Next() error in AutoScanner", it.index) + } + return it.things[it.index-1] +} + +// END DEFINE THE SCANNER + +// safely returns a slice of pointers to the FRUIT protobufs +func (x *Autos) allAutos() []*Auto { + autoMu.RLock() + defer autoMu.RUnlock() + + // Create a new slice to hold pointers to each FRUIT + var tmp []*Auto + tmp = make([]*Auto, len(x.Autos)) + for i, p := range x.Autos { + tmp[i] = p // Copy pointers for safe iteration + } + + return tmp +} + +// safely returns a slice of pointers to the Auto protobufs +func (x *Autos) selectAllAutos() []*Auto { + autoMu.RLock() + defer autoMu.RUnlock() + + // Create a new slice to hold pointers to each Auto + var tmp []*Auto + tmp = make([]*Auto, len(x.Autos)) + for i, p := range x.Autos { + tmp[i] = p // Copy pointers for safe iteration + } + + return tmp +} + +// END SORT + +func (x *Autos) Len() int { + autoMu.RLock() + defer autoMu.RUnlock() + + return len(x.Autos) +} + +// a Append() shortcut (that does Clone() with a mutex) notsure if it really works +func (x *Autos) Append(y *Auto) *Auto { + autoMu.Lock() + defer autoMu.Unlock() + + z := proto.Clone(y).(*Auto) + x.Autos = append(x.Autos, z) + + return z +} + +func (x *Autos) All() *AutoScanner { + AutoPointers := x.selectAllAutos() + + scanner := newAutoScanner(AutoPointers) + return scanner +} + +// Iterate 'for x := range' syntax using the awesome golang 1.24 'iter' +func (x *Autos) IterAll() iter.Seq[*Auto] { + items := x.selectAllAutos() + // log.Println("Made All() Iter.Seq[] with length", len(items)) + return func(yield func(*Auto) bool) { + for _, v := range items { + if !yield(v) { + return + } + } + } +} +func (x *Autos) Delete(y *Auto) bool { + autoMu.Lock() + defer autoMu.Unlock() + + for i, _ := range x.Autos { + if x.Autos[i] == y { + x.Autos[i] = x.Autos[len(x.Autos)-1] + x.Autos = x.Autos[:len(x.Autos)-1] + return true + } + } + return false +} |
