-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberWithUnits.hpp
56 lines (48 loc) · 1.95 KB
/
NumberWithUnits.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
#pragma once
#include <iostream>
#include <fstream>
#include <map>
using std::string;
using std::map;
using std::pair;
using std::ifstream;
using std::ostream;
using std::istream;
namespace ariel {
static map <string, map <string, double>> unitsType;
const static double epsilon = 0.00001;
class NumberWithUnits {
private:
pair <double, string> _unit;
public:
NumberWithUnits(double val, const string &type);
static void read_units(ifstream &units_file) ;
// + -
NumberWithUnits operator+ () const;
NumberWithUnits operator- () const;
//prefix and postfix
NumberWithUnits & operator++ ();
NumberWithUnits operator++ (int);
NumberWithUnits & operator-- ();
NumberWithUnits operator-- (int);
//
NumberWithUnits& operator+= (const NumberWithUnits &num);
NumberWithUnits& operator-= (const NumberWithUnits &num);
//unary
NumberWithUnits operator+ (const NumberWithUnits &other_num)const;
NumberWithUnits operator- (const NumberWithUnits &other_num)const ;
// *
NumberWithUnits operator* (double factor) const;
friend NumberWithUnits operator* (double factor, const NumberWithUnits &num);
// < > =
bool operator> (const NumberWithUnits &other_num) const;
bool operator< (const NumberWithUnits &other_num) const;
bool operator== (const NumberWithUnits &other_num) const;
bool operator<= (const NumberWithUnits &other_num) const;
bool operator>= (const NumberWithUnits &other_num) const;
bool operator!= (const NumberWithUnits &other_num) const;
// << >>
friend ostream& operator<< (ostream& stream, const NumberWithUnits& num);
friend istream& operator>> (istream& stream, NumberWithUnits& num);
};
}