/* * 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("@(#) RepFieldBase.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "RepFieldBase.h" #include "exception.h" #include "logfile.h" #include "misc.h" #include "xios.h" #include "ParseTrace.h" /* The pointer coercion operators are necessary! */ void RepFieldBase::output(ostream& os) const { const RepFieldBase *p; if(ishl7er(os) || isastmer(os)) { LOGDEBUG("hl7/astm"); char del = delims(os).getrep(); p = this; while(p->_car != NULL) { p->_car->output(os); p = (RepFieldBase *)p->_cdr; if(p->_car != NULL) os << del; else break; } } else /* debug */ { LOGDEBUG("debug"); os << DSBGR0 "RepFieldBase" << DSBGR1; if(_car != NULL) { os << DSFRST; _car->output(os); for(p = (RepFieldBase *)_cdr; p->_car!=NULL; p = (RepFieldBase *)p->_cdr) { os << DSSEPR; p->_car->output(os); } } else os << DSNOPS; os << DSEGRP; } LOGDEBUG("end"); } result RepFieldBase::input(istream& is) { RepFieldTracer tracer; if(isdebug(is)) FATAL("can't read from debug stream"); LOGDEBUG("hl7/astm"); const char *dset = getdel(is, Delimiters::replevel); RepFieldBase *q = this; do { tracer++; if(q->_car == NULL) { q->_car = q->ctora(); q->_cdr = q->ctord(); } q->_car->input(is); q = (RepFieldBase *)q->_cdr; } while(match(is, dset)); // Cut off the rest if(q->_car != NULL) { delete q->_car; q->_car = NULL; } if(q->_cdr != NULL) { delete q->_cdr; q->_cdr = NULL; } LOGDEBUG("end"); return SUCCESS; }