From 4489076facea08d786235a90a19109cb1333a933 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 29 Dec 2018 01:13:31 -0500 Subject: [PATCH] engine: Add setters for the trait interfaces Turns out it's useful to wholesale set the entire struct. --- engine/autoedge.go | 4 ++++ engine/autogroup.go | 4 ++++ engine/metaparams.go | 4 ++++ engine/traits/autoedge.go | 6 ++++++ engine/traits/autogroup.go | 6 ++++++ engine/traits/meta.go | 6 ++++++ 6 files changed, 30 insertions(+) diff --git a/engine/autoedge.go b/engine/autoedge.go index 07f830d5..2e51931e 100644 --- a/engine/autoedge.go +++ b/engine/autoedge.go @@ -31,6 +31,10 @@ type EdgeableRes interface { // trait. AutoEdgeMeta() *AutoEdgeMeta + // SetAutoEdgeMeta lets you set all of the meta params for the automatic + // edges trait in a single call. + SetAutoEdgeMeta(*AutoEdgeMeta) + // UIDs includes all params to make a unique identification of this // object. UIDs() []ResUID // most resources only return one diff --git a/engine/autogroup.go b/engine/autogroup.go index 7a5b828e..f0005de6 100644 --- a/engine/autogroup.go +++ b/engine/autogroup.go @@ -34,6 +34,10 @@ type GroupableRes interface { // grouping trait. AutoGroupMeta() *AutoGroupMeta + // SetAutoGroupMeta lets you set all of the meta params for the + // automatic grouping trait in a single call. + SetAutoGroupMeta(*AutoGroupMeta) + // GroupCmp compares two resources and decides if they're suitable for //grouping. This usually needs to be unique to your resource. GroupCmp(res GroupableRes) error diff --git a/engine/metaparams.go b/engine/metaparams.go index 9a01d382..23ad2d0d 100644 --- a/engine/metaparams.go +++ b/engine/metaparams.go @@ -44,6 +44,10 @@ var DefaultMetaParams = &MetaParams{ type MetaRes interface { // MetaParams lets you get or set meta params for the resource. MetaParams() *MetaParams + + // SetMetaParams lets you set all of the meta params for the resource in + // a single call. + SetMetaParams(*MetaParams) } // MetaParams provides some meta parameters that apply to every resource. diff --git a/engine/traits/autoedge.go b/engine/traits/autoedge.go index bccd2757..1f6fe254 100644 --- a/engine/traits/autoedge.go +++ b/engine/traits/autoedge.go @@ -40,3 +40,9 @@ func (obj *Edgeable) AutoEdgeMeta() *engine.AutoEdgeMeta { } return obj.meta } + +// SetAutoEdgeMeta lets you set all of the meta params for the automatic edges +// trait in a single call. +func (obj *Edgeable) SetAutoEdgeMeta(meta *engine.AutoEdgeMeta) { + obj.meta = meta +} diff --git a/engine/traits/autogroup.go b/engine/traits/autogroup.go index 90e50318..a77d520c 100644 --- a/engine/traits/autogroup.go +++ b/engine/traits/autogroup.go @@ -47,6 +47,12 @@ func (obj *Groupable) AutoGroupMeta() *engine.AutoGroupMeta { return obj.meta } +// SetAutoGroupMeta lets you set all of the meta params for the automatic +// grouping trait in a single call. +func (obj *Groupable) SetAutoGroupMeta(meta *engine.AutoGroupMeta) { + obj.meta = meta +} + // GroupCmp compares two resources and decides if they're suitable for grouping. // You'll probably want to override this method when implementing a resource... // This base implementation assumes not, so override me! diff --git a/engine/traits/meta.go b/engine/traits/meta.go index 82156955..0e6e72da 100644 --- a/engine/traits/meta.go +++ b/engine/traits/meta.go @@ -38,3 +38,9 @@ func (obj *Meta) MetaParams() *engine.MetaParams { } return obj.meta } + +// SetMetaParams lets you set all of the meta params for the resource in a +// single call. +func (obj *Meta) SetMetaParams(meta *engine.MetaParams) { + obj.meta = meta +}