00001 /* 00002 * Number.h 00003 * 00004 * Smalltalk like class library for C++ 00005 * Abstract number. Header. 00006 * 00007 * Copyright (c) 2003, 2004 Milan Cermak, Martin Dvorak 00008 */ 00009 /* 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 #ifndef __NUMBER_H 00025 #define __NUMBER_H 00026 00027 #include <stdio.h> 00028 00029 #include <stlib/Object.h> 00030 00031 namespace Core { 00032 00033 class String; 00034 class Visitor; 00035 00036 class Integer; 00037 class Real; 00038 00039 class Number : public Object 00040 { 00041 public: 00042 /* Class-accessing protocol */ 00043 virtual String* className(void) const; 00044 00045 /* Instance creation protocol */ 00050 static Number *fromString(String *str); 00051 static Number *fromStringRadix(String *str, int radix); 00052 00053 /* Converting protocol */ 00054 virtual operator long(void) const; 00055 virtual long asLong(void) const; 00056 virtual operator unsigned long(void) const; 00057 virtual unsigned long asUnsignedLong(void) const; 00058 virtual operator long long(void) const; 00059 virtual long long asLongLong(void) const abstract; 00060 virtual operator double(void) const; 00061 virtual double asDouble(void) const abstract; 00062 00063 /* Comparing protocol */ 00064 virtual bool isEqual(const Object *object) const abstract; 00065 virtual bool isEqual(const Object &object) const 00066 { return Object::isEqual(object); } 00067 virtual bool isEqual(int arg) const; 00068 virtual bool isEqual(double arg) const; 00069 00070 /* Double dispatching protocol */ 00071 virtual bool isEqualToDouble(double argument) const abstract; 00072 virtual bool isEqualToLongLong(long long argument) const abstract; 00073 00074 /* Evaluating protocol */ 00075 virtual Number* negate(void) abstract; 00076 00077 /* Testing protocol */ 00078 virtual bool isInteger(void) const; 00079 00081 virtual bool isNegative(void) const; 00082 virtual bool isNumber(void) const; 00083 00085 virtual bool isPositive(void) const abstract; 00086 virtual bool isReal(void) const; 00087 00089 virtual bool isZero(void) const abstract; 00090 00091 /* Visiting protocol */ 00096 virtual void visitBy(Visitor *visitor); 00097 }; 00098 00099 }; 00100 00101 #endif /* __NUMBER_H */