Calculator Step 6

- Main Page
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Member Functions | Private Attributes | List of all members
number_long Class Reference

`#include <number_impl.hpp>`

Inheritance diagram for number_long:

## Public Member Functions
| number_long (long long value)
long long | value () const
virtual std::shared_ptr < number_impl > | promote_to_void ()
virtual std::shared_ptr < number_impl > | promote_to_rational ()
virtual std::shared_ptr < number_impl > | promote_to_double ()
Public Member Functions inherited from 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
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_long ()

## Private Member Functions
virtual std::string | do_to_string () const
virtual void | do_save (std::ostream &stream) const
virtual bool | do_equals (number_impl const &rhs) const
virtual bool | do_less (number_impl const &rhs) const
virtual std::shared_ptr < number_impl > | do_add (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_subtract (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_multiply (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_divide (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_promote (number_impl &rhs) const

## Private Attributes
long long | value_

## Additional Inherited Members
Static Public Member Functions inherited from number_impl
static std::shared_ptr < number_impl > | read_library (std::istream &stream)
Protected Member Functions inherited from number_impl
| number_impl ()

## Detailed Description

Represent an integer. For the greatest range, always use `long` to represent integers.

Definition at line 98 of file number_impl.hpp.

## Constructor & Destructor Documentation

number_long::number_long | ( | long long | value | ) |
| inline

Definition at line 100 of file number_impl.hpp.

100 : number_impl(), value_(value) {}
number_long::value
long long value() const
Definition: number_impl.hpp:101
number_long::value_
long long value_
Definition: number_impl.hpp:116
number_impl::number_impl
number_impl()
Definition: number_impl.hpp:54

## Member Function Documentation

std::shared_ptr< number_impl > number_long::do_add | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 200 of file number_impl.cpp.

References value(), and value_.

201 {
202 return std::make_shared<number_long>(value_ + dynamic_cast<number_long const&>(rhs).value());
203 }
number_long::value
long long value() const
Definition: number_impl.hpp:101
number_long::value_
long long value_
Definition: number_impl.hpp:116
number_long
Definition: number_impl.hpp:98

std::shared_ptr< number_impl > number_long::do_divide | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 215 of file number_impl.cpp.

References value(), and value_.

216 {
217 long long right = dynamic_cast<number_long const&>(rhs).value();
218 if (right == 0)
219 throw calc_error{"division by zero"};
220 return std::make_shared<number_rational>(value_, right);
221 }
calc_error
Definition: calc_error.hpp:11
number_long::value
long long value() const
Definition: number_impl.hpp:101
number_long::value_
long long value_
Definition: number_impl.hpp:116
number_long
Definition: number_impl.hpp:98

bool number_long::do_equals | ( | number_impl const & | rhs | ) | const
| private virtual

Implements number_impl.

Definition at line 188 of file number_impl.cpp.

References value().

190 {
191 return value() == dynamic_cast<number_long const&>(rhs).value();
192 }
number_long::value
long long value() const
Definition: number_impl.hpp:101
number_long
Definition: number_impl.hpp:98

bool number_long::do_less | ( | number_impl const & | rhs | ) | const
| private virtual

Implements number_impl.

Definition at line 194 of file number_impl.cpp.

References value().

196 {
197 return value() < dynamic_cast<number_long const&>(rhs).value();
198 }
number_long::value
long long value() const
Definition: number_impl.hpp:101
number_long
Definition: number_impl.hpp:98

std::shared_ptr< number_impl > number_long::do_multiply | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 210 of file number_impl.cpp.

References value(), and value_.

211 {
212 return std::make_shared<number_long>(value_ * dynamic_cast<number_long const&>(rhs).value());
213 }
number_long::value
long long value() const
Definition: number_impl.hpp:101
number_long::value_
long long value_
Definition: number_impl.hpp:116
number_long
Definition: number_impl.hpp:98

std::shared_ptr< number_impl > number_long::do_promote | ( | number_impl & | rhs | ) | const
| private virtual

Implements number_impl.

Definition at line 223 of file number_impl.cpp.

References number_impl::promote_to_long().

225 {
226 return rhs.promote_to_long();
227 }
number_impl::promote_to_long
virtual std::shared_ptr< number_impl > promote_to_long()
Definition: number_impl.cpp:102

void number_long::do_save | ( | std::ostream & | stream | ) | const
| private virtual

Implements number_impl.

Definition at line 182 of file number_impl.cpp.

References value().

184 {
185 stream << "long " << value() << ' ';
186 }
number_long::value
long long value() const
Definition: number_impl.hpp:101

std::shared_ptr< number_impl > number_long::do_subtract | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 205 of file number_impl.cpp.

References value(), and value_.

206 {
207 return std::make_shared<number_long>(value_ - dynamic_cast<number_long const&>(rhs).value());
208 }
number_long::value
long long value() const
Definition: number_impl.hpp:101
number_long::value_
long long value_
Definition: number_impl.hpp:116
number_long
Definition: number_impl.hpp:98

std::string number_long::do_to_string | ( |  | ) | const
| private virtual

Implements number_impl.

Definition at line 174 of file number_impl.cpp.

References value().

176 {
177 std::ostringstream stream{};
178 stream << value();
179 return stream.str();
180 }
number_long::value
long long value() const
Definition: number_impl.hpp:101

std::shared_ptr< number_impl > number_long::promote_to_double | ( |  | ) |
| virtual

Reimplemented from number_impl.

Definition at line 239 of file number_impl.cpp.

References value().

240 {
241 return std::make_shared<number_double>(value());
242 }
number_long::value
long long value() const
Definition: number_impl.hpp:101

std::shared_ptr< number_impl > number_long::promote_to_rational | ( |  | ) |
| virtual

Reimplemented from number_impl.

Definition at line 234 of file number_impl.cpp.

References value().

235 {
236 return std::make_shared<number_rational>(value());
237 }
number_long::value
long long value() const
Definition: number_impl.hpp:101

std::shared_ptr< number_impl > number_long::promote_to_void | ( |  | ) |
| virtual

Reimplemented from number_impl.

Definition at line 229 of file number_impl.cpp.

230 {
231 return std::make_shared<number_void>();
232 }

long long number_long::value | ( |  | ) | const
| inline

Definition at line 101 of file number_impl.hpp.

References value_.

Referenced by do_add(), do_divide(), do_equals(), do_less(), do_multiply(), do_save(), do_subtract(), do_to_string(), promote_to_double(), and promote_to_rational().

101 { return value_; }
number_long::value_
long long value_
Definition: number_impl.hpp:116

## Member Data Documentation

long long number_long::value_
| private

Definition at line 116 of file number_impl.hpp.

Referenced by do_add(), do_divide(), do_multiply(), do_subtract(), and value().

The documentation for this class was generated from the following files:

- number_impl.hpp
- number_impl.cpp