Calculator
Step 6
|
#include <number_impl.hpp>
Public Member Functions | |
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 |
std::shared_ptr< number_impl > | add (number_impl const &rhs) |
std::shared_ptr< number_impl > | subtract (number_impl const &rhs) |
std::shared_ptr< number_impl > | multiply (number_impl const &rhs) |
std::shared_ptr< number_impl > | divide (number_impl const &rhs) |
void | add_ref () |
void | del_ref () |
std::shared_ptr< number_impl > | promote (number_impl &rhs) const |
virtual std::shared_ptr < number_impl > | promote_to_void () |
virtual std::shared_ptr < number_impl > | promote_to_long () |
virtual std::shared_ptr < number_impl > | promote_to_rational () |
virtual std::shared_ptr < number_impl > | promote_to_double () |
Static Public Member Functions | |
static std::shared_ptr < number_impl > | read_library (std::istream &stream) |
Protected Member Functions | |
number_impl () | |
Private Member Functions | |
number_impl (number_impl const &n) | |
not implemented More... | |
number_impl & | operator= (number_impl const &n) |
not implemented More... | |
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 std::shared_ptr < number_impl > | do_add (number_impl const &rhs)=0 |
virtual std::shared_ptr < number_impl > | do_subtract (number_impl const &rhs)=0 |
virtual std::shared_ptr < number_impl > | do_multiply (number_impl const &rhs)=0 |
virtual std::shared_ptr < number_impl > | do_divide (number_impl const &rhs)=0 |
virtual std::shared_ptr < number_impl > | do_promote (number_impl &rhs) const =0 |
Private Attributes | |
std::size_t | refcount_ |
Definition at line 10 of file number_impl.hpp.
|
virtual |
Definition at line 9 of file number_impl.cpp.
|
inlineprotected |
Definition at line 54 of file number_impl.hpp.
|
private |
not implemented
std::shared_ptr< number_impl > number_impl::add | ( | number_impl const & | rhs | ) |
Definition at line 74 of file number_impl.cpp.
References do_add().
void number_impl::add_ref | ( | ) |
void number_impl::del_ref | ( | ) |
std::shared_ptr< number_impl > number_impl::divide | ( | number_impl const & | rhs | ) |
Definition at line 89 of file number_impl.cpp.
References do_divide().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by add().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by divide().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by equals().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by less().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by multiply().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by promote().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by save().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by subtract().
|
privatepure virtual |
Implemented in number_double, number_rational, number_long, and number_void.
Referenced by to_string().
bool number_impl::equals | ( | number_impl const & | rhs | ) | const |
Definition at line 62 of file number_impl.cpp.
References do_equals().
bool number_impl::less | ( | number_impl const & | rhs | ) | const |
Definition at line 68 of file number_impl.cpp.
References do_less().
std::shared_ptr< number_impl > number_impl::multiply | ( | number_impl const & | rhs | ) |
Definition at line 84 of file number_impl.cpp.
References do_multiply().
|
private |
not implemented
void number_impl::print | ( | std::ostream & | stream | ) | const |
Print in a human-readable form.
Definition at line 44 of file number_impl.cpp.
References to_string().
std::shared_ptr< 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
.
rhs | The right-hand operand of an arithmetic expression. |
Definition at line 56 of file number_impl.cpp.
References do_promote().
|
virtual |
Reimplemented in number_rational, and number_long.
Definition at line 112 of file number_impl.cpp.
Referenced by number_double::do_promote().
|
virtual |
Definition at line 102 of file number_impl.cpp.
Referenced by number_long::do_promote().
|
virtual |
Reimplemented in number_long.
Definition at line 107 of file number_impl.cpp.
Referenced by number_rational::do_promote().
|
virtual |
Reimplemented in number_double, number_rational, and number_long.
Definition at line 97 of file number_impl.cpp.
Referenced by number_void::do_promote().
|
static |
Read the number type from a library file, then create the proper kind of number.
Definition at line 18 of file number_impl.cpp.
Referenced by number::number().
void number_impl::save | ( | std::ostream & | stream | ) | const |
Save a number to a library file.
Definition at line 12 of file number_impl.cpp.
References do_save().
std::shared_ptr< number_impl > number_impl::subtract | ( | number_impl const & | rhs | ) |
Definition at line 79 of file number_impl.cpp.
References do_subtract().
std::string number_impl::to_string | ( | ) | const |
Convert to a string.
Definition at line 50 of file number_impl.cpp.
References do_to_string().
Referenced by print().
|
private |
Definition at line 73 of file number_impl.hpp.