elem_base.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // package elem_base -- базовый объект
  2. package elem_base
  3. import (
  4. "github.com/google/uuid"
  5. "gitp78su.ipnodns.ru/svi/goarch/lev0/alias"
  6. "gitp78su.ipnodns.ru/svi/goarch/lev0/types"
  7. "gitp78su.ipnodns.ru/svi/kern/v3"
  8. )
  9. // ElemBase -- базовый объект
  10. type ElemBase struct {
  11. Id_ alias.Id `yaml:"id"` // Идентификатор объекта
  12. Type_ alias.Type `yaml:"type"` // Тип объекта
  13. Coord_ types.ICoord `yaml:"coord"` // Координаты элемента
  14. }
  15. var (
  16. hassert = kern.GetFnHassert()
  17. )
  18. // NewElemBase -- возвращает новый базовый объект
  19. func NewElemBase(coord types.ICoord, type_ alias.Type) types.IElemBase {
  20. sf := &ElemBase{
  21. Coord_: coord,
  22. Id_: alias.Id(uuid.New().String()),
  23. Type_: type_,
  24. }
  25. sf.SelfCheck()
  26. return sf
  27. }
  28. // Coord -- возвращает координаты элемента
  29. //
  30. //go:fix inline
  31. func (sf *ElemBase) Coord() types.ICoord {
  32. return sf.Coord_
  33. }
  34. // Type -- возвращает тип объекта
  35. //
  36. //go:fix inline
  37. func (sf *ElemBase) Type() alias.Type {
  38. return sf.Type_
  39. }
  40. // Id -- возвращает ID объекта
  41. //
  42. //go:fix inline
  43. func (sf *ElemBase) Id() alias.Id {
  44. return sf.Id_
  45. }
  46. // SelfCheck -- самопроверка базового элемента
  47. func (sf *ElemBase) SelfCheck() {
  48. hassert(sf.Id_ != "", "ElemBase.SelfCheck(): Id_ is empty")
  49. hassert(sf.Type_ != "", "NewElemBase(): Type_ is empty")
  50. hassert(sf.Coord_ != nil, "NewElemBase(): Coord_ == nil")
  51. }