/* * 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("@(#) UnitAtom.cc (Gunther Schadow) 12/19/96"); #pragma implementation "UnitAtom.h" #include "UnitAtom.h" #include #include #include #include #include #include #include const UnitAtom::unit_s UnitAtom::null_unit = {"1", NULL, NULL, NULL, {0, 0, 0, 0, 0, 0}, 1, 0}; static const char *units_db_base = "units.db"; static char *units_db_file = NULL; odbm::odbm_file UnitAtom::odbmf = odbm::null_dbf; u_int UnitAtom::odbm_obj_cnt = 0; UnitAtom::UnitAtom() : Code(), odbm(&unit.name, &unit.cnv_name, &unit.base, sizeof(unit.base) + sizeof(unit.coeff_mantissa) + sizeof(unit.coeff_exponent), &odbmf, &odbm_obj_cnt, ExternalCode::new_dbf_path(units_db_file, units_db_base)) { unit = null_unit; } UnitAtom::UnitAtom(int mode) : Code(), odbm(&unit.name, &unit.cnv_name, &unit.base, sizeof(unit.base) + sizeof(unit.coeff_mantissa) + sizeof(unit.coeff_exponent), &odbmf, &odbm_obj_cnt, ExternalCode::new_dbf_path(units_db_file, units_db_base), mode) { unit = null_unit; } UnitAtom::UnitAtom(const UnitAtom& x) : Code(), odbm(x) {} UnitAtom::UnitAtom(const char *name) : Code(), odbm(&unit.name, &unit.cnv_name, &unit.base, sizeof(unit.base) + sizeof(unit.coeff_mantissa) + sizeof(unit.coeff_exponent), &odbmf, &odbm_obj_cnt, ExternalCode::new_dbf_path(units_db_file, units_db_base)) { set(name); } UnitAtom::~UnitAtom() { if(unit.name != UnitAtom::null_unit.name && unit.name != NULL) free(unit.name); } UnitAtom &UnitAtom::operator = (const UnitAtom &x) { if(unit.name != UnitAtom::null_unit.name && unit.name != NULL) free(unit.name); odbm::operator = (x); return *this; } ostream & UnitAtom::unit_s::show(ostream &os) const { os << name << "("; return base.show(os) << ", " << coeff_mantissa << "*10^" << coeff_exponent << ", [" << (void*)cnv_from << ":" << (void*)cnv_to << "])"; } void UnitAtom::set(const char *s) { unit.name = strdup(s); // convert to lower case, I don't want this, but HL7 says so! for(char *p = unit.name; *p != 0; p++) *p = tolower((int)p); if(fetch(s) == FAIL) ERROR("unit `%s' not found", s); cnv_func::resolve(unit); Code::set(); } bool UnitAtom::lookup(const char *s) { if(fetch(s) == SUCCESS) { cnv_func::resolve(unit); return TRUE; } else return FALSE; }