00001
00002
00003 #include "xmlUtil/id/IdOpCompress.h"
00004 #include "xml/Dom.h"
00005
00006 namespace xmlUtil {
00007 IdOpCompress::IdOpCompress(DOM_Element cmprss) {
00008 from = xml::Dom::getAttribute(cmprss, "from");
00009 to = xml::Dom::getAttribute(cmprss, "to");
00010 }
00011
00012 NamedId *IdOpCompress::convert(const NamedId& inputId) {
00013
00014 int fromIx = inputId.hasField(from);
00015 int toIx = inputId.hasField(to);
00016
00017
00018
00019
00020
00021
00022 if (toIx < fromIx) return 0;
00023 if (fromIx < 0) return 0;
00024
00025 NamedId *newId = new NamedId(inputId, fromIx + 1);
00026
00027 NamedId::Fields *newFields = newId->m_fields;
00028 NamedId::Fields *inFields = inputId.m_fields;
00029
00030 for (unsigned int ix = toIx; ix < inFields->size(); ix++ ) {
00031 NamedId::IdField * aField = new NamedId::IdField( *((*inFields)[ix]) );
00032 newFields->push_back(aField);
00033 }
00034 return newId;
00035 }
00036 }