Documentation
¶
Overview ¶
package enum provides an API for manipulating enumerations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AllRepresentations = []Representation{ Identifier, Tag, Number, Ordinal, }
AllRepresentations lists all 4 values in order.
Functions ¶
func QuotedString ¶
Types ¶
type Enums ¶
type Enums []Enum
Enums is a slice of Enum.
type FloatEnum ¶
FloatEnum is a specialisation for those enums that have float32 or float64 as the underlying type.
type FloatEnums ¶
type FloatEnums []FloatEnum
FloatEnums is a slice of FloatEnum.
func (FloatEnums) Floats ¶
func (es FloatEnums) Floats() []float64
Floats gets the values of the enums in the same order.
func (FloatEnums) Ordinals ¶
func (es FloatEnums) Ordinals() []int
Ordinals gets the ordinal values of the enums in the same order.
func (FloatEnums) Strings ¶
func (es FloatEnums) Strings() []string
Strings gets the string values of the enums in the same order.
func (FloatEnums) Tags ¶
func (es FloatEnums) Tags() []string
Tags gets the tag values of the enums in the same order. If no tags have been defined, this returns the same as Strings.
type IntEnum ¶
IntEnum is a specialisation for those enums that have int or similar as the underlying type.
type IntEnums ¶
type IntEnums []IntEnum
IntEnums is a slice of IntEnum.
type Representation ¶
type Representation int
const ( Identifier Representation = iota Tag Number // the value of the enumerant as a decimal number Ordinal )
func AsRepresentation ¶
func AsRepresentation(s string) (Representation, error)
AsRepresentation parses a string to find the corresponding Representation, accepting either one of the string values or a number. The input representation is determined by representationMarshalTextRep. It wraps Parse. The input case does not matter.
func MustParseRepresentation ¶
func MustParseRepresentation(s string) Representation
MustParseRepresentation is similar to AsRepresentation except that it panics on error. The input case does not matter.
func RepresentationOf ¶
func RepresentationOf(i int) Representation
RepresentationOf returns a Representation based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Representation is returned.
func (Representation) Int ¶
func (i Representation) Int() int
Int returns the int value, which is not necessarily the same as the ordinal. It serves to facilitate polymorphism (see enum.IntEnum).
func (Representation) IsValid ¶
func (i Representation) IsValid() bool
IsValid determines whether a Representation is one of the defined constants.
func (Representation) Ordinal ¶
func (i Representation) Ordinal() int
Ordinal returns the ordinal number of a Representation. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.
func (*Representation) Parse ¶
func (v *Representation) Parse(s string) error
Parse parses a string to find the corresponding Representation, accepting one of the string values or a number. The input representation is determined by representationMarshalTextRep. It is used by AsRepresentation. The input case does not matter.
Usage Example
v := new(Representation) err := v.Parse(s) ... etc
func (Representation) String ¶
func (i Representation) String() string
String returns the literal string representation of a Representation, which is the same as the const identifier.
func (Representation) Tag ¶
func (i Representation) Tag() string
Tag returns the string representation of a Representation. This is an alias for String.