util

package
v0.0.0-...-b0deb01 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseLocation

func ParseLocation(strval string) (uo.Location, error)

func ParseTagLine

func ParseTagLine(line string) (string, string, error)

func RangeExpression

func RangeExpression(e string, rng RandomSource) int

RangeExpression parses a string expression and returns a number, possibly randomly selected from a set or range.

Types

type ListFileReader

type ListFileReader struct {
	// contains filtered or unexported fields
}

ListFileReader reads ini-like list files

func (*ListFileReader) Errors

func (f *ListFileReader) Errors() []error

Errors returns the slice of all accumulated errors

func (*ListFileReader) HasErrors

func (f *ListFileReader) HasErrors() bool

HasErrors returns true if there are any errors

func (*ListFileReader) ReadNextSegment

func (f *ListFileReader) ReadNextSegment() *ListFileSegment

ReadNextSegment returns the next segment in the current reader stream or nil if the end of the stream has been reached. Use HasErrors and Errors to see if there were errors in execution.

func (*ListFileReader) ReadSegments

func (f *ListFileReader) ReadSegments(r io.Reader) []*ListFileSegment

ReadSegments returns all of the list segments from the reader. Use HasErrors and Errors to look for error conditions found within the file.

func (*ListFileReader) SkipCurrentSegment

func (f *ListFileReader) SkipCurrentSegment() bool

SkipCurrentSegment runs the file forward to the start of the next segment header. StreamNextSegment and ReadNextSegment are both sane to call after a call to SkipCurrentSegment. On error or end of file this function returns false. The error state can be inspected after this call with HasErrors and Errors.

func (*ListFileReader) StartReading

func (f *ListFileReader) StartReading(r io.Reader)

StartReading should be called to begin reading from a new reader

func (*ListFileReader) StreamNextEntry

func (f *ListFileReader) StreamNextEntry() string

StreamNextEntry continues reading the list file until the next non-empty, non-comment line. It expects this line to be an entry line (not a segment header). The empty string return value means no more entries in this segment, or an error condition. Use HasErrors and Errors to inspect the error state.

func (*ListFileReader) StreamNextSegmentHeader

func (f *ListFileReader) StreamNextSegmentHeader() string

StreamNextSegmentHeader continues reading the list file until the next non- empty, non-comment line. It expects this line to be a segment header in the form [SEGMENT_NAME] . The name of the segment is returned. The empty string means end of file or error. Use HasErrors and Errors to inspect the error state.

type ListFileSegment

type ListFileSegment struct {
	Name     string
	Contents []string
}

ListFileSegment represents one segment of the list file

type Queue

type Queue[V any] struct {
	// contains filtered or unexported fields
}

Queue manages a queue of values with a maximum capacity.

func NewQueue

func NewQueue[V any](cap int) *Queue[V]

NewQueue creates a new queue with the given capacity.

func (*Queue[V]) Dequeue

func (q *Queue[V]) Dequeue() V

Dequeue removes and returns the first element of the queue.

func (*Queue[V]) Enqueue

func (q *Queue[V]) Enqueue(v V) bool

Enqueue places a value at the end of the queue and returns true on success.

func (*Queue[V]) Length

func (q *Queue[V]) Length() int

Length returns the current number of values in the queue.

type RNG

type RNG struct {
	// contains filtered or unexported fields
}

RNG is a statefull, NON-thread-safe random number generator

func NewRNG

func NewRNG() *RNG

NewRNG returns a new RNG object seeded with the current millisecond time.

func (*RNG) Random

func (r *RNG) Random(min, max int) int

Random returns a random int value between min and max inclusive

func (*RNG) RandomBool

func (r *RNG) RandomBool() bool

RandomBool returns a random bool value

type RandomSource

type RandomSource interface {
	// Random returns a random int value between min and max inclusive
	Random(int, int) int
}

RandomSource is the interface sources of psuedo-random numbers that the Random* functions expect.

type Registry

type Registry[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Registry is a managed map that only supports Add and Get operations. This is used in the factory pattern as well as a few other things.

func NewRegistry

func NewRegistry[K comparable, V any](name string) *Registry[K, V]

NewRegistry returns a new Registry ready for use.

func (*Registry[K, V]) Add

func (r *Registry[K, V]) Add(k K, v V)

Add adds a value to the registry

func (*Registry[K, V]) Contains

func (r *Registry[K, V]) Contains(k K) bool

Contains returns true if the key is contained within the registry

func (*Registry[K, V]) Get

func (r *Registry[K, V]) Get(k K) (V, bool)

Get returns the value associated with key and has the same semantics as looking up a map key

func (*Registry[K, V]) GetName

func (r *Registry[K, V]) GetName() string

GetName returns the debug name of the registry

func (*Registry[K, V]) Map

func (r *Registry[K, V]) Map(fn func(K, V) error) []error

Map executes fn on every object in the pool and returns a slice of all non-nil return values.

type Slice

type Slice[T SliceElement] []T

Slice is a generic wrapper around slices of objects

func (Slice[T]) Append

func (s Slice[T]) Append(v T) Slice[T]

Append appends a value to the slice and returns the slice

func (Slice[T]) Contains

func (s Slice[T]) Contains(v T) bool

Contains returns true if the value v is found in the slice

func (Slice[T]) IndexOf

func (s Slice[T]) IndexOf(v T) int

IndexOf returns the index of the first of that value in the slice, or -1

func (Slice[T]) Insert

func (s Slice[T]) Insert(idx int, v T) Slice[T]

Insert inserts a value at the given index

func (Slice[T]) Remove

func (s Slice[T]) Remove(v T) Slice[T]

Remove returns the slice with the first value v removed

type SliceElement

type SliceElement interface {
	Serial() uo.Serial
}

type TagFileObject

type TagFileObject struct {
	// contains filtered or unexported fields
}

TagFileObject is the intermediate representation of an object in tag file format.

func NewTagFileObject

func NewTagFileObject() *TagFileObject

NewTagFileObject creates a new TagFileObject for the given tag file reader.

func (*TagFileObject) Errors

func (o *TagFileObject) Errors() []error

Errors returns a slice of all of the errors encountered by this object.

func (*TagFileObject) GetBool

func (o *TagFileObject) GetBool(name string, def bool) bool

GetBool returns the named property as a boolean value or the default if not found. This function may add errors to the internal error slice.

func (*TagFileObject) GetBounds

func (o *TagFileObject) GetBounds(name string, def uo.Bounds) uo.Bounds

GetBounds returns a uo.Bounds value. The default value is returned if the named tag is not found.

func (*TagFileObject) GetFloat

func (o *TagFileObject) GetFloat(name string, def float32) float32

GetFloat returns the named property as a float32 or the default if not found. This function may add errors to the internal error slice.

func (*TagFileObject) GetHex

func (o *TagFileObject) GetHex(name string, def uint32) uint32

GetHex returns the named property as an unsigned number or the default if not found. This function may add errors to the internal error slice.

func (*TagFileObject) GetLocation

func (o *TagFileObject) GetLocation(name string, def uo.Location) uo.Location

GetLocation returns a uo.Location value. The default value is returned if the named tag is not found.

func (*TagFileObject) GetNumber

func (o *TagFileObject) GetNumber(name string, def int) int

GetNumber returns the named property as a number or the default if not found. This function may add errors to the internal error slice.

func (*TagFileObject) GetObjectReferences

func (o *TagFileObject) GetObjectReferences(name string) []uo.Serial

GetObjectReferences returns a slice of uo.Serial values. nil is the default value. This function may add errors to the internal error slice.

func (*TagFileObject) GetString

func (o *TagFileObject) GetString(name, def string) string

GetString returns the named property as a string or the default if not found.

func (*TagFileObject) GetULong

func (o *TagFileObject) GetULong(name string, def uint64) uint64

GetULong returns the named property as a uint64 or the default if not found. This function may add errors to the internal error slice. Only use this for actual 64-bit values, like uo.Time.

func (*TagFileObject) HandlePropertyLine

func (o *TagFileObject) HandlePropertyLine(line string) error

HandlePropertyLine attempts to handle a single property line in the file.

func (*TagFileObject) HasErrors

func (o *TagFileObject) HasErrors() bool

HasErrors returns true if the object has encountered any errors.

func (*TagFileObject) InjectError

func (o *TagFileObject) InjectError(err error)

InjectError injects the error into this object's error slice. This is used by higher-level data loading functions to report out errors without panicing.

func (*TagFileObject) Map

func (o *TagFileObject) Map(fn func(name, value string) error) []error

Map executes fn for every key/value pair in the object.

func (*TagFileObject) Set

func (o *TagFileObject) Set(name, value string)

Set adds or overwrites the raw string associated with the name

func (*TagFileObject) TypeName

func (o *TagFileObject) TypeName() string

TypeName returns the type name of the object described

type TagFileReader

type TagFileReader struct {
	ListFileReader
}

TagFileReader reads objects from tag files.

func (*TagFileReader) ReadObject

func (f *TagFileReader) ReadObject() *TagFileObject

ReadObject returns the next object in the file, or nil if no more objects are in the current file. Use HasErrors and Errors to see if there were errors.

Jump to

Keyboard shortcuts

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