/* * 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. */ #ifndef PG_LINEARCODE_H_ #define PG_LINEARCODE_H_ #include #pragma interface #include #include /* * Linear Code are simple arrays. Code is looked up by a linear searching * through the array. Thus, each code is mapped to a consecutive integer * number. The first code is mapped to `first' and the last code i mapped * to `last' (which is equal to `size' - 1). Additional mappings are: * * (int) (const char*) * invalid code string `invalid' `' * code data was not given `not_set' `' * code data is null `null' `""' */ class LinearCode : public Code { public: const invalid = -3; const not_present = -2; const null = -1; const first = 0; void unset(); void nullify(); const LinearCode& operator = (int val); const LinearCode& operator = (const char *s); const LinearCode& operator = (const LinearCode&); operator const char* () const; operator int () const; bool operator == (const LinearCode&) const; bool operator != (const LinearCode&) const; bool operator == (const char *x) const; bool operator != (const char *x) const; bool operator == (int x) const; bool operator != (int x) const; bool OK() const; int lookup(const char *str) const; bool valid(int) const; protected: LinearCode(const char *table[], size_t size); LinearCode(int val, const char *table[], size_t size); LinearCode(const char *s, const char *table[], size_t size); private: int _val; const char **_table; int _size; void set(const char *); }; #ifndef OUTLINE # include "LinearCode.icc" #endif #endif /* !PG_LINEARCODE_H_ */