/* * 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("@(#) SItyp.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "SItyp.h" #include "exception.h" #include "logfile.h" #include "xios.h" #include "ioext.h" #include #include #include #include "ParseTrace.h" SItyp::operator unsigned long() const { if(ispresent() && ! isnull()) return _int; else FATAL("access into non-present object"); } result SItyp::input(istream& is) { if(isdebug(is)) FATAL("can't read from debug stream"); LOGDEBUG("hl7/astm"); char *s = gets(is, getdel(is)); if( *s == 0 ) goto is_not_present; else if( strcmp(s, NULLVAL) == 0 ) goto is_null; else { /* clear the previous error, since strtol doesn't have another way * of indicating an error */ errno = 0; char *p; _int = strtoul(s,&p,10); if( errno == 0 ) if( *p == 0 ) // strtoul eat up everything goto is_present; else // junk found { record_parse_error("syntax error at `%s'", p); EPARSE("syntax error at `%s'", p); } else // error occured ERROS("strtol on `%s'", s); } FATAL("how did I come to this point??"); is_null: Primtype::nullify(); goto finish; is_not_present: Primtype::unset(); goto finish; is_present: Primtype::set(); goto finish; finish: delete [] s; return SUCCESS; } void SItyp::output(ostream& os) const { if(ishl7er(os) || isastmer(os)) { LOGDEBUG("hl7/astm"); if (ispresent()) { if (isnull()) os << NULLVAL; else os << dec << _int; } } else /* debug */ { LOGDEBUG("debug"); os << DSBGR0 "SItyp" DSBGR1; if (ispresent()) if (isnull()) os << DSNULL; else os << DSFRST << dec << _int; else os << DSNOPS; os << DSEGRP; } }