Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Core::Integer Class Reference

This class represents small integers, ie. More...

#include <Integer.h>

Inheritance diagram for Core::Integer:

Inheritance graph
[legend]
Collaboration diagram for Core::Integer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual StringclassName (void) const
 Answer receiver class name.
virtual double asDouble (void) const
virtual long long asLongLong (void) const
virtual long hash (void) const
 Answer object hash value.
virtual bool isEqual (const Object *object) const
 Compare receiver with given object.
virtual bool isEqual (const Object &object) const
 Compare receiver with given object.
virtual bool isEqual (int arg) const
virtual bool isEqual (double arg) const
virtual bool isEqualToDouble (double arg) const
virtual bool isEqualToLongLong (long long arg) const
virtual Numbernegate (void)
virtual void printOn (Stream *stream) const
 Print object identification into the stream.
virtual bool isInteger (void) const
virtual bool isPositive (void) const
 Answer whether the recevier is positive (including zero).
virtual bool isZero (void) const
 Answer whether the receiver represents a zero in it's domain.

Static Public Member Functions

static Integervalue (long long val)

Protected Member Functions

 Integer (long long val)

Protected Attributes

long long _value

Static Protected Attributes

static Array _instances

Detailed Description

This class represents small integers, ie.

native integers (long long int) that are of limited size. Generally a long wrapper for operations with other numbers. First 512 integers (0 to 511) are cached to avoid frequent instance creation. All methods are commented in the Number class.

See also:
Number

Definition at line 45 of file Integer.h.


Constructor & Destructor Documentation

Integer::Integer long long  val  )  [protected]
 

Definition at line 37 of file Integer.cc.

References _value.

Referenced by value().

00038 {
00039     _value = val;
00040 }


Member Function Documentation

double Integer::asDouble void   )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 63 of file Integer.cc.

References _value.

00064 {
00065     return (double) _value;
00066 }

long long Integer::asLongLong void   )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 68 of file Integer.cc.

References _value.

00069 {
00070     return _value;
00071 }

String * Integer::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Number.

Definition at line 43 of file Integer.cc.

00044 {
00045     return new String("Integer");
00046 }

long Integer::hash void   )  const [virtual]
 

Answer object hash value.

The value should be same for objects found equal with isEqual() method. So if you rewrite this method you should rewrite isEqual() method too.

Reimplemented from Core::Object.

Definition at line 74 of file Integer.cc.

References _value.

00075 {
00076     return (long) _value;
00077 }

virtual bool Core::Integer::isEqual double  arg  )  const [inline, virtual]
 

Reimplemented from Core::Number.

Definition at line 72 of file Integer.h.

References Core::Number::isEqual().

00073       { return Number::isEqual(arg); }

virtual bool Core::Integer::isEqual int  arg  )  const [inline, virtual]
 

Reimplemented from Core::Number.

Definition at line 70 of file Integer.h.

References Core::Number::isEqual().

00071       { return Number::isEqual(arg); }

virtual bool Core::Integer::isEqual const Object object  )  const [inline, virtual]
 

Compare receiver with given object.

Do not rewrite this method. It just a sugar for Object::isEqual(Object *).

  • object - object to compare receiver with

Reimplemented from Core::Number.

Definition at line 68 of file Integer.h.

References Core::Number::isEqual().

00069       { return Number::isEqual(object); }

bool Integer::isEqual const Object object  )  const [virtual]
 

Compare receiver with given object.

This method could compare objects with more sophisticated algorithm (eg. based on instance variables comparing or so).

If you rewrite this method you should rewrite hash() too.

  • object - object to compare receiver with

Reimplemented from Core::Number.

Definition at line 79 of file Integer.cc.

References _value.

00080 {
00081     if (!object->isNumber()) return false;
00082 
00083     return ((Number *) object)->isEqualToLongLong(_value);
00084 }

bool Integer::isEqualToDouble double  arg  )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 92 of file Integer.cc.

References _value.

00093 {
00094     return _value == arg;
00095 }

bool Integer::isEqualToLongLong long long  arg  )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 87 of file Integer.cc.

References _value.

00088 {
00089     return _value == arg;
00090 }

bool Integer::isInteger void   )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 113 of file Integer.cc.

00114 {
00115     return true;
00116 }

bool Integer::isPositive void   )  const [virtual]
 

Answer whether the recevier is positive (including zero).

Reimplemented from Core::Number.

Definition at line 118 of file Integer.cc.

References _value.

00119 {
00120     return _value >= 0;
00121 }

bool Integer::isZero void   )  const [virtual]
 

Answer whether the receiver represents a zero in it's domain.

Reimplemented from Core::Number.

Definition at line 123 of file Integer.cc.

References _value.

Referenced by negate().

00124 {
00125     return _value == 0;
00126 }

Number * Integer::negate void   )  [virtual]
 

Reimplemented from Core::Number.

Definition at line 98 of file Integer.cc.

References _value, isZero(), and value().

00099 {
00100     if (isZero()) return this;
00101     return Integer::value(-_value);
00102 }

void Integer::printOn Stream stream  )  const [virtual]
 

Print object identification into the stream.

Object identification is formed from its className() by default. But complicated classes (eg. collections) may print some other information.

  • stream - stream to print to.

Reimplemented from Core::Object.

Definition at line 105 of file Integer.cc.

References _value, and Core::Stream::nextPutAll().

00106 {
00107     char number[25];
00108     sprintf(number, "%lld", _value);
00109     stream->nextPutAll(number);
00110 }

Integer * Integer::value long long  val  )  [static]
 

Definition at line 49 of file Integer.cc.

References _instances, Core::Array::at(), FLY_INSTANCES, Integer(), nil, and Core::Array::put().

Referenced by Core::ByteArray::at(), Core::UTF8StreamEncoder::encodeTo(), Core::UCS2StreamEncoder::encodeTo(), Core::Number::fromStringRadix(), Core::ByteCharacterEncoder::initializeAsciiEncoder(), negate(), Core::Stream::nextBigEndianLong(), Core::Stream::nextBigEndianShort(), Core::Stream::nextLittleEndianLong(), Core::Stream::nextLittleEndianShort(), Core::Stream::nextPutBigEndianLong(), Core::Stream::nextPutBigEndianShort(), Core::Stream::nextPutLittleEndianLong(), Core::Stream::nextPutLittleEndianShort(), Core::EncodedStreamFactory::normalizedEncoding(), Core::ByteCharacterEncoder::parseLine(), Core::Real::rounded(), Core::Real::truncated(), and Core::Character::value().

00050 {
00051     if (val >= 0 && val < FLY_INSTANCES) {
00052         Integer *inst = dynamic_cast<Integer *>(_instances.at(val));
00053         if (inst == nil) {
00054             inst = new Integer(val);
00055             _instances.put(val, inst);
00056         }
00057         return inst;
00058     } else
00059         return new Integer(val);
00060 }


Member Data Documentation

Array Integer::_instances [static, protected]
 

Referenced by value().

long long Core::Integer::_value [protected]
 

Definition at line 48 of file Integer.h.

Referenced by asDouble(), asLongLong(), hash(), Integer(), isEqual(), isEqualToDouble(), isEqualToLongLong(), isPositive(), isZero(), negate(), and printOn().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:51:34 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2