Documentation ¶
Index ¶
- type Access
- type AccessNode
- type Collection
- type CollectionDef
- type GetArgsFn
- type GetFn
- type Incrementor
- type Iterator
- type Meta
- type NameMap
- func (m *NameMap[V]) Add(value V) bool
- func (m *NameMap[V]) Clear()
- func (m NameMap[V]) Get(name string) (V, bool)
- func (m NameMap[V]) Has(name string) bool
- func (m NameMap[V]) IsValid() bool
- func (m NameMap[V]) Len() int
- func (m *NameMap[V]) Rebuild()
- func (m *NameMap[V]) Remove(value V) bool
- func (m *NameMap[V]) RemoveName(name string) bool
- func (m *NameMap[V]) Rename(oldName string)
- func (m *NameMap[V]) Set(value V)
- type PathNode
- type Prop
- type Ptr
- type RefFn
- type SetFn
- type Type
- type TypeDef
- type TypedValue
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Access ¶
type Access struct { Base *Type Path []PathNode Nodes []AccessNode Cache []Value CacheRef []bool CanSet bool CanGet bool CanRef bool }
Access to value down a path starting from a given type.
func (Access) Last ¶
func (a Access) Last() *AccessNode
The last node in the access path. If there is no path then nil is returned.
func (Access) Ref ¶
Gets a reference to a value in the access path from the source. A reference points to an addressable value meaning changing the value directly is possible.
type AccessNode ¶
type AccessNode struct { Prop *Prop Key Value Type *Type Args []Value Get GetFn Ref RefFn Set SetFn }
A node along an access path with the necessary values.
type Collection ¶
type Collection interface { // The number of items in the collection. Len() int // Gets the value of the item in the collection with the given key Get(key Value) (Value, bool) // Sets the value of the item in the collection with the given key Set(key Value, value Value) bool // Adds the value to the collection Add(key Value, value Value) bool // Returns true if a value exists in the collection with the given key Contains(key Value) bool // Returns an iterator for the collection. Iterator() Iterator }
Something that can iterate or fetch values from a collection of key-values.
type CollectionDef ¶
type CollectionDef struct { // The key type. Key *Type // The value type. Value *Type // Returns a collection given a value. Collect func(value Value) Collection }
A definition for a type which holds key-values
type Incrementor ¶
type Incrementor[V constraints.Ordered] struct { // contains filtered or unexported fields }
Auto-incrementing value generator.
func NewIncrementor ¶
func NewIncrementor[V constraints.Ordered](start V, increment V) Incrementor[V]
Returns a new incrementor with the given initial value and how much to increment by on each Get() call.
type Iterator ¶
type Iterator interface { // Returns true if there is a next key & value HasNext() bool // Returns the next key and value Next() (value Value, key Value) // Removes the last key and value returned by Next and returns true. // If they cannot be removed or Next() was never called then false is returned. Remove() bool // Sets the value for the last key returned by Next and returns true. // If it cannot be set or Next() was never called then false is returned. Set(value Value) bool // Resets the iterator to the beginning of the key-values. Reset() }
Iterates over values and keys.
type NameMap ¶
type NameMap[V any] struct { Values []V // contains filtered or unexported fields }
A map of named values. This structure is useful when the most common operation is iteration where adding & removing are less common.
func NewNameMap ¶
func NewNameMap[V any](getName func(V) string, capacity int, insensitive bool, ordered bool) NameMap[V]
Creates a new named map optionally having the names be case insensitive and optionally retaining insertion order when remove is performed.
func (*NameMap[V]) Add ¶
Adds a named value to the map and returns true on success. False is returned if a value with the given name already exists.
func (NameMap[V]) IsValid ¶
Returns whether the internal state of the map is valid. The internal state of the map can be invalid if the Values was manipulated directly or if any of the names of the values has changed and a Rebuild or Update was not called.
func (*NameMap[V]) Rebuild ¶
func (m *NameMap[V]) Rebuild()
Handles the value being renamed given the old name. If the old name does not exist a rebuild is performed.
func (*NameMap[V]) RemoveName ¶
Removes the value with the name from the map.
type PathNode ¶
A path node represents a path starting with a base value and ending with a desired value.
func NewPathFromTokens ¶
Creates a new simple path from a stream of tokens.
type Prop ¶
type Prop struct { // The name of the property Name string // The type of the prop Type *Type // A function to return a copy of a prop value on a source value. Get GetArgsFn // A function to return a pointer to a prop value from a source value. Ref RefFn // A function to set a prop value on a source value. Set SetFn // A virtual prop is one that can be get or set but should be transferred. Virtual bool // The default value for a property. Why is this here? Default any // Metadata on the Prop Meta map[Meta]Value }
A property on a type
func (Prop) IsReadOnly ¶
type Type ¶
A lightweight type with an ID (auto-incrementing starting at 0) and a name. A definition can be attached to it later.
type TypeDef ¶
type TypeDef struct { // Creates a value of this type if possible. Create func() Value // If the type supports it this value is convertible to a string. ToString func(Value) string // If the type supports it this value is convertible from a string. FromString func(x string) (Value, error) // The properties on this type. Props NameMap[*Prop] // A definition if this type holds a collection of key-values. Collection *CollectionDef // Metadata on the Type Meta map[Meta]Value }
A definition for a type.
type TypedValue ¶
A value with given defined type.