Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::Number Class Reference

#include <Number.h>

Inheritance diagram for util::Number:

util::PrimitiveType util::Computable util::Object util::Number::FloatTemplate< T > util::Number::IntegerTemplate< T > List of all members.

Detailed Description

Number is the base class for all numeric types.

Each subclass of Number wraps a certain primitive numeric type. Numbers are Computable, i.e. arithmetic operations can be performed on the classes.


Public Types

typedef IntegerTemplate< char > Char
 A shorthand for a 8-bit integer.

typedef IntegerTemplate< short > Short
 A shorthand for a 16-bit integer.

typedef IntegerTemplate< int > Integer
 A shorthand for a 32-bit integer.

typedef IntegerTemplate< long > Long
 A shorthand for a 64-bit integer.

typedef FloatTemplate< float > Float
 A shorthand for a 32-bit floating point number.

typedef FloatTemplate< double > Double
 A shorthand for a 64-bit floating point number.


Public Methods

 operator bool () const throw (ComputationException&)
 Typecast to bool returns true when doubleValue() returns != 0.

SmartPtr< Computablecomplement () const throw (ComputationException&)
 If a complement can be defined for this, then return it.

 operator char () const
 operator short () const
 operator int () const
 operator long () const
 operator float () const
 operator double () const
virtual char charValue () const=0
virtual short shortValue () const=0
virtual int intValue () const=0
virtual long longValue () const=0
virtual float floatValue () const=0
virtual double doubleValue () const=0
SmartPtr< Computableplus (const Computable &c, bool switched=false) const throw (ComputationException&)
 Calculate the sum of this and c.

SmartPtr< Computableminus (const Computable &c) const throw (ComputationException&)
 Calculate the difference of this and c.

SmartPtr< Computablemultiply (const Computable &c, bool switched=false) const throw (ComputationException&)
 Calculate the product of this and c.

SmartPtr< Computabledivide (const Computable &c) const throw (ComputationException&)
 Calculate the quotient of this and c.

SmartPtr< Computablemodulus (const Computable &c) const throw (ComputationException&)
 Calculate the modulus of this and c.

int compare (const Computable &c) const throw (ComputationException&)
 Compare two computable objects.


Member Function Documentation

int util::Number::compare const Computable   c const throw (ComputationException&) [virtual]
 

Compare two computable objects.

This method should return a negative number, zero, or a positive number if c is larger than, equal to or smaller than this, respectively. Override this method if a simple one-dimensional comparison is sufficient for your custom type. If not, then you must override the less, greater etc. methods.

Reimplemented from util::Computable.

SmartPtr< Computable > util::Number::divide const Computable   c const throw (ComputationException&) [virtual]
 

Calculate the quotient of this and c.

See also:
plus(Computable&)

Reimplemented from util::Computable.

SmartPtr< Computable > util::Number::minus const Computable   c const throw (ComputationException&) [virtual]
 

Calculate the difference of this and c.

See also:
plus(Computable&)

Reimplemented from util::Computable.

SmartPtr< Computable > util::Number::modulus const Computable   c const throw (ComputationException&) [virtual]
 

Calculate the modulus of this and c.

See also:
plus(Computable&)

Reimplemented from util::Computable.

SmartPtr< Computable > util::Number::multiply const Computable   c,
bool    switched = false
const throw (ComputationException&) [virtual]
 

Calculate the product of this and c.

See also:
plus(Computable&)

Reimplemented from util::Computable.

SmartPtr< Computable > util::Number::plus const Computable   c,
bool    switched = false
const throw (ComputationException&) [virtual]
 

Calculate the sum of this and c.

Return a pointer to a newly allocated object which may be of any computable type. The caller is responsible for releasing the pointer. If switched is true, the result should be c + (this) instead of (this) + c, although for most types it should not make a difference. The switched helps developers as they do not need to implement the plus operation twice for any new type. The very same routine will calculate both String+Integer and Integer+String, for example, and there is no need to alter both classes.

Exceptions:
ComputationException  & if the operation cannot be performed. This exception is throw by default by all computation methods. Subclasses must override what is necessary.

Reimplemented from util::Computable.


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.