Пример #1
0
bool ClassHandler::get(Core::BaseObject *obj, void *n) {
	MemberNodeHandler *anyMemberHandler = NULL;
	bool anyIsOptional = true;

	for ( MemberList::iterator it = elements.begin();
	      it != elements.end(); ++it ) {
		if ( it->tag == "" ) {
			if ( anyMemberHandler == NULL ) {
				anyMemberHandler = &*it;
				anyIsOptional = it->optional;
			}
		}
		else if ( equalsTag(n, it->tag.c_str(), it->nameSpace.c_str()) ) {
			it->get(obj, n, this);
			isOptional = it->optional;
			memberHandler = &*it;
			return true;
		}
	}

	for ( MemberList::iterator it = childs.begin();
	      it != childs.end(); ++it ) {
		if ( it->tag == "" ) {
			if ( anyMemberHandler == NULL ) {
				anyMemberHandler = &*it;
				anyIsOptional = it->optional;
			}
		}
		else if ( equalsTag(n, it->tag.c_str(), it->nameSpace.c_str()) ) {
			it->get(obj, n, this);
			isOptional = it->optional;
			memberHandler = &*it;
			return true;
		}
	}

	if ( anyMemberHandler ) {
		memberHandler = anyMemberHandler;
		isOptional = anyIsOptional;
		isAnyType = true;
		return true;
	}

	return false;
}
Пример #2
0
bool ClassHandler::init(Core::BaseObject *obj, void *n, TagSet &mandatory) {
	xmlNodePtr node = reinterpret_cast<xmlNodePtr>(n);

	// Fill in mandatory tags
	for ( MemberList::iterator it = attributes.begin();
	      it != attributes.end(); ++it ) {
		if ( !it->optional ) mandatory.insert(it->tag);
	}

	for ( MemberList::iterator it = elements.begin();
	      it != elements.end(); ++it ) {
		if ( !it->optional && !it->tag.empty() ) mandatory.insert(it->tag);
	}

	for ( MemberList::iterator it = childs.begin();
	      it != childs.end(); ++it ) {
		if ( !it->optional && !it->tag.empty() ) mandatory.insert(it->tag);
	}

	if ( cdataUsed )
		cdata.get(obj, n, this);

	if ( attributes.empty() ) return true;

	for ( xmlAttrPtr attr = node->properties; attr != NULL; attr = attr->next ) {
		if ( attr->children ) {
			for ( MemberList::iterator it = attributes.begin();
			      it != attributes.end(); ++it ) {
				if ( equalsTag(attr, it->tag.c_str(), it->nameSpace.c_str()) ) {
					if ( it->get(obj, attr, this) && !it->optional ) {
						mandatory.erase(it->tag);
						break;
					}
				}
			}
		}
	}

	return true;
}