nodes

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2018 License: GPL-3.0 Imports: 3 Imported by: 75

Documentation

Index

Constants

View Source
const (
	KindNil = Kind(1 << iota)
	KindObject
	KindArray
	KindString
	KindInt
	KindUint
	KindFloat
	KindBool
)
View Source
const (
	KindsValues = KindString | KindInt | KindUint | KindFloat | KindBool
	KindsNotNil = KindObject | KindArray | KindsValues
	KindsAny    = KindNil | KindsNotNil
)

Variables

This section is empty.

Functions

func Count

func Count(root Node, kinds Kind) int

Count returns a number of nodes with given kinds.

func Equal

func Equal(n1, n2 Node) bool

Equal compares two subtrees.

func WalkPreOrder

func WalkPreOrder(root Node, walk func(Node) bool)

WalkPreOrder visits all nodes of the tree in pre-order.

Types

type Array

type Array []Node

Array is an ordered list of nodes.

func (Array) Clone

func (m Array) Clone() Node

Clone returns a deep copy of an Array.

func (Array) CloneList

func (m Array) CloneList() Array

CloneList creates a copy of an Array without copying it's elements.

func (Array) Equal

func (m Array) Equal(n Node) bool

func (Array) EqualArray

func (m Array) EqualArray(m2 Array) bool

func (Array) Native

func (m Array) Native() interface{}

Native converts an array to a generic Go slice type ([]interface{}).

func (*Array) SetNode

func (m *Array) SetNode(n Node) error

type Bool

type Bool bool

Bool is a boolean value used in tree fields.

func (Bool) Clone

func (v Bool) Clone() Node

Clone returns a copy of the value.

func (Bool) Equal

func (v Bool) Equal(n Node) bool

func (Bool) Native

func (v Bool) Native() interface{}

Native converts the value to a bool.

func (*Bool) SetNode

func (v *Bool) SetNode(n Node) error

type Float

type Float float64

Float is a floating point value used in tree fields.

func (Float) Clone

func (v Float) Clone() Node

Clone returns a copy of the value.

func (Float) Equal

func (v Float) Equal(n Node) bool

func (Float) Native

func (v Float) Native() interface{}

Native converts the value to a float64.

func (*Float) SetNode

func (v *Float) SetNode(n Node) error

type Int

type Int int64

Int is a integer value used in tree fields.

func (Int) Clone

func (v Int) Clone() Node

Clone returns a copy of the value.

func (Int) Equal

func (v Int) Equal(n Node) bool

func (Int) Native

func (v Int) Native() interface{}

Native converts the value to an int64.

func (*Int) SetNode

func (v *Int) SetNode(n Node) error

type Kind

type Kind int

Kind is a node kind.

func KindOf

func KindOf(n Node) Kind

KindOf returns a kind of the node.

func (Kind) In

func (k Kind) In(k2 Kind) bool

func (Kind) Split

func (k Kind) Split() []Kind

func (Kind) String

func (k Kind) String() string

type Node

type Node interface {
	// Clone creates a deep copy of the node.
	Clone() Node
	Native() interface{}
	Equal(n2 Node) bool
	// contains filtered or unexported methods
}

Node is a generic interface for a tree structure.

Can be one of:

  • Object
  • Array
  • Value

func Apply

func Apply(root Node, apply func(n Node) (Node, bool)) (Node, bool)

Apply takes a root node and applies callback to each node of the tree recursively. Apply returns an old or a new node and a flag that indicates if node was changed or not. If callback returns true and a new node, Apply will make a copy of parent node and will replace an old value with a new one. It will make a copy of all parent nodes recursively in this case.

func ToNode

func ToNode(o interface{}, fallback ToNodeFunc) (Node, error)

ToNode converts objects returned by schema-less encodings such as JSON to Node objects.

type NodePtr

type NodePtr interface {
	Value
	SetNode(v Node) error
}

NodePtr is an assignable node pointer.

type Object

type Object map[string]Node

Object is a representation of generic node with fields.

func (Object) Clone

func (m Object) Clone() Node

Clone returns a deep copy of an Object.

func (Object) CloneObject

func (m Object) CloneObject() Object

CloneObject clones this node only, without deep copy of field values.

func (Object) Equal

func (m Object) Equal(n Node) bool

func (Object) EqualObject

func (m Object) EqualObject(m2 Object) bool

func (Object) Keys

func (m Object) Keys() []string

Keys returns a sorted list of node keys.

func (Object) Native

func (m Object) Native() interface{}

Native converts an object to a generic Go map type (map[string]interface{}).

func (Object) Set

func (m Object) Set(k string, v Node) Object

Set is a helper for setting node properties.

func (*Object) SetNode

func (m *Object) SetNode(n Node) error

type String

type String string

String is a string value used in tree fields.

func (String) Clone

func (v String) Clone() Node

Clone returns a copy of the value.

func (String) Equal

func (v String) Equal(n Node) bool

func (String) Native

func (v String) Native() interface{}

Native converts the value to a string.

func (*String) SetNode

func (v *String) SetNode(n Node) error

type ToNodeFunc

type ToNodeFunc func(interface{}) (Node, error)

type Uint

type Uint uint64

Uint is a unsigned integer value used in tree fields.

func (Uint) Clone

func (v Uint) Clone() Node

Clone returns a copy of the value.

func (Uint) Equal

func (v Uint) Equal(n Node) bool

func (Uint) Native

func (v Uint) Native() interface{}

Native converts the value to an int64.

func (*Uint) SetNode

func (v *Uint) SetNode(n Node) error

type Value

type Value interface {
	Node
	// contains filtered or unexported methods
}

Value is a generic interface for values stored inside the tree.

Can be one of:

  • String
  • Int
  • Uint
  • Float
  • Bool

Directories

Path Synopsis
Package nodesproto is a generated protocol buffer package.
Package nodesproto is a generated protocol buffer package.
pio

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL