diff options
| author | manuel <manuel@nc8430.lan> | 2009-05-10 19:48:42 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-05-10 19:48:42 +0200 |
| commit | fe1ef6b47f59899e8687bb1dcc92eba1d103a08f (patch) | |
| tree | 8870b836f47add7219951bb51fb710ce81fb9521 /ue3 | |
| parent | 6a813b50e4fc3bba829c3a94495d6061ea92bada (diff) | |
| download | ooprog-fe1ef6b47f59899e8687bb1dcc92eba1d103a08f.tar.gz ooprog-fe1ef6b47f59899e8687bb1dcc92eba1d103a08f.tar.bz2 ooprog-fe1ef6b47f59899e8687bb1dcc92eba1d103a08f.zip | |
making cdat a template
Diffstat (limited to 'ue3')
| -rw-r--r-- | ue3/mycpu/cdat.cpp | 126 | ||||
| -rw-r--r-- | ue3/mycpu/cdat.h | 176 |
2 files changed, 118 insertions, 184 deletions
diff --git a/ue3/mycpu/cdat.cpp b/ue3/mycpu/cdat.cpp deleted file mode 100644 index 455d3bc..0000000 --- a/ue3/mycpu/cdat.cpp +++ /dev/null | |||
| @@ -1,126 +0,0 @@ | |||
| 1 | /** | ||
| 2 | * @module cdat | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief TODO | ||
| 5 | * @date 10.05.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "cdat.h" | ||
| 9 | |||
| 10 | |||
| 11 | int CDat::value() const | ||
| 12 | { | ||
| 13 | return m_value; | ||
| 14 | } | ||
| 15 | |||
| 16 | /*----------------------------------------------------------------------------*/ | ||
| 17 | |||
| 18 | bool CDat::operator<(const CDat& x) const | ||
| 19 | { | ||
| 20 | return m_value < x.m_value; | ||
| 21 | } | ||
| 22 | |||
| 23 | /*----------------------------------------------------------------------------*/ | ||
| 24 | |||
| 25 | bool CDat::operator==(const CDat& x) const | ||
| 26 | { | ||
| 27 | return m_value == x.m_value; | ||
| 28 | } | ||
| 29 | |||
| 30 | /*----------------------------------------------------------------------------*/ | ||
| 31 | |||
| 32 | CDat& CDat::operator+=(const CDat& x) | ||
| 33 | { | ||
| 34 | m_value += x.m_value; | ||
| 35 | return *this; | ||
| 36 | } | ||
| 37 | |||
| 38 | /*----------------------------------------------------------------------------*/ | ||
| 39 | |||
| 40 | CDat& CDat::operator-=(const CDat& x) | ||
| 41 | { | ||
| 42 | m_value -= x.m_value; | ||
| 43 | return *this; | ||
| 44 | } | ||
| 45 | |||
| 46 | /*----------------------------------------------------------------------------*/ | ||
| 47 | |||
| 48 | CDat& CDat::operator*=(const CDat& x) | ||
| 49 | { | ||
| 50 | m_value *= x.m_value; | ||
| 51 | return *this; | ||
| 52 | } | ||
| 53 | |||
| 54 | /*----------------------------------------------------------------------------*/ | ||
| 55 | |||
| 56 | CDat& CDat::operator/=(const CDat& x) | ||
| 57 | { | ||
| 58 | m_value /= x.m_value; | ||
| 59 | return *this; | ||
| 60 | } | ||
| 61 | |||
| 62 | /*----------------------------------------------------------------------------*/ | ||
| 63 | |||
| 64 | CDat& CDat::operator%=(const CDat& x) | ||
| 65 | { | ||
| 66 | m_value %= x.m_value; | ||
| 67 | return *this; | ||
| 68 | } | ||
| 69 | |||
| 70 | /*----------------------------------------------------------------------------*/ | ||
| 71 | |||
| 72 | CDat& CDat::operator|=(const CDat& x) | ||
| 73 | { | ||
| 74 | m_value |= x.m_value; | ||
| 75 | return *this; | ||
| 76 | } | ||
| 77 | |||
| 78 | /*----------------------------------------------------------------------------*/ | ||
| 79 | |||
| 80 | CDat& CDat::operator&=(const CDat& x) | ||
| 81 | { | ||
| 82 | m_value &= x.m_value; | ||
| 83 | return *this; | ||
| 84 | } | ||
| 85 | |||
| 86 | /*----------------------------------------------------------------------------*/ | ||
| 87 | |||
| 88 | CDat& CDat::operator^=(const CDat& x) | ||
| 89 | { | ||
| 90 | m_value ^= x.m_value; | ||
| 91 | return *this; | ||
| 92 | } | ||
| 93 | |||
| 94 | /*----------------------------------------------------------------------------*/ | ||
| 95 | |||
| 96 | CDat& CDat::operator++() | ||
| 97 | { | ||
| 98 | m_value++; | ||
| 99 | return *this; | ||
| 100 | } | ||
| 101 | |||
| 102 | /*----------------------------------------------------------------------------*/ | ||
| 103 | |||
| 104 | CDat& CDat::operator--() | ||
| 105 | { | ||
| 106 | m_value--; | ||
| 107 | return *this; | ||
| 108 | } | ||
| 109 | |||
| 110 | /*----------------------------------------------------------------------------*/ | ||
| 111 | |||
| 112 | std::ostream& operator<<(std::ostream& stream, CDat cdat) | ||
| 113 | { | ||
| 114 | stream << cdat.m_value; | ||
| 115 | return stream; | ||
| 116 | } | ||
| 117 | |||
| 118 | /*----------------------------------------------------------------------------*/ | ||
| 119 | |||
| 120 | std::istream& operator>>(std::istream & stream, CDat& cdat) | ||
| 121 | { | ||
| 122 | stream >> cdat.m_value; | ||
| 123 | return stream; | ||
| 124 | } | ||
| 125 | |||
| 126 | /* vim: set et sw=2 ts=2: */ | ||
diff --git a/ue3/mycpu/cdat.h b/ue3/mycpu/cdat.h index 8b067f9..dc8a07c 100644 --- a/ue3/mycpu/cdat.h +++ b/ue3/mycpu/cdat.h | |||
| @@ -1,29 +1,28 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module cdat | 2 | * @module cdat |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief Datatype template for mycpu |
| 5 | * @date 10.05.2009 | 5 | * @date 10.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef CDAT_H | 8 | #ifndef CDATT_H |
| 9 | #define CDAT_H | 9 | #define CDATT_H |
| 10 | 10 | ||
| 11 | #include <boost/operators.hpp> | 11 | #include <boost/operators.hpp> |
| 12 | #include <iostream> | 12 | #include <iostream> |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * @class CDat | 15 | * @class CDatT |
| 16 | * | 16 | * |
| 17 | * TODO | 17 | * Datatype template for mycpu. |
| 18 | * | ||
| 19 | * On error TODO will be thrown. | ||
| 20 | */ | 18 | */ |
| 21 | class CDat | 19 | template <class T> |
| 22 | : boost::operators<CDat> | 20 | class CDatT |
| 21 | : boost::operators<CDatT<T> > | ||
| 23 | { | 22 | { |
| 24 | public: | 23 | public: |
| 25 | /** | 24 | /** |
| 26 | * @method CDat | 25 | * @method CDatT |
| 27 | * @brief Default ctor | 26 | * @brief Default ctor |
| 28 | * @param - | 27 | * @param - |
| 29 | * @return - | 28 | * @return - |
| @@ -31,11 +30,11 @@ class CDat | |||
| 31 | * @exception bad_alloc | 30 | * @exception bad_alloc |
| 32 | * @conditions none | 31 | * @conditions none |
| 33 | */ | 32 | */ |
| 34 | CDat() | 33 | CDatT() |
| 35 | {} | 34 | {} |
| 36 | 35 | ||
| 37 | /** | 36 | /** |
| 38 | * @method ~CDat | 37 | * @method ~CDatT |
| 39 | * @brief Default dtor | 38 | * @brief Default dtor |
| 40 | * @param - | 39 | * @param - |
| 41 | * @return - | 40 | * @return - |
| @@ -43,177 +42,226 @@ class CDat | |||
| 43 | * @exception none | 42 | * @exception none |
| 44 | * @conditions none | 43 | * @conditions none |
| 45 | */ | 44 | */ |
| 46 | ~CDat() | 45 | ~CDatT() |
| 47 | {} | 46 | {} |
| 48 | 47 | ||
| 49 | /** | 48 | /** |
| 50 | * @method CDat | 49 | * @method CDatT |
| 51 | * @brief Copy constructor for CDat | 50 | * @brief Copy constructor for CDatT |
| 52 | * @param other reference to CDat which will be copied | 51 | * @param other reference to CDatT which will be copied |
| 53 | * @return - | 52 | * @return - |
| 54 | * @globalvars none | 53 | * @globalvars none |
| 55 | * @exception none | 54 | * @exception none |
| 56 | * @conditions none | 55 | * @conditions none |
| 57 | */ | 56 | */ |
| 58 | CDat(const CDat& other) | 57 | CDatT(const CDatT& other) |
| 59 | : m_value(other.m_value) | 58 | : m_value(other.m_value) |
| 60 | {} | 59 | {} |
| 61 | 60 | ||
| 62 | /** | 61 | /** |
| 63 | * @method CDat | 62 | * @method CDatT |
| 64 | * @brief Copy constructor for int | 63 | * @brief Copy constructor for int |
| 65 | * @param newval new value for CDat | 64 | * @param newval new value for CDatT |
| 66 | * @return - | 65 | * @return - |
| 67 | * @globalvars none | 66 | * @globalvars none |
| 68 | * @exception none | 67 | * @exception none |
| 69 | * @conditions none | 68 | * @conditions none |
| 70 | */ | 69 | */ |
| 71 | CDat(int newval) | 70 | CDatT(T newval) |
| 72 | : m_value(newval) | 71 | : m_value(newval) |
| 73 | {} | 72 | {} |
| 74 | 73 | ||
| 75 | /** | 74 | /** |
| 76 | * @method value | 75 | * @method value |
| 77 | * @brief returns value of CDat | 76 | * @brief returns value of CDatT |
| 78 | * @param - | 77 | * @param - |
| 79 | * @return value of CDat | 78 | * @return value of CDatT |
| 80 | * @globalvars none | 79 | * @globalvars none |
| 81 | * @exception none | 80 | * @exception none |
| 82 | * @conditions none | 81 | * @conditions none |
| 83 | */ | 82 | */ |
| 84 | int value() const; | 83 | T value() const |
| 84 | { | ||
| 85 | return m_value; | ||
| 86 | } | ||
| 85 | 87 | ||
| 86 | /** | 88 | /** |
| 87 | * @method operator< | 89 | * @method operator< |
| 88 | * @brief implementation of operator < | 90 | * @brief implementation of operator < |
| 89 | * @param reference to CDat | 91 | * @param reference to CDatT |
| 90 | * @return true if cdat is less than object x | 92 | * @return true if cdat is less than object x |
| 91 | * @globalvars none | 93 | * @globalvars none |
| 92 | * @exception none | 94 | * @exception none |
| 93 | * @conditions none | 95 | * @conditions none |
| 94 | */ | 96 | */ |
| 95 | bool operator<(const CDat& x) const; | 97 | bool operator<(const CDatT& x) const |
| 98 | { | ||
| 99 | return m_value < x.m_value; | ||
| 100 | } | ||
| 96 | 101 | ||
| 97 | /** | 102 | /** |
| 98 | * @method operator== | 103 | * @method operator== |
| 99 | * @brief implementation of operator == | 104 | * @brief implementation of operator == |
| 100 | * @param reference to CDat | 105 | * @param reference to CDatT |
| 101 | * @return true if cdat equals object x | 106 | * @return true if cdat equals object x |
| 102 | * @globalvars none | 107 | * @globalvars none |
| 103 | * @exception none | 108 | * @exception none |
| 104 | * @conditions none | 109 | * @conditions none |
| 105 | */ | 110 | */ |
| 106 | bool operator==(const CDat& x) const; | 111 | bool operator==(const CDatT& x) const |
| 112 | { | ||
| 113 | return m_value == x.m_value; | ||
| 114 | } | ||
| 107 | 115 | ||
| 108 | /** | 116 | /** |
| 109 | * @method operator+= | 117 | * @method operator+= |
| 110 | * @brief implementation of operator += | 118 | * @brief implementation of operator += |
| 111 | * @param reference to CDat | 119 | * @param reference to CDatT |
| 112 | * @return refecence to CDat | 120 | * @return refecence to CDatT |
| 113 | * @globalvars none | 121 | * @globalvars none |
| 114 | * @exception none | 122 | * @exception none |
| 115 | * @conditions none | 123 | * @conditions none |
| 116 | */ | 124 | */ |
| 117 | CDat& operator+=(const CDat& x); | 125 | CDatT& operator+=(const CDatT& x) |
| 126 | { | ||
| 127 | m_value += x.m_value; | ||
| 128 | return *this; | ||
| 129 | } | ||
| 118 | 130 | ||
| 119 | /** | 131 | /** |
| 120 | * @method operator-= | 132 | * @method operator-= |
| 121 | * @brief implementation of operator -= | 133 | * @brief implementation of operator -= |
| 122 | * @param reference to CDat | 134 | * @param reference to CDatT |
| 123 | * @return refecence to CDat | 135 | * @return refecence to CDatT |
| 124 | * @globalvars none | 136 | * @globalvars none |
| 125 | * @exception none | 137 | * @exception none |
| 126 | * @conditions none | 138 | * @conditions none |
| 127 | */ | 139 | */ |
| 128 | CDat& operator-=(const CDat& x); | 140 | CDatT& operator-=(const CDatT& x) |
| 141 | { | ||
| 142 | m_value -= x.m_value; | ||
| 143 | return *this; | ||
| 144 | } | ||
| 129 | 145 | ||
| 130 | /** | 146 | /** |
| 131 | * @method operator*= | 147 | * @method operator*= |
| 132 | * @brief implementation of operator *= | 148 | * @brief implementation of operator *= |
| 133 | * @param reference to CDat | 149 | * @param reference to CDatT |
| 134 | * @return refecence to CDat | 150 | * @return refecence to CDatT |
| 135 | * @globalvars none | 151 | * @globalvars none |
| 136 | * @exception none | 152 | * @exception none |
| 137 | * @conditions none | 153 | * @conditions none |
| 138 | */ | 154 | */ |
| 139 | CDat& operator*=(const CDat& x); | 155 | CDatT& operator*=(const CDatT& x) |
| 156 | { | ||
| 157 | m_value *= x.m_value; | ||
| 158 | return *this; | ||
| 159 | } | ||
| 140 | 160 | ||
| 141 | /** | 161 | /** |
| 142 | * @method operator/= | 162 | * @method operator/= |
| 143 | * @brief implementation of operator /= | 163 | * @brief implementation of operator /= |
| 144 | * @param reference to CDat | 164 | * @param reference to CDatT |
| 145 | * @return refecence to CDat | 165 | * @return refecence to CDatT |
| 146 | * @globalvars none | 166 | * @globalvars none |
| 147 | * @exception none | 167 | * @exception none |
| 148 | * @conditions none | 168 | * @conditions none |
| 149 | */ | 169 | */ |
| 150 | CDat& operator/=(const CDat& x); | 170 | CDatT& operator/=(const CDatT& x) |
| 171 | { | ||
| 172 | m_value /= x.m_value; | ||
| 173 | return *this; | ||
| 174 | } | ||
| 151 | 175 | ||
| 152 | /** | 176 | /** |
| 153 | * @method operator%= | 177 | * @method operator%= |
| 154 | * @brief implementation of operator %= | 178 | * @brief implementation of operator %= |
| 155 | * @param reference to CDat | 179 | * @param reference to CDatT |
| 156 | * @return refecence to CDat | 180 | * @return refecence to CDatT |
| 157 | * @globalvars none | 181 | * @globalvars none |
| 158 | * @exception none | 182 | * @exception none |
| 159 | * @conditions none | 183 | * @conditions none |
| 160 | */ | 184 | */ |
| 161 | CDat& operator%=(const CDat& x); | 185 | CDatT& operator%=(const CDatT& x) |
| 186 | { | ||
| 187 | m_value %= x.m_value; | ||
| 188 | return *this; | ||
| 189 | } | ||
| 162 | 190 | ||
| 163 | /** | 191 | /** |
| 164 | * @method operator|= | 192 | * @method operator|= |
| 165 | * @brief implementation of operator |= | 193 | * @brief implementation of operator |= |
| 166 | * @param reference to CDat | 194 | * @param reference to CDatT |
| 167 | * @return refecence to CDat | 195 | * @return refecence to CDatT |
| 168 | * @globalvars none | 196 | * @globalvars none |
| 169 | * @exception none | 197 | * @exception none |
| 170 | * @conditions none | 198 | * @conditions none |
| 171 | */ | 199 | */ |
| 172 | CDat& operator|=(const CDat& x); | 200 | CDatT& operator|=(const CDatT& x) |
| 201 | { | ||
| 202 | m_value |= x.m_value; | ||
| 203 | return *this; | ||
| 204 | } | ||
| 173 | 205 | ||
| 174 | /** | 206 | /** |
| 175 | * @method operator&= | 207 | * @method operator&= |
| 176 | * @brief implementation of operator &= | 208 | * @brief implementation of operator &= |
| 177 | * @param reference to CDat | 209 | * @param reference to CDatT |
| 178 | * @return refecence to CDat | 210 | * @return refecence to CDatT |
| 179 | * @globalvars none | 211 | * @globalvars none |
| 180 | * @exception none | 212 | * @exception none |
| 181 | * @conditions none | 213 | * @conditions none |
| 182 | */ | 214 | */ |
| 183 | CDat& operator&=(const CDat& x); | 215 | CDatT& operator&=(const CDatT& x) |
| 216 | { | ||
| 217 | m_value &= x.m_value; | ||
| 218 | return *this; | ||
| 219 | } | ||
| 184 | 220 | ||
| 185 | /** | 221 | /** |
| 186 | * @method operator^= | 222 | * @method operator^= |
| 187 | * @brief implementation of operator ^= | 223 | * @brief implementation of operator ^= |
| 188 | * @param reference to CDat | 224 | * @param reference to CDatT |
| 189 | * @return refecence to CDat | 225 | * @return refecence to CDatT |
| 190 | * @globalvars none | 226 | * @globalvars none |
| 191 | * @exception none | 227 | * @exception none |
| 192 | * @conditions none | 228 | * @conditions none |
| 193 | */ | 229 | */ |
| 194 | CDat& operator^=(const CDat& x); | 230 | CDatT& operator^=(const CDatT& x) |
| 231 | { | ||
| 232 | m_value ^= x.m_value; | ||
| 233 | return *this; | ||
| 234 | } | ||
| 195 | 235 | ||
| 196 | /** | 236 | /** |
| 197 | * @method operator++ | 237 | * @method operator++ |
| 198 | * @brief implementation of operator ++ | 238 | * @brief implementation of operator ++ |
| 199 | * @param - | 239 | * @param - |
| 200 | * @return refecence to CDat | 240 | * @return refecence to CDatT |
| 201 | * @globalvars none | 241 | * @globalvars none |
| 202 | * @exception none | 242 | * @exception none |
| 203 | * @conditions none | 243 | * @conditions none |
| 204 | */ | 244 | */ |
| 205 | CDat& operator++(); | 245 | CDatT& operator++() |
| 246 | { | ||
| 247 | m_value++; | ||
| 248 | return *this; | ||
| 249 | } | ||
| 206 | 250 | ||
| 207 | /** | 251 | /** |
| 208 | * @method operator-- | 252 | * @method operator-- |
| 209 | * @brief implementation of operator -- | 253 | * @brief implementation of operator -- |
| 210 | * @param - | 254 | * @param - |
| 211 | * @return refecence to CDat | 255 | * @return refecence to CDatT |
| 212 | * @globalvars none | 256 | * @globalvars none |
| 213 | * @exception none | 257 | * @exception none |
| 214 | * @conditions none | 258 | * @conditions none |
| 215 | */ | 259 | */ |
| 216 | CDat& operator--(); | 260 | CDatT& operator--() |
| 261 | { | ||
| 262 | m_value--; | ||
| 263 | return *this; | ||
| 264 | } | ||
| 217 | 265 | ||
| 218 | /** | 266 | /** |
| 219 | * @method operator<< | 267 | * @method operator<< |
| @@ -225,7 +273,11 @@ class CDat | |||
| 225 | * @exception none | 273 | * @exception none |
| 226 | * @conditions none | 274 | * @conditions none |
| 227 | */ | 275 | */ |
| 228 | friend std::ostream& operator<<(std::ostream& stream, CDat cdat); | 276 | friend std::ostream& operator<<(std::ostream& stream, CDatT cdat) |
| 277 | { | ||
| 278 | stream << cdat.m_value; | ||
| 279 | return stream; | ||
| 280 | } | ||
| 229 | 281 | ||
| 230 | /** | 282 | /** |
| 231 | * @method operator>> | 283 | * @method operator>> |
| @@ -237,13 +289,21 @@ class CDat | |||
| 237 | * @exception none | 289 | * @exception none |
| 238 | * @conditions none | 290 | * @conditions none |
| 239 | */ | 291 | */ |
| 240 | friend std::istream& operator>>(std::istream & stream, CDat& cdat); | 292 | friend std::istream& operator>>(std::istream & stream, CDatT& cdat) |
| 293 | { | ||
| 294 | stream >> cdat.m_value; | ||
| 295 | return stream; | ||
| 296 | } | ||
| 241 | 297 | ||
| 242 | private: | 298 | private: |
| 243 | /* members */ | 299 | /* members */ |
| 244 | int m_value; | 300 | T m_value; |
| 245 | }; | 301 | }; |
| 246 | 302 | ||
| 303 | |||
| 304 | /** define CDat */ | ||
| 305 | typedef CDatT<int> CDat; | ||
| 306 | |||
| 247 | #endif | 307 | #endif |
| 248 | 308 | ||
| 249 | /* vim: set et sw=2 ts=2: */ | 309 | /* vim: set et sw=2 ts=2: */ |
