00001 /* 00002 * Real.h 00003 * 00004 * Smalltalk like class library for C++ 00005 * Native double wrapper. Header. 00006 * 00007 * Copyright (c) 2004 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 __REAL_H 00025 #define __REAL_H 00026 00027 #include <stlib/Number.h> 00028 00029 namespace Core { 00030 00031 class String; 00032 class Stream; 00033 00034 class Integer; 00035 00042 class Real : public Number 00043 { 00044 protected: 00045 double _value; 00046 00047 protected: 00048 Real(double v); 00049 00050 public: 00051 /* Class-accessing protocol */ 00052 virtual String *className(void) const; 00053 00054 /* Instance creation protocol */ 00055 static Real *value(double val); 00056 00057 /* Converting protocol */ 00058 virtual double asDouble(void) const; 00059 virtual long long asLongLong(void) const; 00060 00062 virtual Integer *rounded(void) const; 00063 00065 virtual Integer *truncated(void) const; 00066 00067 /* Comparing protocol */ 00068 virtual long hash(void) const; 00069 virtual bool isEqual(const Object *object) const; 00070 virtual bool isEqual(const Object &object) const 00071 { return Number::isEqual(object); } 00072 virtual bool isEqual(int arg) const 00073 { return Number::isEqual(arg); } 00074 virtual bool isEqual(double arg) const 00075 { return Number::isEqual(arg); } 00076 00077 /* Double dispatching protocol */ 00078 virtual bool isEqualToLongLong(long long arg) const; 00079 virtual bool isEqualToDouble(double arg) const; 00080 00081 /* Evaluating protocol */ 00082 virtual Number* negate(void); 00083 00084 /* Printing protocol */ 00085 virtual void printOn(Stream *stream) const; 00086 00087 /* Testing protocol */ 00088 virtual bool isReal(void) const; 00089 virtual bool isPositive(void) const; 00090 virtual bool isZero(void) const; 00091 }; 00092 00093 }; 00094 00095 #endif /* __REAL_H */