number_impl Class Reference

#include <number_impl.hpp>

Inheritance diagram for number_impl:

number_double number_long number_rational number_void

List of all members.

Public Member Functions

 number_impl ()
virtual ~number_impl ()
void print (std::ostream &stream) const
std::string to_string () const
void save (std::ostream &stream) const
bool equals (number_impl const &rhs) const
bool less (number_impl const &rhs) const
number_impladd (number_impl const &rhs)
number_implsubtract (number_impl const &rhs)
number_implmultiply (number_impl const &rhs)
number_impldivide (number_impl const &rhs)
void add_ref ()
void del_ref ()
number_implpromote (number_impl &rhs) const
virtual number_implpromote_to_void ()
virtual number_implpromote_to_long ()
virtual number_implpromote_to_rational ()
virtual number_implpromote_to_double ()

Static Public Member Functions

static number_implread_library (std::istream &stream)

Private Member Functions

 number_impl (number_impl const &n)
 not implemented
number_imploperator= (number_impl const &n)
 not implemented
virtual std::string do_to_string () const =0
virtual void do_save (std::ostream &stream) const =0
virtual bool do_equals (number_impl const &rhs) const =0
virtual bool do_less (number_impl const &rhs) const =0
virtual number_impldo_add (number_impl const &rhs)=0
virtual number_impldo_subtract (number_impl const &rhs)=0
virtual number_impldo_multiply (number_impl const &rhs)=0
virtual number_impldo_divide (number_impl const &rhs)=0
virtual number_impldo_promote (number_impl &rhs) const =0

Private Attributes

std::size_t refcount_


Detailed Description

Definition at line 9 of file number_impl.hpp.


Constructor & Destructor Documentation

number_impl::number_impl (  )  [inline]

Definition at line 12 of file number_impl.hpp.

00012 : refcount_(1) {}

number_impl::~number_impl (  )  [virtual]

Definition at line 8 of file number_impl.cpp.

00009 {}

number_impl::number_impl ( number_impl const &  n  )  [private]

not implemented


Member Function Documentation

void number_impl::print ( std::ostream &  stream  )  const

Print in a human-readable form.

Definition at line 55 of file number_impl.cpp.

References to_string().

Referenced by number::print().

00057 {
00058   stream << to_string();
00059 }

std::string number_impl::to_string (  )  const

Convert to a string.

Definition at line 61 of file number_impl.cpp.

References do_to_string().

Referenced by print(), and number::to_string().

00063 {
00064   return do_to_string();
00065 }

void number_impl::save ( std::ostream &  stream  )  const

Save a number to a library file.

Definition at line 23 of file number_impl.cpp.

References do_save().

Referenced by number::save().

00025 {
00026   do_save(stream);
00027 }

number_impl * number_impl::read_library ( std::istream &  stream  )  [static]

Read the number type from a library file, then create the proper kind of number.

Definition at line 29 of file number_impl.cpp.

00030 {
00031   std::string type;
00032   if (not (stream >> type))
00033     throw calc_error("malformed library, missing number type");
00034 
00035   if (type == "void")
00036     return new number_void();
00037 
00038   if (type == "long") {
00039     long x;
00040     if (not (stream >> x))
00041       throw calc_error("malformed library, missing long value");
00042     return new number_long(x);
00043   }
00044 
00045   if (type == "double") {
00046     double x;
00047     if (not (stream >> x))
00048       throw calc_error("malformed library, missing double value");
00049     return new number_long(x);
00050   }
00051 
00052   throw calc_error("malformed library, unknown number type: " + type);
00053 }

bool number_impl::equals ( number_impl const &  rhs  )  const

Definition at line 73 of file number_impl.cpp.

References do_equals().

Referenced by number::equals().

00075 {
00076   return do_equals(rhs);
00077 }

bool number_impl::less ( number_impl const &  rhs  )  const

Definition at line 79 of file number_impl.cpp.

References do_less().

Referenced by number::less().

00081 {
00082   return do_less(rhs);
00083 }

number_impl * number_impl::add ( number_impl const &  rhs  ) 

Definition at line 85 of file number_impl.cpp.

References do_add().

Referenced by number::operator+().

00086 {
00087   return do_add(rhs);
00088 }

number_impl * number_impl::subtract ( number_impl const &  rhs  ) 

Definition at line 90 of file number_impl.cpp.

References do_subtract().

Referenced by number::operator-().

00091 {
00092   return do_subtract(rhs);
00093 }

number_impl * number_impl::multiply ( number_impl const &  rhs  ) 

Definition at line 95 of file number_impl.cpp.

References do_multiply().

Referenced by number::operator *().

00096 {
00097   return do_multiply(rhs);
00098 }

number_impl * number_impl::divide ( number_impl const &  rhs  ) 

Definition at line 100 of file number_impl.cpp.

References do_divide().

Referenced by number::operator/().

00101 {
00102   return do_divide(rhs);
00103 }

void number_impl::add_ref (  ) 

Definition at line 11 of file number_impl.cpp.

References refcount_.

Referenced by number_void::do_add(), number_void::do_divide(), number_void::do_multiply(), number_void::do_subtract(), number::number(), number::operator=(), promote_to_double(), promote_to_long(), promote_to_rational(), and promote_to_void().

00012 {
00013   ++refcount_;
00014 }

void number_impl::del_ref (  ) 

Definition at line 16 of file number_impl.cpp.

References refcount_.

Referenced by number::operator=(), and number::~number().

00017 {
00018   --refcount_;
00019   if (refcount_ == 0)
00020     delete this;
00021 }

number_impl * number_impl::promote ( number_impl rhs  )  const

Promote rhs to match the type of this number. This function uses double-dispatch, so this number calls a virtual promote_to_*() function that notifies rhs of the desired type. If the desired type is "larger" than the type of rhs, the promote_to_*() function returns a new number_impl of the desired type. Otherwise, the function returns rhs.

Parameters:
rhs The right-hand operand of an arithmetic expression.

Definition at line 67 of file number_impl.cpp.

References do_promote().

Referenced by number::coerce().

00069 {
00070   return do_promote(rhs);
00071 }

number_impl * number_impl::promote_to_void (  )  [virtual]

Reimplemented in number_long, number_rational, and number_double.

Definition at line 109 of file number_impl.cpp.

References add_ref().

Referenced by number_void::do_promote().

00110 {
00111   add_ref();
00112   return this;
00113 }

number_impl * number_impl::promote_to_long (  )  [virtual]

Definition at line 115 of file number_impl.cpp.

References add_ref().

Referenced by number_long::do_promote().

00116 {
00117   add_ref();
00118   return this;
00119 }

number_impl * number_impl::promote_to_rational (  )  [virtual]

Reimplemented in number_long.

Definition at line 121 of file number_impl.cpp.

References add_ref().

Referenced by number_rational::do_promote().

00122 {
00123   add_ref();
00124   return this;
00125 }

number_impl * number_impl::promote_to_double (  )  [virtual]

Reimplemented in number_long, and number_rational.

Definition at line 127 of file number_impl.cpp.

References add_ref().

Referenced by number_double::do_promote().

00128 {
00129   add_ref();
00130   return this;
00131 }

number_impl& number_impl::operator= ( number_impl const &  n  )  [private]

not implemented

virtual std::string number_impl::do_to_string (  )  const [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by to_string().

virtual void number_impl::do_save ( std::ostream &  stream  )  const [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by save().

virtual bool number_impl::do_equals ( number_impl const &  rhs  )  const [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by equals().

virtual bool number_impl::do_less ( number_impl const &  rhs  )  const [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by less().

virtual number_impl* number_impl::do_add ( number_impl const &  rhs  )  [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by add().

virtual number_impl* number_impl::do_subtract ( number_impl const &  rhs  )  [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by subtract().

virtual number_impl* number_impl::do_multiply ( number_impl const &  rhs  )  [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by multiply().

virtual number_impl* number_impl::do_divide ( number_impl const &  rhs  )  [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by divide().

virtual number_impl* number_impl::do_promote ( number_impl rhs  )  const [private, pure virtual]

Implemented in number_void, number_long, number_rational, and number_double.

Referenced by promote().


Member Data Documentation

std::size_t number_impl::refcount_ [private]

Definition at line 70 of file number_impl.hpp.

Referenced by add_ref(), and del_ref().


The documentation for this class was generated from the following files:
Generated on Sun Nov 30 10:06:54 2008 for Calculator by  doxygen 1.5.3