Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::Computable Class Reference

#include <Computable.h>

Inheritance diagram for util::Computable:

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

Detailed Description

Computable is a base class for all objects that can be used in arithmetic operations unaware of their type.

That is, Computable references can be used even though one does not know the actual types they point to.


Public Methods

virtual SmartPtr< Computable > plus (const Computable &c, bool switched=false) const throw (ComputationException&)
 Calculate the sum of this and c.

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

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

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

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

SmartPtr< Computable > operator[] (const Computable &c) const throw (ComputationException&)
 Array index operator calls arrayIndex(c).

virtual SmartPtr< Computable > arrayIndex (const Computable &c) const throw (ComputationException&)
 If this is an array of something, then return the cth something.

SmartPtr< Computable > operator() (const Computable &c) const throw (ComputationException&)
 Function call operator calls functionCall(c).

virtual SmartPtr< Computable > functionCall (const Computable &c) const throw (ComputationException&)
 If this is a thing that can be called, then call it with c as a parameter.

SmartPtr< Computable > operator- () const throw (ComputationException&)
 Negation operator calls negate().

virtual SmartPtr< Computable > negate () const throw (ComputationException&)
 If a negation can be defined for this, then return it.

SmartPtr< Computable > operator! () const throw (ComputationException&)
 Complement operator calls complement().

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

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

virtual SmartPtr< Computable > less (const Computable &c) const throw (ComputationException&)
 Check if this is less than c.

virtual SmartPtr< Computable > greater (const Computable &c) const throw (ComputationException&)
 Check if this is greater than c.

virtual SmartPtr< Computable > lessOrEqual (const Computable &c) const throw (ComputationException&)
 Check if this is less than or equal to c.

virtual SmartPtr< Computable > greaterOrEqual (const Computable &c) const throw (ComputationException&)
 Check if this is greater than or equal to c.

virtual SmartPtr< Computable > equal (const Computable &c) const throw (ComputationException&)
 Check if this is equal to c.

virtual SmartPtr< Computable > different (const Computable &c) const throw (ComputationException&)
 Check if this is different from c.

virtual SmartPtr< Computable > logAnd (const Computable &c) const throw (ComputationException&)
 Perform a logical and operation on this and c.

virtual SmartPtr< Computable > logOr (const Computable &c) const throw (ComputationException&)
 Perform a logical or operation on this and c.

virtual SmartPtr< Computable > binAnd (const Computable &c) const throw (ComputationException&)
 Calculate a binary AND operation on this and c.

virtual SmartPtr< Computable > binOr (const Computable &c) const throw (ComputationException&)
 Calculate a binary OR operation on this and c.

virtual SmartPtr< Computable > binXor (const Computable &c) const throw (ComputationException&)
 Calculate a binary XOR operation on this and c.

virtual operator bool () const throw (ComputationException&)
 Cast a computable object to the primitive type 'bool'.


Protected Methods

ComputationException createException (std::string op, const Computable &c) const


Member Function Documentation

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

If this is an array of something, then return the cth something.

As a default, if the parameter is a numeric type with a value of 0, then a clone of the object itself is returned. This way it is not necessary to distinguish between one-element vectors and scalars.

virtual int util::Computable::compare const Computable &    c const throw (ComputationException&) [inline, 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 in util::Number.

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

Check if this is different from c.

The default return type is Boolean, and it is formed by calling compare(c).

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

Calculate the quotient of this and c.

See also:
plus(Computable&)

Reimplemented in util::Number.

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

Check if this is equal to c.

The default return type is Boolean, and it is formed by calling compare(c).

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

Check if this is greater than c.

The default return type is Boolean, and it is formed by calling compare(c).

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

Check if this is greater than or equal to c.

The default return type is Boolean, and it is formed by calling compare(c).

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

Check if this is less than c.

The default return type is Boolean, and it is formed by calling compare(c).

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

Check if this is less than or equal to c.

The default return type is Boolean, and it is formed by calling compare(c).

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

Perform a logical and operation on this and c.

The default implementation tries to cast both objects to the primitive type 'bool'. It then performs a logical and operation on the primitive types and returns a new Boolean object containing th result.

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

Perform a logical or operation on this and c.

The default implementation tries to cast both objects to the primitive type 'bool'. It then performs a logical or operation on the primitive types and returns a new Boolean object containing th result.

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

Calculate the difference of this and c.

See also:
plus(Computable&)

Reimplemented in util::Number.

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

Calculate the modulus of this and c.

See also:
plus(Computable&)

Reimplemented in util::Number.

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

Calculate the product of this and c.

See also:
plus(Computable&)

Reimplemented in util::Number, and util::String.

virtual SmartPtr<Computable> util::Computable::plus const Computable &    c,
bool    switched = false
const throw (ComputationException&) [inline, 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 in util::Number, and util::String.


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.