/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" IDENT("@(#) ASTMMessage.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "ASTMMessage.h" #include "xios.h" #include "misc.h" #include "logfile.h" #include "exception.h" #include "ParseTrace.h" void ASTMMessage::unset() { LOGDEBUG("unset"); Hea.unset(); SegStruc::unset(); Tra.unset(); } bool ASTMMessage::commit() { Hea.commit(); SegStruc::commit(); Tra.commit(); return TRUE; } result ASTMMessage::input(istream& is) { SegStrucTracer tracer(type()); if(isdebug(is)) FATAL("can't read from debug stream"); if(!istouched(is)) { LOGDEBUG("untouched stream"); streammarker spos(is.rdbuf()); if( Hea.input(is) != SUCCESS ) { unset(); is.rdbuf()->seekmark(spos); record_parse_error("could not read header"); EPARSE("could not read header"); return FAIL; } tracer++; } else /* istouched(is) means that the header is read already */ { LOGDEBUG("touched stream"); untouch(is); } if( SegStruc::input(is) != SUCCESS ) EPARSE("failed to read message body"); if( Tra.input(is) != SUCCESS ) { record_parse_error("could not read trailer"); EPARSE("could not read trailer"); return FAIL; } tracer++; if( Tra.Ter == TerCode::SenAbort ) { ERROR("message aborted by sender"); } return SUCCESS; } void ASTMMessage::output(ostream& os) const { if(isastmer(os) || ishl7er(os)) { LOGDEBUG("astm/hl7"); if(ispresent()) { Hea.output(os); SegStruc::output(os); Tra.output(os); } } else { LOGDEBUG("debug"); os << DSBGR0 << "ASTMmsg" << DSBGR1; if (ispresent()) { os << DSFRST << Hea; SegStruc::output(os); os << DSSEPR << Tra << DSEGRP; } } }