ScummVM API documentation
fixed.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef BAGEL_BOFLIB_FIXED_H
24 #define BAGEL_BOFLIB_FIXED_H
25 
26 #include "bagel/boflib/object.h"
27 #include "bagel/boflib/misc.h"
28 
29 namespace Bagel {
30 
31 class CBofFixed : public CBofObject {
32 private:
33  Fixed _lVal;
34  CBofFixed(const Fixed Arg) {
35  _lVal = Arg;
36  }
37 
38 public:
39  // Constructors
40  CBofFixed() {
41  _lVal = 0L;
42  }
43  CBofFixed(const CBofFixed &Arg) {
44  _lVal = Arg._lVal;
45  }
46  CBofFixed(const int Arg) {
47  _lVal = (Fixed)(((long)(Arg)) << 16);
48  }
49  CBofFixed(const double Arg) {
50  _lVal = (Fixed)(Arg * (1 << 16));
51  }
52 
53  // Operators
54  // inline CBofFixed operator =(const CBofFixed& Arg) const;
55  CBofFixed operator+(const CBofFixed &Arg) const {
56  return _lVal + Arg._lVal;
57  }
58  CBofFixed operator-(const CBofFixed &Arg) const {
59  return _lVal - Arg._lVal;
60  }
61 
62  CBofFixed operator*(const CBofFixed &Arg) const {
63  return fixedMultiply(_lVal, Arg._lVal);
64  }
65 
66  CBofFixed operator/(const CBofFixed &Arg) const {
67  return fixedDivide(_lVal, Arg._lVal);
68  }
69 
70  CBofFixed operator-=(const CBofFixed &Arg) {
71  _lVal -= Arg._lVal;
72  return *this;
73  }
74 
75  CBofFixed operator+=(const CBofFixed &Arg) {
76  _lVal += Arg._lVal;
77  return *this;
78  }
79 
80  CBofFixed operator*=(const CBofFixed &Arg) {
81  _lVal = _lVal * Arg._lVal;
82 
83  return *this;
84  }
85 
86  CBofFixed operator/=(const CBofFixed &Arg) {
87  _lVal = _lVal / Arg._lVal;
88 
89  return *this;
90  }
91 
92  CBofFixed operator=(const CBofFixed &Arg) {
93  _lVal = Arg._lVal;
94  return *this;
95  }
96 
97  // Conversion operators
98  operator int() {
99  return (int)(((int32)_lVal) >> 16);
100  }
101 };
102 
103 } // namespace Bagel
104 
105 #endif
Definition: object.h:28
Definition: fixed.h:31
Definition: bagel.h:31