2019-02-27 20:55:48 +00:00
|
|
|
package stack
|
|
|
|
|
|
|
|
// Boolean represents a boolean value on the stack
|
|
|
|
type Boolean struct {
|
|
|
|
*abstractItem
|
|
|
|
val bool
|
|
|
|
}
|
|
|
|
|
2019-03-15 22:30:25 +00:00
|
|
|
//NewBoolean returns a new boolean stack item
|
2019-03-16 21:44:03 +00:00
|
|
|
func NewBoolean(val bool) *Boolean {
|
2019-03-15 22:30:25 +00:00
|
|
|
return &Boolean{
|
|
|
|
&abstractItem{},
|
|
|
|
val,
|
2019-03-16 21:44:03 +00:00
|
|
|
}
|
2019-03-15 22:30:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 20:55:48 +00:00
|
|
|
// Boolean overrides the default implementation
|
|
|
|
// by the abstractItem, returning a Boolean struct
|
|
|
|
func (b *Boolean) Boolean() (*Boolean, error) {
|
|
|
|
return b, nil
|
|
|
|
}
|
2019-03-16 21:44:03 +00:00
|
|
|
|
|
|
|
// Value returns the underlying boolean value
|
|
|
|
func (b *Boolean) Value() bool {
|
|
|
|
return b.val
|
|
|
|
}
|
2019-03-28 19:26:55 +00:00
|
|
|
|
|
|
|
// Not returns a Boolean whose underlying value is flipped.
|
|
|
|
// If the value is True, it is flipped to False and viceversa
|
|
|
|
func (b *Boolean) Not() *Boolean {
|
|
|
|
return NewBoolean(!b.Value())
|
|
|
|
}
|
2019-03-29 21:22:45 +00:00
|
|
|
|
|
|
|
// And returns a Boolean whose underlying value is obtained
|
|
|
|
// by applying the && operator to two Booleans' values.
|
|
|
|
func (b *Boolean) And(a *Boolean) *Boolean {
|
|
|
|
c := b.Value() && a.Value()
|
|
|
|
return NewBoolean(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Or returns a Boolean whose underlying value is obtained
|
|
|
|
// by applying the || operator to two Booleans' values.
|
|
|
|
func (b *Boolean) Or(a *Boolean) *Boolean {
|
|
|
|
c := b.Value() || a.Value()
|
|
|
|
return NewBoolean(c)
|
|
|
|
}
|