2012-04-30 08:40:55 +02:00
|
|
|
package main
|
|
|
|
|
2012-05-06 08:21:31 +02:00
|
|
|
// Size corresponds to an expression that represents the number of bytes
|
|
|
|
// in some *thing*. Generally, sizes are used to allocate buffers and to
|
|
|
|
// inform X how big requests are.
|
|
|
|
// Size is basically a thin layer over an Expression that yields easy methods
|
|
|
|
// for adding and multiplying sizes.
|
2012-04-30 08:40:55 +02:00
|
|
|
type Size struct {
|
|
|
|
Expression
|
|
|
|
}
|
|
|
|
|
2012-05-06 08:21:31 +02:00
|
|
|
// newFixedSize creates a new Size with some fixed and known value.
|
2012-04-30 08:40:55 +02:00
|
|
|
func newFixedSize(fixed uint) Size {
|
2012-05-06 09:06:02 +02:00
|
|
|
return Size{&Value{v: int(fixed)}}
|
2012-04-30 08:40:55 +02:00
|
|
|
}
|
|
|
|
|
2012-05-06 08:21:31 +02:00
|
|
|
// newExpressionSize creates a new Size with some expression.
|
2012-04-30 08:40:55 +02:00
|
|
|
func newExpressionSize(variable Expression) Size {
|
|
|
|
return Size{variable}
|
|
|
|
}
|
|
|
|
|
2012-05-06 08:21:31 +02:00
|
|
|
// Add adds s1 and s2 and returns a new Size.
|
2012-04-30 08:40:55 +02:00
|
|
|
func (s1 Size) Add(s2 Size) Size {
|
|
|
|
return Size{newBinaryOp("+", s1, s2)}
|
|
|
|
}
|
|
|
|
|
2012-05-06 08:21:31 +02:00
|
|
|
// Multiply mupltiplies s1 and s2 and returns a new Size.
|
2012-04-30 08:40:55 +02:00
|
|
|
func (s1 Size) Multiply(s2 Size) Size {
|
|
|
|
return Size{newBinaryOp("*", s1, s2)}
|
|
|
|
}
|