tree.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package model
  2. type AttrName string
  3. type LeafName string
  4. //Attribute of node
  5. type Attribute interface {
  6. String() string
  7. }
  8. //Leaf is node without children nodes
  9. type Leaf interface {
  10. Name() LeafName
  11. Attr(AttrName, ...Attribute) Attribute
  12. Parent(...Node) Node
  13. }
  14. //Node holds chidlren nodes, Carrier in CRM pattern
  15. type Node interface {
  16. Leaf
  17. Child(int) Leaf
  18. IndexOf(Leaf) int
  19. NofChild() int
  20. }
  21. //Model holds root node and constructs special riders
  22. type Model interface {
  23. Root() Node
  24. NewReader(...Reader) Reader
  25. NewWriter(...Writer) Writer
  26. }
  27. //Reader is a reading rider in CRM pattern
  28. //Reader stands on node and runs above it's child nodes
  29. type Reader interface {
  30. InitFrom(Reader)
  31. Base() Model
  32. Read() Leaf
  33. Eol() bool
  34. Pos(...Leaf) Leaf
  35. }
  36. //Writer is a modifying rider in CRM pattern
  37. //Writer stands on node and modifies it's children and attributes
  38. type Writer interface {
  39. InitFrom(Writer)
  40. Base() Model
  41. Pos(...Leaf) Leaf
  42. Write(Leaf, ...Leaf)
  43. WritePos(Leaf, ...Leaf) Leaf
  44. Attr(AttrName, interface{}) Writer //for fluid interface
  45. Delete(Leaf)
  46. }