q5/mutable_xobject.go
aozhiwei 80edf5bfe5 1
2020-10-30 19:09:47 +08:00

52 lines
1.2 KiB
Go

package q5
type MutableXObject struct {
XObject
}
func NewMxoArray() *MutableXObject {
p := new(MutableXObject)
p.XObject._type = XOT_ARRAY
p.XObject._val = make([]*XObject, 0)
return p
}
func NewMxoObject() *MutableXObject {
p := new(MutableXObject)
p.XObject._type = XOT_OBJECT
p.XObject._val = make(map[string]*XObject)
return p
}
func (this *MutableXObject) PushXValue(val *XValue) *MutableXObject{
this.PushXObject(val.AsXObject())
return this
}
func (this *MutableXObject) PushXObject(val *XObject) *MutableXObject{
if this.XObject.GetType() != XOT_ARRAY {
panic("MutableXObject.PushXvalue type error")
}
array := this.XObject._val.([]*XObject)
this.XObject._val = append(array, val)
return this
}
func (this *MutableXObject) SetXValue(key string, val *XValue) *MutableXObject{
this.SetXObject(key, val.AsXObject())
return this
}
func (this *MutableXObject) SetXObject(key string, val *XObject) *MutableXObject{
if this.XObject.GetType() != XOT_OBJECT {
panic("MutableXObject.PushXvalue type error")
}
kvObj := this.XObject._val.(map[string]*XObject)
kvObj[key] = val
return this
}
func (this *MutableXObject) AsXObject() *XObject{
return &this.XObject
}