#include "rbxs_pullattributeset.h" #include "rbxs_pullattribute.h" #include "rbxs_qname.h" #include "rbxs_pull.h" //*********************************************************************************** // GC //*********************************************************************************** void rbxs_pullattributeset_free(rbxs_pullattributeset *prbxs_pullattributeset) { if (prbxs_pullattributeset != NULL) { free(prbxs_pullattributeset); } } void rbxs_pullattributeset_mark(rbxs_pullattributeset *prbxs_pullattributeset) { if (prbxs_pullattributeset == NULL) return; if (!NIL_P(prbxs_pullattributeset->node)) rb_gc_mark(prbxs_pullattributeset->node); } //*********************************************************************************** // Methods //*********************************************************************************** VALUE rbxs_pullattributeset_include(VALUE self, VALUE which) { rbxs_pullattributeset *prbxs_pullattributeset; rbxs_pull *prbxs_pull; Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset); Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull); Check_Type(which, T_STRING); if (xmlTextReaderMoveToAttribute(prbxs_pull->reader,STR2CSTR(which))) return(Qtrue); else return(Qfalse); } VALUE rbxs_pullattributeset_empty(VALUE self) { rbxs_pullattributeset *prbxs_pullattributeset; rbxs_pull *prbxs_pull; Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset); Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull); return(xmlTextReaderHasAttributes(prbxs_pull->reader) ? Qfalse : Qtrue); } VALUE rbxs_pullattributeset_length(VALUE self) { rbxs_pullattributeset *prbxs_pullattributeset; rbxs_pull *prbxs_pull; Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset); Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull); return(NUM2INT(xmlTextReaderAttributeCount(prbxs_pull->reader))); } VALUE rbxs_pullattributeset_each(VALUE self) { rbxs_pullattributeset *prbxs_pullattributeset; rbxs_pull *prbxs_pull; Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset); Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull); while (xmlTextReaderMoveToNextAttribute(prbxs_pull->reader)) { xmlChar *ret; VALUE val; ret = xmlTextReaderValue(prbxs_pull->reader); val = rb_str_new2(ret); xmlFree(ret); rb_yield_values(2,rbxs_qname_new(cSimpleQName,prbxs_pullattributeset->node,RBXS_PARSER_TYPE_READER),val); } xmlTextReaderMoveToElement(prbxs_pull->reader); return(self); } VALUE rbxs_pullattributeset_get(VALUE self, VALUE which) { rbxs_pullattributeset *prbxs_pullattributeset; Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset); return(rbxs_pullattribute_new(cSimplePullAttribute,prbxs_pullattributeset->node,which)); } VALUE rbxs_pullattributeset_first(VALUE self) { return rbxs_pullattributeset_get(self,INT2NUM(0)); } VALUE rbxs_pullattributeset_last(VALUE self) { return rbxs_pullattributeset_get(self,INT2NUM(-1)); } //*********************************************************************************** // Constructors //*********************************************************************************** VALUE rbxs_pullattributeset_new(VALUE class, VALUE node) { rbxs_pullattributeset *prbxs_pullattributeset; prbxs_pullattributeset = (rbxs_pullattributeset *)malloc(sizeof(rbxs_pullattributeset)); if (prbxs_pullattributeset == NULL ) rb_raise(rb_eNoMemError, "No memory left for XML::Simple::PullAttributeSet struct"); prbxs_pullattributeset->node = node; return(Data_Wrap_Struct(class, rbxs_pullattributeset_mark, rbxs_pullattributeset_free, prbxs_pullattributeset)); } //*********************************************************************************** // Initialize class Node //*********************************************************************************** VALUE cSimplePullAttributeSet; void init_rbxs_pullattributeset(void) { cSimplePullAttributeSet = rb_define_class_under( cSimplePull, "AttributeSet", rb_cObject ); rb_define_method(cSimplePullAttributeSet, "length", rbxs_pullattributeset_length, 0); rb_define_method(cSimplePullAttributeSet, "empty?", rbxs_pullattributeset_empty, 0); rb_define_method(cSimplePullAttributeSet, "each", rbxs_pullattributeset_each, 0); rb_define_method(cSimplePullAttributeSet, "[]", rbxs_pullattributeset_get, 1); rb_define_method(cSimplePullAttributeSet, "first", rbxs_pullattributeset_first, 0); rb_define_method(cSimplePullAttributeSet, "last", rbxs_pullattributeset_last, 0); rb_define_method(cSimplePullAttributeSet, "include?", rbxs_pullattributeset_include, 1); }