diff --git a/cb76668f8e404fb9094cf7f30da5ccf971c82e0e b/cb76668f8e404fb9094cf7f30da5ccf971c82e0e deleted file mode 100644 index a91dadc..0000000 --- a/cb76668f8e404fb9094cf7f30da5ccf971c82e0e +++ /dev/null @@ -1,774 +0,0 @@ -// `autogen:go.mod` - -module go.wit.com/toolkits/tree - -go 1.22 - -toolchain go1.23.4 - -require ( - go.wit.com/log v0.22.11 - go.wit.com/widget v1.1.28 - google.golang.org/protobuf v1.36.5 -) - -// `autogen:go.sum` - -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -go.wit.com/log v0.22.11 h1:BiJe+S81kWrMqW1QyZVu1Es2d//WG9FAcZQEhZkkM4c= -go.wit.com/log v0.22.11/go.mod h1:LsP0nAH4hZEf2qj/F5UmGQT0OEJ3Q5698/P8ZOI2JuE= -go.wit.com/widget v1.1.28 h1:xBrJBJ/5qGXTRE2uyOEcCV+6xAq8+3kBgqsJc1kqkiM= -go.wit.com/widget v1.1.28/go.mod h1:9P1d7NRtyFwEkMS3ccpTEyRqZaFnScbWvE4MB5ooeZI= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= -google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= - -// `autogen:widget.marshal.pb.go` - -// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. -// This file was autogenerated with autogenpb v0.0.50 2025-02-07_10:21:13_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 tree - -// `autogen:widget.pb.go` - -// Code modified by go.wit.com/apps/autogenpb DO NOT EDIT. -// -// user defined Mutex locks were auto added -// -// autogenpb version & build time: v0.0.50 2025-02-07_10:21:13_UTC -// autogenpb auto generates Sort(), Unique() and Marshal() functions -// go install go.wit.com/apps/autogenpb@latest - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.35.2-devel -// protoc v3.21.12 -// source: widget.proto - -// playing around with ideas here - -package tree // autogenpb changed the package name - -import ( - reflect "reflect" - sync "sync" - - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - _ "google.golang.org/protobuf/types/known/timestamppb" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Size struct { - sync.RWMutex // auto-added by go.wit.com/apps/autogenpb - - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Width int64 `protobuf:"varint,1,opt,name=width,proto3" json:"width,omitempty"` - Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` -} - -func (x *Size) Reset() { - *x = Size{} - mi := &file_widget_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Size) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Size) ProtoMessage() {} - -func (x *Size) ProtoReflect() protoreflect.Message { - mi := &file_widget_proto_msgTypes[0] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Size.ProtoReflect.Descriptor instead. -func (*Size) Descriptor() ([]byte, []int) { - return file_widget_proto_rawDescGZIP(), []int{0} -} - -func (x *Size) GetWidth() int64 { - if x != nil { - return x.Width - } - return 0 -} - -func (x *Size) GetHeight() int64 { - if x != nil { - return x.Height - } - return 0 -} - -type Location struct { - sync.RWMutex // auto-added by go.wit.com/apps/autogenpb - - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - X int64 `protobuf:"varint,1,opt,name=x,proto3" json:"x,omitempty"` - Y int64 `protobuf:"varint,2,opt,name=y,proto3" json:"y,omitempty"` -} - -func (x *Location) Reset() { - *x = Location{} - mi := &file_widget_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Location) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Location) ProtoMessage() {} - -func (x *Location) ProtoReflect() protoreflect.Message { - mi := &file_widget_proto_msgTypes[1] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Location.ProtoReflect.Descriptor instead. -func (*Location) Descriptor() ([]byte, []int) { - return file_widget_proto_rawDescGZIP(), []int{1} -} - -func (x *Location) GetX() int64 { - if x != nil { - return x.X - } - return 0 -} - -func (x *Location) GetY() int64 { - if x != nil { - return x.Y - } - return 0 -} - -type Tree struct { - sync.RWMutex // auto-added by go.wit.com/apps/autogenpb - - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Parent *Widget `protobuf:"bytes,1,opt,name=parent,proto3" json:"parent,omitempty"` - Children []*Widget `protobuf:"bytes,2,rep,name=children,proto3" json:"children,omitempty"` -} - -func (x *Tree) Reset() { - *x = Tree{} - mi := &file_widget_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Tree) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Tree) ProtoMessage() {} - -func (x *Tree) ProtoReflect() protoreflect.Message { - mi := &file_widget_proto_msgTypes[2] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Tree.ProtoReflect.Descriptor instead. -func (*Tree) Descriptor() ([]byte, []int) { - return file_widget_proto_rawDescGZIP(), []int{2} -} - -func (x *Tree) GetParent() *Widget { - if x != nil { - return x.Parent - } - return nil -} - -func (x *Tree) GetChildren() []*Widget { - if x != nil { - return x.Children - } - return nil -} - -type Widget struct { - sync.RWMutex // auto-added by go.wit.com/apps/autogenpb - - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Size *Size `protobuf:"bytes,3,opt,name=size,proto3" json:"size,omitempty"` - Location *Location `protobuf:"bytes,4,opt,name=location,proto3" json:"location,omitempty"` - Color string `protobuf:"bytes,5,opt,name=color,proto3" json:"color,omitempty"` -} - -func (x *Widget) Reset() { - *x = Widget{} - mi := &file_widget_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Widget) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Widget) ProtoMessage() {} - -func (x *Widget) ProtoReflect() protoreflect.Message { - mi := &file_widget_proto_msgTypes[3] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Widget.ProtoReflect.Descriptor instead. -func (*Widget) Descriptor() ([]byte, []int) { - return file_widget_proto_rawDescGZIP(), []int{3} -} - -func (x *Widget) GetId() int64 { - if x != nil { - return x.Id - } - return 0 -} - -func (x *Widget) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Widget) GetSize() *Size { - if x != nil { - return x.Size - } - return nil -} - -func (x *Widget) GetLocation() *Location { - if x != nil { - return x.Location - } - return nil -} - -func (x *Widget) GetColor() string { - if x != nil { - return x.Color - } - return "" -} - -type Widgets struct { - sync.RWMutex // auto-added by go.wit.com/apps/autogenpb - - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // `autogenpb:uuid:0331fcd7-3c8c-43e4-be1b-77db6a6bc58c` - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // `autogenpb:version:v1` - Widgets []*Widget `protobuf:"bytes,3,rep,name=Widgets,proto3" json:"Widgets,omitempty"` -} - -func (x *Widgets) Reset() { - *x = Widgets{} - mi := &file_widget_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Widgets) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Widgets) ProtoMessage() {} - -func (x *Widgets) ProtoReflect() protoreflect.Message { - mi := &file_widget_proto_msgTypes[4] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Widgets.ProtoReflect.Descriptor instead. -func (*Widgets) Descriptor() ([]byte, []int) { - return file_widget_proto_rawDescGZIP(), []int{4} -} - -func (x *Widgets) GetUuid() string { - if x != nil { - return x.Uuid - } - return "" -} - -func (x *Widgets) GetVersion() string { - if x != nil { - return x.Version - } - return "" -} - -func (x *Widgets) GetWidgets() []*Widget { - if x != nil { - return x.Widgets - } - return nil -} - -var File_widget_proto protoreflect.FileDescriptor - -var file_widget_proto_rawDesc = []byte{ - 0x0a, 0x0c, 0x77, 0x69, 0x64, 0x67, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, - 0x6d, 0x61, 0x69, 0x6e, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x34, 0x0a, 0x04, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x14, 0x0a, - 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x77, 0x69, - 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x26, 0x0a, 0x08, 0x4c, - 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x01, 0x79, 0x22, 0x56, 0x0a, 0x04, 0x54, 0x72, 0x65, 0x65, 0x12, 0x24, 0x0a, 0x06, 0x70, - 0x61, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, 0x61, - 0x69, 0x6e, 0x2e, 0x57, 0x69, 0x64, 0x67, 0x65, 0x74, 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, - 0x74, 0x12, 0x28, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x02, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x57, 0x69, 0x64, 0x67, 0x65, - 0x74, 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x22, 0x8e, 0x01, 0x0a, 0x06, - 0x57, 0x69, 0x64, 0x67, 0x65, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x73, 0x69, - 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, - 0x53, 0x69, 0x7a, 0x65, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x2a, 0x0a, 0x08, 0x6c, 0x6f, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6d, - 0x61, 0x69, 0x6e, 0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x6c, 0x6f, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x22, 0x5f, 0x0a, 0x07, - 0x57, 0x69, 0x64, 0x67, 0x65, 0x74, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, - 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x07, 0x57, 0x69, 0x64, 0x67, 0x65, 0x74, 0x73, - 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x57, 0x69, - 0x64, 0x67, 0x65, 0x74, 0x52, 0x07, 0x57, 0x69, 0x64, 0x67, 0x65, 0x74, 0x73, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_widget_proto_rawDescOnce sync.Once - file_widget_proto_rawDescData = file_widget_proto_rawDesc -) - -func file_widget_proto_rawDescGZIP() []byte { - file_widget_proto_rawDescOnce.Do(func() { - file_widget_proto_rawDescData = protoimpl.X.CompressGZIP(file_widget_proto_rawDescData) - }) - return file_widget_proto_rawDescData -} - -var file_widget_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_widget_proto_goTypes = []any{ - (*Size)(nil), // 0: main.Size - (*Location)(nil), // 1: main.Location - (*Tree)(nil), // 2: main.Tree - (*Widget)(nil), // 3: main.Widget - (*Widgets)(nil), // 4: main.Widgets -} -var file_widget_proto_depIdxs = []int32{ - 3, // 0: main.Tree.parent:type_name -> main.Widget - 3, // 1: main.Tree.children:type_name -> main.Widget - 0, // 2: main.Widget.size:type_name -> main.Size - 1, // 3: main.Widget.location:type_name -> main.Location - 3, // 4: main.Widgets.Widgets:type_name -> main.Widget - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name -} - -func init() { file_widget_proto_init() } -func file_widget_proto_init() { - if File_widget_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_widget_proto_rawDesc, - NumEnums: 0, - NumMessages: 5, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_widget_proto_goTypes, - DependencyIndexes: file_widget_proto_depIdxs, - MessageInfos: file_widget_proto_msgTypes, - }.Build() - File_widget_proto = out.File - file_widget_proto_rawDesc = nil - file_widget_proto_goTypes = nil - file_widget_proto_depIdxs = nil -} - -// `autogen:widget.sort.pb.go` - -// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. -// This file was autogenerated with autogenpb v0.0.50 2025-02-07_10:21:13_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 tree - -import ( - "fmt" - "sync" -) - -// a simple global lock -var widgetMu sync.RWMutex - -func (x *Widgets) fixUuid() { - if x == nil { - return - } - if x.Uuid == "0331fcd7-3c8c-43e4-be1b-77db6a6bc58c" { - return - } - x.Uuid = "0331fcd7-3c8c-43e4-be1b-77db6a6bc58c" - x.Version = "v1 go.wit.com/toolkits/tree" -} - -func NewWidgets() *Widgets { - x := new(Widgets) - x.Uuid = "0331fcd7-3c8c-43e4-be1b-77db6a6bc58c" - x.Version = "v1 go.wit.com/toolkits/tree" - return x -} - -// START SORT - -// DEFINE THE Widgets ITERATOR. -// itializes a new iterator. -func newWidgetsIterator(things []*Widgets) *WidgetsIterator { - return &WidgetsIterator{things: things} -} - -type WidgetsIterator struct { - sync.RWMutex // this isn't getting used properly yet? - - things []*Widgets - index int -} - -func (it *WidgetsIterator) Scan() bool { - if it.index >= len(it.things) { - return false - } - it.index++ - return true -} - -// Next() returns the next thing in the array -func (it *WidgetsIterator) Next() *Widgets { - if it.things[it.index-1] == nil { - fmt.Println("Next() error in WidgetsIterator", it.index) - } - return it.things[it.index-1] -} - -// END DEFINE THE ITERATOR - -// DEFINE THE Widget ITERATOR. -// itializes a new iterator. -func newWidgetIterator(things []*Widget) *WidgetIterator { - return &WidgetIterator{things: things} -} - -type WidgetIterator struct { - sync.RWMutex // this isn't getting used properly yet? - - things []*Widget - index int -} - -func (it *WidgetIterator) Scan() bool { - if it.index >= len(it.things) { - return false - } - it.index++ - return true -} - -// Next() returns the next thing in the array -func (it *WidgetIterator) Next() *Widget { - if it.things[it.index-1] == nil { - fmt.Println("Next() error in WidgetIterator", it.index) - } - return it.things[it.index-1] -} - -// END DEFINE THE ITERATOR - -// DEFINE THE Size ITERATOR. -// itializes a new iterator. -func newSizeIterator(things []*Size) *SizeIterator { - return &SizeIterator{things: things} -} - -type SizeIterator struct { - sync.RWMutex // this isn't getting used properly yet? - - things []*Size - index int -} - -func (it *SizeIterator) Scan() bool { - if it.index >= len(it.things) { - return false - } - it.index++ - return true -} - -// Next() returns the next thing in the array -func (it *SizeIterator) Next() *Size { - if it.things[it.index-1] == nil { - fmt.Println("Next() error in SizeIterator", it.index) - } - return it.things[it.index-1] -} - -// END DEFINE THE ITERATOR - -// DEFINE THE Location ITERATOR. -// itializes a new iterator. -func newLocationIterator(things []*Location) *LocationIterator { - return &LocationIterator{things: things} -} - -type LocationIterator struct { - sync.RWMutex // this isn't getting used properly yet? - - things []*Location - index int -} - -func (it *LocationIterator) Scan() bool { - if it.index >= len(it.things) { - return false - } - it.index++ - return true -} - -// Next() returns the next thing in the array -func (it *LocationIterator) Next() *Location { - if it.things[it.index-1] == nil { - fmt.Println("Next() error in LocationIterator", it.index) - } - return it.things[it.index-1] -} - -// END DEFINE THE ITERATOR - -// DEFINE THE Tree ITERATOR. -// itializes a new iterator. -func newTreeIterator(things []*Tree) *TreeIterator { - return &TreeIterator{things: things} -} - -type TreeIterator struct { - sync.RWMutex // this isn't getting used properly yet? - - things []*Tree - index int -} - -func (it *TreeIterator) Scan() bool { - if it.index >= len(it.things) { - return false - } - it.index++ - return true -} - -// Next() returns the next thing in the array -func (it *TreeIterator) Next() *Tree { - if it.things[it.index-1] == nil { - fmt.Println("Next() error in TreeIterator", it.index) - } - return it.things[it.index-1] -} - -// END DEFINE THE ITERATOR - -// safely returns a slice of pointers to the FRUIT protobufs -func (x *Widgets) allWidgets() []*Widget { - x.RLock() - defer x.RUnlock() - - // Create a new slice to hold pointers to each FRUIT - var tmp []*Widget - tmp = make([]*Widget, len(x.Widgets)) - for i, p := range x.Widgets { - tmp[i] = p // Copy pointers for safe iteration - } - - return tmp -} - -// safely returns a slice of pointers to the FRUIT protobufs -func (x *Tree) allChildren() []*Widget { - x.RLock() - defer x.RUnlock() - - // Create a new slice to hold pointers to each FRUIT - var tmp []*Widget - tmp = make([]*Widget, len(x.Children)) - for i, p := range x.Children { - tmp[i] = p // Copy pointers for safe iteration - } - - return tmp -} - -// safely returns a slice of pointers to the Widget protobufs -func (x *Widgets) selectAllWidgets() []*Widget { - x.RLock() - defer x.RUnlock() - - // Create a new slice to hold pointers to each Widget - var tmp []*Widget - tmp = make([]*Widget, len(x.Widgets)) - for i, p := range x.Widgets { - tmp[i] = p // Copy pointers for safe iteration - } - - return tmp -} - -// safely returns a slice of pointers to the Widget protobufs -func (x *Tree) selectAllChildren() []*Widget { - x.RLock() - defer x.RUnlock() - - // Create a new slice to hold pointers to each Widget - var tmp []*Widget - tmp = make([]*Widget, len(x.Children)) - for i, p := range x.Children { - tmp[i] = p // Copy pointers for safe iteration - } - - return tmp -} - -// END SORT - -func (x *Widgets) Len() int { - x.RLock() - defer x.RUnlock() - - return len(x.Widgets) -} - -// just a simple Append() shortcut (but still uses the mutex lock) -func (x *Widgets) Append(y *Widget) { - x.Lock() - defer x.Unlock() - - x.Widgets = append(x.Widgets, y) -} - -func (x *Widgets) All() *WidgetIterator { - WidgetPointers := x.selectAllWidgets() - - iterator := newWidgetIterator(WidgetPointers) - return iterator -} - -func (x *Widgets) Delete(y *Widget) bool { - x.Lock() - defer x.Unlock() - - for i, _ := range x.Widgets { - if x.Widgets[i] == y { - x.Widgets[i] = x.Widgets[len(x.Widgets)-1] - x.Widgets = x.Widgets[:len(x.Widgets)-1] - return true - } - } - return false -} - -// `autogen:`