common

package
Version: v0.0.0-...-1ddb0de Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package common package provides utility APIs that are used by other (more specialized) packages (e.g. mtl and obj) in the go-data-front library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommentEvent

type CommentEvent struct {

	// Comment holds the comment text that has been scanned.
	Comment string
}

CommentEvent indicates that a comment section has been scanned through.

type Event

type Event interface{}

Event represents an event that has occurred during scanning. This is the mechanism through which the Scanner API returns key MTL resource elements to the user.

This interface is subclassed and users should cast this interface to one of them in order to extract meaningful data.

Example event types: - CommentEvent - obj.ObjectEvent - mtl.MaterialEvent

type EventHandler

type EventHandler func(event Event) error

EventHandler function is passed to the Scanner by the API user in order to receive scanning events.

Implementations of this function should do a type switch on the event in order to determine the exact type and read meaningful data from it.

Implementations can return an error in order to stop any further processing of the Wavefront file.

type Line

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

Line represents a single logical line in a Wavefront file. You should get a hold of such a structure through the use of the LineScanner API.

func (Line) CommandName

func (l Line) CommandName() string

CommandName returns the name of the command. One should first use the IsCommand method to assure that this logical line is indeed a command.

func (Line) Comment

func (l Line) Comment() string

Comment returns the comment held by this logical line. One should first use IsComment to assure that this logical line is indeed a comment.

func (Line) FloatParam

func (l Line) FloatParam(index int) (float64, error)

FloatParam returns the parameter, converted to a float, at the specified index

func (Line) HasCommandName

func (l Line) HasCommandName(name string) bool

HasCommandName checks whether the command held by this logical line has the specified name. One should first use IsCommand to assure that this logical line is indeed a command.

func (Line) IntParam

func (l Line) IntParam(index int) (int64, error)

IntParam returns the parameter, converted to an integer, at the specified index

func (Line) IsBlank

func (l Line) IsBlank() bool

IsBlank returns whether the current logical line is blank

func (Line) IsCommand

func (l Line) IsCommand() bool

IsCommand returns whether the current logical line represents a command (e.g. usemtl, mtllib, vn, etc.)

func (Line) IsComment

func (l Line) IsComment() bool

IsComment returns whether the current logical line represents a comment

func (Line) ParamCount

func (l Line) ParamCount() int

ParamCount returns the number of parameters provided with the current command. Parameters are indexed from `0` up to the number (excluding) returned by this function.

func (Line) ReferenceSetParam

func (l Line) ReferenceSetParam(index int) ReferenceSet

ReferenceSetParam returns the parameter converted into a ReferenceSet

func (Line) StringParam

func (l Line) StringParam(index int) string

StringParam returns the parameter, converted to a string, at the specified index

type LineScanner

type LineScanner interface {
	// Scan scans the next logical line and returns whether that was successful.
	// A scan is not successful when the end of the file is reached or when an
	// error has occurred during scanning.
	Scan() bool

	// Err is used to get the scanning error, should one have actually occurred.
	// If `nil` is returned, then scanning was successful and one can proceed
	// and access the line through the Line method.
	Err() error

	// Line returns the last scanned logical line.
	Line() Line
}

LineScanner is an API that allows one to scan Wavefront files one logical line at a time.

func NewLineScanner

func NewLineScanner(reader io.Reader) LineScanner

NewLineScanner creates a new LineScanner instance that uses the specified io.Reader to read a Wavefront resource.

type ReferenceSet

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

ReferenceSet represents a set of references. This is represented in a Wavefront through a list of values separated by `/` symbols. It is possible to have blank references.

func (ReferenceSet) Count

func (s ReferenceSet) Count() int

Count returns the number of references in this reference set

func (ReferenceSet) FloatReference

func (s ReferenceSet) FloatReference(index int) (float64, error)

FloatReference returns the reference at the specified index location as float if possible to convert, otherwise it returns an error

func (ReferenceSet) IntReference

func (s ReferenceSet) IntReference(index int) (int64, error)

IntReference returns the reference at the specified index location as int if possible to convert, otherwise it returns an error

func (ReferenceSet) IsBlank

func (s ReferenceSet) IsBlank(index int) bool

IsBlank returns whether the reference at the specified index position is blank. (e.g. the reference at index 1 in a//c is blank)

func (ReferenceSet) StringReference

func (s ReferenceSet) StringReference(index int) string

StringReference returns the reference at the specified index location as string

type Scanner

type Scanner interface {

	// Performs a scan through the Wavefront resource that is
	// provided through the io.Reader.
	//
	// The EventHandler parameter is used by the implementation to
	// pass scanning events back to the user for processing.
	//
	// An error is returned should parsing fail for some reason or
	// if the user returns an error via the EventHandler.
	Scan(io.Reader, EventHandler) error
}

Scanner represents an event-based parser for Wavefront resources.

Implementations of this interface would usually scan through the Wavefront resource and act on each special element that is detected (e.g. when a normal or material declaration is parsed)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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