This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RationalCalculator.hpp
83 lines (70 loc) · 1.97 KB
/
RationalCalculator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef CALCULATOR_RATIONALCALCULATOR_HPP
#define CALCULATOR_RATIONALCALCULATOR_HPP
#include <string>
#include "Calculator.hpp"
#include "boilerplate/precision/math_Rational.h"
/**
* A subclass of [[Calculator]] that deals exclusively with [[math::Rational]]s.
*
* Includes some extra commands for controlling precision, as well as the
* required subclass implementations of [[Calculator::is_int]] and
* [[Calculator::to_string]].
*/
class RationalCalculator : public Calculator<math::Rational> {
/**
* The precision rationals will be displayed as in
* [[RationalCalculator::to_string]].
*/
long precision = -1;
/**
* Whether or not to commatize the output (1000.123456 -> 1,000.123456)
*/
bool commatize = true;
/**
* Check if a rational is an integer. Clearly, rationals are integers if the
* denominator's absolute value is one.
*
* @param num The number to check,
* @return Whether it's an integer.
*/
bool is_int(const math::Rational & num) override;
/**
* Commatizes a string. For example, turns 100000 into 100,000 and 1000 into
* 1,000
*
* @param str The string to commatize
* @return
*/
std::wstring commatize_str(const std::wstring & str);
/**
* Registers commands and their corresponding help pages.
*/
void register_commands();
/**
* Adds the `commands` help page and adds it to the `starthere` help page.
*/
void generate_commands_help();
/**
* Registers all the custom functions
*/
void register_functions();
/**
* Generates help for the functions
*/
void generate_functions_help();
public:
/**
* Constructor. Set up some new commands, make some amends to existing help
* pages, create some new ones, etc.
*/
RationalCalculator();
/**
* Convert a [[math::Rational]] to a string, using the current
* [[RationalCalculator::precision]] setting.
*
* @param num The number to convert.
* @return
*/
std::wstring to_string(const math::Rational & num) override;
};
#endif //CALCULATOR_RATIONALCALCULATOR_HPP