/* * 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("@(#) HashCode.cc (Gunther Schadow) 12/19/96"); #pragma implementation "HashCode.h" #include "HashCode.h" #include "logfile.h" #include "exception.h" #include "misc.h" #include "xios.h" HashCode::HashCode(const char *table[], int first, int last) : Code() { _first = first; _last = last; _table = table; _val = not_present; } const HashCode& HashCode::operator = (const HashCode &x) { Code::operator = (x); if(_table != x._table) FATAL("type mismatch %p for %p", x._table, _table); else _val = x._val; return *this; } bool HashCode::operator != (const char *x) const { return ! operator == (x); } HashCode::HashCode(int val, const char *table[], int first, int last) : Code() { _first = first; _last = last; _table = table; _val = val; switch(_val) { case not_present: Code::unset(); break; case null: Code::nullify(); break; default: if(valid(_val)) Code::set(); else ERROR("illegal value `%d'", val); } } const HashCode& HashCode::operator = (int val) { _val = val; switch(_val) { case not_present: Code::unset(); break; case null: Code::nullify(); break; default: if(valid(_val)) Code::set(); else ERROR("illegal value `%d'", val); } return *this; } int HashCode::lookup(const char *s) return val { if(s == NULL) return not_present; else if (*s == 0) return null; else { val = in_word_set(s, strlen(s)); if(val == -1) return invalid; else return val; } } HashCode::HashCode(const char *s, const char *table[], int first, int last) : Code() { _first = first; _last = last; _table = table; _val = lookup(s); switch(_val) { case not_present: Code::unset(); break; case null: Code::nullify(); break; case invalid: ERROR("illegal code `%s'", s); default: Code::set(); } } const HashCode& HashCode::operator = (const char *s) { _val = lookup(s); switch(_val) { case not_present: Code::unset(); break; case null: Code::nullify(); break; case invalid: ERROR("illegal code `%s'", s); default: Code::set(); } return *this; } HashCode::operator const char* () const { if (ispresent()) if (isnull()) return ""; else return _table[_val]; else return NULL; } bool HashCode::OK() const { if(_table == NULL) FATAL("no table"); else if(_val < not_present || _last < _val ) FATAL("illegal value %d", _val); return Code::OK(); }