/* * 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_UNIT_H_ #define PG_UNIT_H_ #include #pragma interface #include #include #include #include class prefices { public: static const int not_found; static const int best_fit; static int lookup(const char *sym, int pfxlen, const char **root); static int lookup(const char *sym, int *pfxlen, const char **root); private: static struct prefix_s { const char *name; int len; int exponent; } tab[]; }; class Unit : public Code { public: Unit(); Unit(const Unit&); Unit(const char*); ~Unit(); operator const char *() const; Unit& operator = (const Unit&); Unit& operator = (const char*); Unit operator * (const Unit&) const; Unit operator / (const Unit&) const; Unit& operator *= (const Unit&); Unit& operator /= (const Unit&); Unit& pow(int i); Unit& invert(); bool operator == (const Unit&) const; bool operator == (const char*) const; bool operator != (const Unit&) const; bool operator != (const char*) const; typedef base_unit_vector dimension; friend double convert(double value, const Unit &from, const Unit &to); friend const dimension &dim(const Unit&); const struct UnitAtom::unit_s *operator->() const; private: UnitAtom::unit_s unit; void set(const char *); static char *invert(const char*); static char *pow(const char*, int); static bool tounit(const char *sym, size_t len, int &pfx, UnitAtom &ua); }; #ifndef OUTLINE # include "Unit.icc" #endif #endif /* !PG_UNIT_H_ */