Example #1
0
static void writeAnn(struct gff3Ann *g3a, FILE *fh)
/* write an annotation record to the specified file */
{
writeFields(g3a, fh);
fputc('\t', fh);
writeAttrs(g3a, fh);
fputc('\n', fh);
}
Example #2
0
void iom_file::writeAttr(XmlWriter &out, IomObject &obj,int attr)
{
	int valueCount=obj->getAttrValueCount(attr);
	if(valueCount>0){
		const XMLCh *val=obj->getAttrPrim(attr,0);
		// not a primitive?
		if(!val){
			IomObject child=obj->getAttrObj(attr,0);
			// some special cases
			if(child->getTag()==tags::get_COORD()){
				// COORD
				out.startElement(attr,0,0);
				writeCoord(out,child);
				out.endElement(/*attr*/);
				if(valueCount>1){
					iom_issueerr("max one COORD value allowed");
				}
			}else if(child->getTag()==tags::get_POLYLINE()){
				// POLYLINE
				out.startElement(attr,0,0);
				writePolyline(out,child,false);
				out.endElement(/*attr*/);
				if(valueCount>1){
					iom_issueerr("max one POLYLINE value allowed");
				}
			}else if(child->getTag()==tags::get_MULTISURFACE()){
				// MULTISURFACE
				out.startElement(attr,0,0);
				writeSurface(out,child);
				out.endElement(/*attr*/);
				if(valueCount>1){
					iom_issueerr("max one MULTISURFACE value allowed");
				}
			}else{
				// normal case
				const XMLCh *ref=child->getRefOid();
				bool isRef= ref ? true : false;
				// Reference-attribute or Role or EmbeddedLink?
				if(isRef){
					const XMLCh *extref=0;
					const XMLCh *bid=0;
					XMLCh itoabuf[40];
					const XMLCh *orderpos=0;
					if(ref){
						if(child->getRefOrderPos()>0){
							XMLString::binToText( child->getRefOrderPos(),itoabuf,sizeof(itoabuf)-1,10);
							orderpos=itoabuf;
						}
					}
					bid=child->getRefBid();
					if(bid){
						extref=ref;
						ref=0;
					}
					XmlWrtAttr refAttr[]={
						 XmlWrtAttr(ref      ? ustrings::get_REF()     :0, ref,true)
						,XmlWrtAttr(extref   ? ustrings::get_EXTREF()  :0, extref,true)
						,XmlWrtAttr(bid      ? ustrings::get_BID()     :0, bid,true)
						,XmlWrtAttr(orderpos ? ustrings::get_ORDER_POS():0, orderpos)
					};
					out.startElement(attr,refAttr,sizeof(refAttr)/sizeof(refAttr[0]));
					if(child->getAttrCount()>0){
						out.startElement(child->getTag(),0,0);
						writeAttrs(out,child);
						out.endElement(/*child*/);
					}
					out.endElement(/*attr*/);
					if(valueCount>1){
						iom_issueerr("max one reference value allowed");
					}
				}else{
					// struct
					out.startElement(attr,0,0);
					int valuei=0;
					while(1){
						out.startElement(child->getTag(),0,0);
						writeAttrs(out,child);
						out.endElement(/*child*/);
						valuei++;
						if(valuei>=valueCount){
							break;
						}
						child=obj->getAttrObj(attr,valuei);
					}
					out.endElement(/*attr*/);
				}
			}

		}else{
			out.startElement(attr,0,0);
			out.characters(val);
			out.endElement(/*attr*/);
			if(valueCount>1){
				iom_issueerr("max one primitive-type value allowed");
			}
		}
	}
}
Example #3
0
/** write all baskets to an xml file.
 */
int iom_file::save()
{
	// build class/attribute list
	if(ilibasket.isNull()){
		iom_issueerr("model required to save data");
		return IOM_ERR_ILLEGALSTATE;
	}
	buildTagList();

	// read rest of file (before we overwrite it!)
	IomIterator bi=new iom_iterator(this);
	while(!bi->next_basket().isNull()){
		; // empty
	}

	// open file for write
	XmlWriter out;
	int ind=0;
	out.open(filename);out.printNewLine();

	// write header
	XmlWrtAttr trsfAttr[]={XmlWrtAttr(ustrings::get_xmlns(),ustrings::get_NS_INTERLIS22())};
	out.printIndent(ind);
	out.startElement(tags::get_TRANSFER(),trsfAttr,sizeof(trsfAttr)/sizeof(trsfAttr[0]));out.printNewLine();
	{
		ind++;
		out.printIndent(ind);
		XStr version("2.2");
		XmlWrtAttr headAttr[]={
			XmlWrtAttr(ustrings::get_VERSION(),version.unicodeForm())
			,XmlWrtAttr(ustrings::get_SENDER(),getHeadSecSender())
		};
		out.startElement(tags::get_HEADERSECTION(),headAttr,sizeof(headAttr)/sizeof(headAttr[0]));out.printNewLine();
		{
			ind++;
			out.printIndent(ind);
			out.startElement(tags::get_ALIAS(),0,0);out.printNewLine();
			{
				ind++;
				ind--;
			}
			out.printIndent(ind);
			out.endElement(/*ALIAS*/);out.printNewLine();
			out.printIndent(ind);
			out.startElement(tags::get_COMMENT(),0,0);
			out.characters(getHeadSecComment());
			out.endElement(/*COMMENT*/);out.printNewLine();
			ind--;
		}
		out.printIndent(ind);
		out.endElement(/*HEADERSECTION*/);out.printNewLine();
		ind--;
	}

	// write DATASECTION
	{
		ind++;
		out.printIndent(ind);
		out.startElement(tags::get_DATASECTION(),0,0);out.printNewLine();
		{
			ind++;

			// write all baskets
			for(std::vector<IomBasket>::size_type basketi=0;basketi<basketv.size();basketi++){
				IomBasket basket=basketv.at(basketi);
				const XMLCh *topics=basket->getTopics();
				const XMLCh *kind=encodeBasketKind(basket->getKind());
				const XMLCh *startstate=basket->getKind()!=IOM_FULL ? basket->getStartState() : 0;
				const XMLCh *endstate=basket->getKind()!=IOM_FULL ? basket->getEndState() : 0;
				const XMLCh *consistency=encodeConsistency(basket->getConsistency());
				XmlWrtAttr basketAttr[]={
					XmlWrtAttr(ustrings::get_BID(),basket->getOid(),true)
					,XmlWrtAttr(topics ? ustrings::get_TOPICS():0,topics)
					,XmlWrtAttr(kind ? ustrings::get_KIND():0 ,kind)
					,XmlWrtAttr(startstate ? ustrings::get_STARTSTATE():0,startstate)
					,XmlWrtAttr(endstate ? ustrings::get_ENDSTATE():0,endstate)
					,XmlWrtAttr(consistency ? ustrings::get_CONSISTENCY():0,consistency)
				};
				out.printIndent(ind);
				if(basket->getTag()==0){
					iom_issueerr("basket requires a TOPIC name");
					return IOM_ERR_ILLEGALSTATE;
				}
				out.startElement(basket->getTag(),basketAttr,sizeof(basketAttr)/sizeof(basketAttr[0]));out.printNewLine();
				{
					ind++;
					// write all objects
					IomIterator obji=new iom_iterator(basket);
					IomObject obj=obji->next_object();
					while(!obj.isNull()){
						out.printIndent(ind);
						const XMLCh *bid=obj->getBid();
						const XMLCh *ops=encodeOperation(obj->getOperation());
						const XMLCh *consistency=encodeConsistency(basket->getConsistency());
						XmlWrtAttr objAttr[]={
							XmlWrtAttr(ustrings::get_TID(),obj->getOid(),true)
							,XmlWrtAttr(bid ? ustrings::get_BID():0,bid,true)
							,XmlWrtAttr(ops ? ustrings::get_OPERATION():0 ,ops)
							,XmlWrtAttr(consistency ? ustrings::get_CONSISTENCY():0,consistency)
						};
						out.startElement(obj->getTag(),objAttr,sizeof(objAttr)/sizeof(objAttr[0]));
						writeAttrs(out,obj);
						out.endElement(/*object*/);out.printNewLine();
						obj=obji->next_object();
					}
					ind--;
				}
				out.printIndent(ind);
				out.endElement(/*basket*/);out.printNewLine();
			}
			ind--;
		}
		out.printIndent(ind);
		out.endElement(/*DATASECTION*/);out.printNewLine();
		ind--;
	}
	out.printIndent(ind);
	out.endElement(/*TRANSFER*/);out.printNewLine();
	// close file
	out.close();
	return 0;
}
Example #4
0
/** writes a polyline value.
 */
void iom_file::writePolyline(XmlWriter &out, IomObject &obj,bool hasLineAttr)
{
/*
     object: POLYLINE [INCOMPLETE]
       lineattr
         object: Model.Topic.LineAttr
           attr00
             11
       sequence // if incomplete; multi sequence values
         object: SEGMENTS
           segment
             object: COORD
               C1
                 102.0
               C2
                 402.0
           segment
             object: ARC
               C1
                 103.0
               C2
                 403.0
               A1
                 104.0
               A2
                 404.0
           segment
             object: Model.SplineParam
               SegmentEndPoint
                 object: COORD
                   C1
                     103.0
                   C2
                     403.0
               p0
                 1.0
               p1
                 2.0

		<POLYLINE>
			<LINEATTR>
				<Model.Topic.LineAttr>
					<attr00>11</attr00>
				</Model.Topic.LineAttr>
			</LINEATTR>
			<COORD>
				<C1>101.0</C1>
				<C2>401.0</C2>
			</COORD>
			<COORD>
				<C1>102.0</C1>
				<C2>402.0</C2>
			</COORD>
			<Model.SplineParam>
				<SegmentEndPoint>
					<COORD>
						<C1>103.0</C1>
						<C2>403.0</C2>
					</COORD>
				</SegmentEndPoint>
				<p0>1.0</p0>
				<p1>2.0</p1>
			</Model.SplineParam>
		</POLYLINE>
*/
	out.startElement(tags::get_POLYLINE(),0,0);
	if(hasLineAttr){
		IomObject lineattr=obj->getAttrObj(tags::get_lineattr(),0);
		if(!lineattr.isNull()){
			out.startElement(tags::get_LINEATTR(),0,0);
			out.startElement(lineattr->getTag(),0,0);
			writeAttrs(out,lineattr);
			out.endElement(/*lineattr*/);
			out.endElement(/*LINEATTR*/);
		}
	}
	bool clipped=obj->getConsistency()==IOM_INCOMPLETE;
	for(int sequencei=0;sequencei<obj->getAttrValueCount(tags::get_sequence());sequencei++){
		if(clipped){
			out.startElement(tags::get_CLIPPED(),0,0);
		}else{
			// an unclipped polyline should have only one sequence element
			if(sequencei>0){
				iom_issueerr("unclipped polyline with multi 'sequence' elements");
				break;
			}
		}
		IomObject sequence=obj->getAttrObj(tags::get_sequence(),sequencei);
		for(int segmenti=0;segmenti<sequence->getAttrValueCount(tags::get_segment());segmenti++){
			IomObject segment=sequence->getAttrObj(tags::get_segment(),segmenti);
			if(segment->getTag()==tags::get_COORD()){
				// COORD
				writeCoord(out,segment);
			}else if(segment->getTag()==tags::get_ARC()){
				// ARC
				writeArc(out,segment);
			}else{
				// custum line form
				out.startElement(segment->getTag(),0,0);
				writeAttrs(out,segment);
				out.endElement(/*segment*/);
			}

		}
		if(clipped){
			out.endElement(/*CLIPPED*/);
		}
	}
	out.endElement(/*POLYLINE*/);
}