cpp

package
v0.0.0-...-d5b5c0c Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PageSize = 4096
	MaxWidth = 72
)

Size constants.

Variables

This section is empty.

Functions

func CreateImplementations

func CreateImplementations(f fs.FS) error

CreateImplementations creates the files that don't rely on variable state.

func Execute

func Execute(f fs.FS, t *template.Template, args interface{}) error

TODO: Tighten up this package a lot.

Types

type ArrayWriter

type ArrayWriter struct {
	Into io.WriteCloser
	// contains filtered or unexported fields
}

ArrayWriter consumes bytes and formats them as a C++ array literal.

TODO: Set an unrecoverable error state to indicate that internal state may be unusable.

TODO: Support chunked write / partial lines from Write, etc. without weird line breaks.

TODO: Support Windows-style newline + carriage return?

TODO: Optimize for space? (Base64 / other solutions?)

TODO: Add benchmark tests.

func NewArrayWriter

func NewArrayWriter(over io.WriteCloser) ArrayWriter

NewArrayWriter constructs a new ArrayWriter over the given writer.

func (ArrayWriter) Close

func (a ArrayWriter) Close() error

Close calls Flush and then closes the underlying WriteCloser if successful. It may not be used after this.

func (ArrayWriter) Flush

func (a ArrayWriter) Flush() error

Flush flushes any remaining buffered contents to a.Into.

func (ArrayWriter) ReadFrom

func (a ArrayWriter) ReadFrom(some io.Reader) (total int64, err error)

ReadFrom consumes bytes from the given Reader, translating them into hex literals formatted for a C++ byte array literal.

The returned count is the number of bytes consumed from the Reader.

func (ArrayWriter) Write

func (a ArrayWriter) Write(some []byte) (int, error)

Write implements io.Writer on ArrayWriter for the purpose of Copy from an io.WriterTo.

type AssetDecl

type AssetDecl Resource

func (AssetDecl) Expand

func (a AssetDecl) Expand(r io.WriteCloser) error

type CMakeLists

type CMakeLists Resources

func (CMakeLists) Create

func (c CMakeLists) Create(f fs.FS) error

type CloserCloser

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

func (CloserCloser) Close

func (c CloserCloser) Close() error

type Creator

type Creator interface{ Create(fs.FS) error }

type DoneCloser

type DoneCloser struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

func (DoneCloser) Close

func (d DoneCloser) Close() error

func (DoneCloser) Count

func (d DoneCloser) Count() int64

func (DoneCloser) ReadFrom

func (d DoneCloser) ReadFrom(r io.Reader) (int64, error)

type ID

type ID Resources

func (ID) Create

func (i ID) Create(f fs.FS) error

Create a header defining an enum of IDs.

type MapperHdr

type MapperHdr Resources

func (MapperHdr) Create

func (m MapperHdr) Create(f fs.FS) error

type Mappings

type Mappings Resources

func (Mappings) Create

func (m Mappings) Create(f fs.FS) error

type Resource

type Resource struct {
	// Name is the original filename of the resource.  This is
	// needed for encoding the actual variable name in the var
	// declaration.
	Name string

	// TODO:
	// ID is a numeric ID assigned to the resource in case of a name
	// collision.
	ID int

	// Size is the full uncompressed size of the resource.
	Size int64

	// Into is the writer which the static asset will be written to.
	// Decl is the writer which will encode the variable declaration
	// referring to the asset.
	Into, Decl io.WriteCloser

	// CompCount is set in the Close method if the underlying "Into"
	// implements compress.Counter.
	CompCount int64

	// This handles closing the compressor / array writer first, and
	// then the file underlying it.
	CloserCloser
}

Resource represents a static asset or resource generated from a file.

func (*Resource) Close

func (r *Resource) Close() (err error)

func (*Resource) Count

func (r *Resource) Count() int64

func (*Resource) ReadFrom

func (r *Resource) ReadFrom(some io.Reader) (n int64, err error)

func (Resource) VarName

func (r Resource) VarName() string

VarName returns the cleansed name of the resource which may be used as a sanitized variable name in C++.

func (*Resource) Write

func (r *Resource) Write(some []byte) (n int, err error)

type ResourceManager

type ResourceManager struct {
	Resources
}

type Resources

type Resources []Resource

Resources implements sort.Interface.

func (Resources) Len

func (r Resources) Len() int

Resources implements sort.Interface.

func (Resources) Less

func (r Resources) Less(i, j int) bool

func (Resources) Swap

func (r Resources) Swap(i, j int)

type Target

type Target struct {
	fs.FS
	*sync.WaitGroup
	*sync.Pool
	// contains filtered or unexported fields
}

Target is a complete C++ static asset class.

TODO: cpp.Target is just a wrapper for a handful of C helpers.

func PrepareTarget

func PrepareTarget(over fs.FS, using compress.Maker) Target

func (Target) Create

func (t Target) Create(name string) (io.WriteCloser, error)

Create creates a Resource which the static asset will be written to, which uses a Compressor from the Target's pool.

func (Target) Finalize

func (t Target) Finalize() error

type TemplateID

type TemplateID int
const (
	TmpDecl TemplateID = iota
	TmpID
	TmpMapperHdr
	TmpMapperImpl
	TmpMappings
	TmpResourceHdr
	TmpResourceImpl

	TmpCMakeLists
	TmpGitignore
	TmpClangFormat
)

Template ID constants.

Jump to

Keyboard shortcuts

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