Calculator Step 6

- Main Page
- Classes
- Files

- File List
- File Members

number.hpp
Go to the documentation of this file.
1 #ifndef NUMBER_HPP_
2 #define NUMBER_HPP_
3
4 #include <memory>
5 #include <ostream>
6 #include <string>
7
8 #include "rational.hpp"
9
11 class number_impl;
12
16 class number
17 {
18 public:
23 number();
30 number(int x);
35 number(long x);
40 number(long long x);
46 number(double x);
50 number(rational<long long> const& x);
51
52 number(number const&) = default;
53 number(number&&) = default;
54 number& operator=(number const&) = default;
55 number& operator=(number&&) = default;
56 ~number() = default;
57
59 number(std::istream& stream);
60
64 void save(std::ostream& stream) const;
65
71 bool equals(number b);
72
78 bool less(number b);
79
86 void coerce(number& rhs);
87
90 std::string to_string() const;
91
95 void print(std::ostream& stream);
96
102 number operator+(number rhs);
108 number operator-(number rhs);
114 number operator*(number rhs);
121 number operator/(number rhs);
122
123 private:
127 number(std::shared_ptr<number_impl> ptr);
128
129 std::shared_ptr<number_impl> pimpl_;
130 };
131
138 inline bool operator==(number a, number b)
139 {
140 return a.equals(b);
141 }
142
149 inline bool operator!=(number a, number b)
150 {
151 return not (a == b);
152 }
153
160 inline bool operator<(number a, number b)
161 {
162 return a.less(b);
163 }
164
171 inline bool operator<=(number a, number b)
172 {
173 return not(b < a);
174 }
175
182 inline bool operator>(number a, number b)
183 {
184 return b < a;
185 }
186
193 inline bool operator>=(number a, number b)
194 {
195 return not (a < b);
196 }
197
202 inline number operator-(number n)
203 {
204 return number{0} - n;
205 }
206
211 inline std::ostream& operator<<(std::ostream& stream, number n)
212 {
213 n.print(stream);
214 return stream;
215 }
216
217 #endif
number::pimpl_
std::shared_ptr< number_impl > pimpl_
Definition: number.hpp:129
number::operator-
number operator-(number rhs)
Definition: number.cpp:82
operator!=
bool operator!=(number a, number b)
Definition: number.hpp:149
number::to_string
std::string to_string() const
Definition: number.cpp:45
operator==
bool operator==(number a, number b)
Definition: number.hpp:138
number::operator+
number operator+(number rhs)
Definition: number.cpp:76
operator<<
std::ostream & operator<<(std::ostream &stream, number n)
Definition: number.hpp:211
rational.hpp
number
Definition: number.hpp:16
number::~number
~number()=default
number::operator=
number & operator=(number const &)=default
operator<=
bool operator<=(number a, number b)
Definition: number.hpp:171
number::number
number()
Definition: number.cpp:7
operator-
number operator-(number n)
Definition: number.hpp:202
number::print
void print(std::ostream &stream)
Definition: number.cpp:51
number::less
bool less(number b)
Definition: number.cpp:70
number::operator*
number operator*(number rhs)
Definition: number.cpp:88
rational< long long >
number::save
void save(std::ostream &stream) const
Definition: number.cpp:39
number::coerce
void coerce(number &rhs)
Definition: number.cpp:56
number::equals
bool equals(number b)
Definition: number.cpp:64
number_impl
Definition: number_impl.hpp:10
operator>
bool operator>(number a, number b)
Definition: number.hpp:182
number::operator/
number operator/(number rhs)
Definition: number.cpp:94
operator>=
bool operator>=(number a, number b)
Definition: number.hpp:193
operator<
bool operator<(number a, number b)
Definition: number.hpp:160