pro mgtmtag::_print, indent=indent
compile_opt strictarr
_indent = n_elements(indent) eq 0L ? '' : indent
attrnames = self.attributes->keys(count=nattrs)
attrvalues = self.attributes->values()
attrs = nattrs gt 0L ? strjoin(attrnames + '=' + attrvalues, ', ') : ''
print, self.type, attrs, format='(%"+ %s: %s")'
for c = 0L, self.children->count() - 1L do begin
child = self.children->get(position=c)
child->_print, indent=_indent + ' '
endfor
end
pro mgtmtag::getProperty, n_children=nChildren, n_attributes=nattributes, $
attribute_names=attributeNames, _ref_extra=e
compile_opt strictarr
if (arg_present(nchildren)) then nChildren = self.children->count()
if (arg_present(nattributes)) then nattributes = self.attributes->count()
if (arg_present(attributeNames)) then attributeNames = self.attributes->keys()
if (n_elements(e) gt 0) then begin
self->mgtmnode::getProperty, _strict_extra=e
endif
end
function mgtmtag::getChild, pos, last=last
compile_opt strictarr
if (keyword_set(last)) then begin
return, self.children->get(position=self.children->count() - 1L)
endif
return, self.children->get(position=pos)
end
pro mgtmtag::addChild, child
compile_opt strictarr
self.children->add, child
end
function mgtmtag::isEmpty
compile_opt strictarr
return, self.children->count() eq 0
end
pro mgtmtag::removeChild, pos, last=last
compile_opt strictarr
_pos = keyword_set(last) ? (self.children->count() - 1L) : pos
self.children->remove, position=_pos
end
function mgtmtag::getAttribute, name, found=found
compile_opt strictarr
return, self.attributes->get(name, found=found)
end
pro mgtmtag::addAttribute, name, value
compile_opt strictarr
self.attributes->put, name, value
end
function mgtmtag::_clone
compile_opt strictarr
tag = obj_new('MGtmTag', type=self.type)
for c = 0L, self.children->count() - 1L do begin
child = self.children->get(position=c)
tag->addChild, child->_clone()
endfor
keys = self.attributes->keys(count=nkeys)
for k = 0L, nkeys - 1L do begin
tag->addAttribute, keys[k], self.attributes->get(keys[k])
endfor
return, tag
end
pro mgtmtag::cleanup
compile_opt strictarr
obj_destroy, [self.children, self.attributes]
end
function mgtmtag::init, _extra=e
compile_opt strictarr
if (~self->mgtmnode::init(_strict_extra=e)) then return, 0
self.children = obj_new('MGcoArrayList', type=11, block_size=8)
self.attributes = obj_new('MGcoHashTable', key_type=7, value_type=7, $
array_size=8)
return, 1
end
pro mgtmtag__define
compile_opt strictarr
define = { MGtmTag, inherits MGtmNode, $
attributes: obj_new(), $
children: obj_new() $
}
end