/* * 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("@(#) Code.cc (Gunther Schadow) 12/19/96"); #pragma implementation "Code.h" #include "Code.h" #include "DataTypeCode.h" #include "logfile.h" #include "exception.h" #include "misc.h" #include "xios.h" #include "ioext.h" Code::Code() : Primtype(DataTypeCode::IDval) {} result Code::input(istream& is) { if(isdebug(is)) FATAL("can't read from a debug stream"); char *sbuf = clws(trws(gets(is, getdel(is)))); LOGDEBUG("got `%s'", sbuf); if (*sbuf == 0) unset(); else set(sbuf); delete [] sbuf; return SUCCESS; } void Code::output(ostream& os) const { if(ishl7er(os) || isastmer(os)) { LOGDEBUG("hl7/astm"); if(ispresent()) if(isnull()) os << NULLVAL; else os << operator const char* (); } else { LOGDEBUG("debug"); os << DSBGR0 "Code" DSBGR1; if(!ispresent()) os << DSNOPS; else if(isnull()) os << DSNULL; else os << DSFRST DSBQUO << operator const char *() << DSEQUO; os << DSEGRP; } } bool Code::operator == (const Code &x) const { bool Ea = ispresent(); bool Eb = x.ispresent(); bool Na = isnull(); bool Nb = x.isnull(); if(Ea && Eb) // both must exist if(Na && Nb) // and either both are null return TRUE; else if(!Na && !Nb) // or both are non-null and have the same string value if(strcmp(operator const char *(),x.operator const char *()) == 0) return TRUE; else // otherwise not! return FALSE; else return FALSE; else return FALSE; }