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