bool.go 4.43 KB
Newer Older
Eric Myhre's avatar
Eric Myhre committed
1 2 3
package mixins

import (
tavit ohanian's avatar
tavit ohanian committed
4
	ld "gitlab.dms3.io/ld/go-ld-prime"
Eric Myhre's avatar
Eric Myhre committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
)

// Bool can be embedded in a struct to provide all the methods that
// have fixed output for any int-kinded nodes.
// (Mostly this includes all the methods which simply return ErrWrongKind.)
// Other methods will still need to be implemented to finish conforming to Node.
//
// To conserve memory and get a TypeName in errors without embedding,
// write methods on your type with a body that simply initializes this struct
// and immediately uses the relevant method;
// this is more verbose in source, but compiles to a tighter result:
// in memory, there's no embed; and in runtime, the calls will be inlined
// and thus have no cost in execution time.
type Bool struct {
	TypeName string
}

tavit ohanian's avatar
tavit ohanian committed
22 23
func (Bool) Kind() ld.Kind {
	return ld.Kind_Bool
Eric Myhre's avatar
Eric Myhre committed
24
}
tavit ohanian's avatar
tavit ohanian committed
25 26
func (x Bool) LookupByString(string) (ld.Node, error) {
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupByString", AppropriateKind: ld.KindSet_JustMap, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
27
}
tavit ohanian's avatar
tavit ohanian committed
28 29
func (x Bool) LookupByNode(key ld.Node) (ld.Node, error) {
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupByNode", AppropriateKind: ld.KindSet_JustMap, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
30
}
tavit ohanian's avatar
tavit ohanian committed
31 32
func (x Bool) LookupByIndex(idx int64) (ld.Node, error) {
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupByIndex", AppropriateKind: ld.KindSet_JustList, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
33
}
tavit ohanian's avatar
tavit ohanian committed
34 35
func (x Bool) LookupBySegment(ld.PathSegment) (ld.Node, error) {
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "LookupBySegment", AppropriateKind: ld.KindSet_Recursive, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
36
}
tavit ohanian's avatar
tavit ohanian committed
37
func (Bool) MapIterator() ld.MapIterator {
Eric Myhre's avatar
Eric Myhre committed
38 39
	return nil
}
tavit ohanian's avatar
tavit ohanian committed
40
func (Bool) ListIterator() ld.ListIterator {
Eric Myhre's avatar
Eric Myhre committed
41 42
	return nil
}
43
func (Bool) Length() int64 {
Eric Myhre's avatar
Eric Myhre committed
44 45
	return -1
}
46
func (Bool) IsAbsent() bool {
Eric Myhre's avatar
Eric Myhre committed
47 48 49 50 51
	return false
}
func (Bool) IsNull() bool {
	return false
}
52
func (x Bool) AsInt() (int64, error) {
tavit ohanian's avatar
tavit ohanian committed
53
	return 0, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsInt", AppropriateKind: ld.KindSet_JustInt, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
54 55
}
func (x Bool) AsFloat() (float64, error) {
tavit ohanian's avatar
tavit ohanian committed
56
	return 0, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsFloat", AppropriateKind: ld.KindSet_JustFloat, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
57 58
}
func (x Bool) AsString() (string, error) {
tavit ohanian's avatar
tavit ohanian committed
59
	return "", ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsString", AppropriateKind: ld.KindSet_JustString, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
60 61
}
func (x Bool) AsBytes() ([]byte, error) {
tavit ohanian's avatar
tavit ohanian committed
62
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsBytes", AppropriateKind: ld.KindSet_JustBytes, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
63
}
tavit ohanian's avatar
tavit ohanian committed
64 65
func (x Bool) AsLink() (ld.Link, error) {
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AsLink", AppropriateKind: ld.KindSet_JustLink, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
66 67 68 69 70 71 72 73
}

// BoolAssembler has similar purpose as Bool, but for (you guessed it)
// the NodeAssembler interface rather than the Node interface.
type BoolAssembler struct {
	TypeName string
}

tavit ohanian's avatar
tavit ohanian committed
74 75
func (x BoolAssembler) BeginMap(sizeHint int64) (ld.MapAssembler, error) {
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "BeginMap", AppropriateKind: ld.KindSet_JustMap, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
76
}
tavit ohanian's avatar
tavit ohanian committed
77 78
func (x BoolAssembler) BeginList(sizeHint int64) (ld.ListAssembler, error) {
	return nil, ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "BeginList", AppropriateKind: ld.KindSet_JustList, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
79 80
}
func (x BoolAssembler) AssignNull() error {
tavit ohanian's avatar
tavit ohanian committed
81
	return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignNull", AppropriateKind: ld.KindSet_JustNull, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
82
}
83
func (x BoolAssembler) AssignInt(int64) error {
tavit ohanian's avatar
tavit ohanian committed
84
	return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignInt", AppropriateKind: ld.KindSet_JustInt, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
85 86
}
func (x BoolAssembler) AssignFloat(float64) error {
tavit ohanian's avatar
tavit ohanian committed
87
	return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignFloat", AppropriateKind: ld.KindSet_JustFloat, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
88 89
}
func (x BoolAssembler) AssignString(string) error {
tavit ohanian's avatar
tavit ohanian committed
90
	return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignString", AppropriateKind: ld.KindSet_JustString, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
91 92
}
func (x BoolAssembler) AssignBytes([]byte) error {
tavit ohanian's avatar
tavit ohanian committed
93
	return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignBytes", AppropriateKind: ld.KindSet_JustBytes, ActualKind: ld.Kind_Bool}
Eric Myhre's avatar
Eric Myhre committed
94
}
tavit ohanian's avatar
tavit ohanian committed
95 96
func (x BoolAssembler) AssignLink(ld.Link) error {
	return ld.ErrWrongKind{TypeName: x.TypeName, MethodName: "AssignLink", AppropriateKind: ld.KindSet_JustLink, ActualKind: ld.Kind_Bool}
97
}