diff options
Diffstat (limited to 'ue4/mycpu/cdatn.h')
| -rw-r--r-- | ue4/mycpu/cdatn.h | 382 |
1 files changed, 382 insertions, 0 deletions
diff --git a/ue4/mycpu/cdatn.h b/ue4/mycpu/cdatn.h new file mode 100644 index 0000000..32d8d7b --- /dev/null +++ b/ue4/mycpu/cdatn.h | |||
| @@ -0,0 +1,382 @@ | |||
| 1 | /** | ||
| 2 | * @module cdatn | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief Datatype template and datatype definition for CCPU and CMem | ||
| 5 | * @date 26.05.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef CDATN_H | ||
| 9 | #define CDATN_H 1 | ||
| 10 | |||
| 11 | #include <boost/operators.hpp> | ||
| 12 | #include <iostream> | ||
| 13 | |||
| 14 | /** | ||
| 15 | * @class CDatN | ||
| 16 | * | ||
| 17 | * Datatype template for CCPU and CMem. | ||
| 18 | */ | ||
| 19 | class CDatN | ||
| 20 | : public boost::operators<CDatN> | ||
| 21 | { | ||
| 22 | private: | ||
| 23 | /** | ||
| 24 | * @method CDatN | ||
| 25 | * @brief Default ctor | ||
| 26 | * @param - | ||
| 27 | * @return - | ||
| 28 | * @globalvars none | ||
| 29 | * @exception bad_alloc | ||
| 30 | * @pre none | ||
| 31 | * @post none | ||
| 32 | */ | ||
| 33 | CDatN() | ||
| 34 | {} | ||
| 35 | |||
| 36 | public: | ||
| 37 | /** | ||
| 38 | * @method ~CDatN | ||
| 39 | * @brief Default dtor | ||
| 40 | * @param - | ||
| 41 | * @return - | ||
| 42 | * @globalvars none | ||
| 43 | * @exception none | ||
| 44 | * @pre none | ||
| 45 | * @post none | ||
| 46 | */ | ||
| 47 | virtual ~CDatN() | ||
| 48 | {} | ||
| 49 | |||
| 50 | /** | ||
| 51 | * @method CDatN | ||
| 52 | * @brief Copy constructor for CDatN | ||
| 53 | * @param other reference to CDatN which will be copied | ||
| 54 | * @return - | ||
| 55 | * @globalvars none | ||
| 56 | * @exception none | ||
| 57 | * @pre none | ||
| 58 | * @post none | ||
| 59 | */ | ||
| 60 | CDatN(const CDatN& other) | ||
| 61 | : m_value(other.m_value), m_width(other.m_width) | ||
| 62 | {} | ||
| 63 | |||
| 64 | /** | ||
| 65 | * @method CDatN | ||
| 66 | * @brief Copy constructor for int | ||
| 67 | * @param newval new value for CDatN | ||
| 68 | * @param width maximum width | ||
| 69 | * @return - | ||
| 70 | * @globalvars none | ||
| 71 | * @exception none | ||
| 72 | * @pre none | ||
| 73 | * @post none | ||
| 74 | */ | ||
| 75 | CDatN(const int newval, unsigned width = 31) | ||
| 76 | : m_value(((1 << width) - 1) & newval), m_width(width) | ||
| 77 | {} | ||
| 78 | |||
| 79 | /** | ||
| 80 | * @method getValue | ||
| 81 | * @brief returns value of CDatN | ||
| 82 | * @param - | ||
| 83 | * @return value of CDatN | ||
| 84 | * @globalvars none | ||
| 85 | * @exception none | ||
| 86 | * @pre none | ||
| 87 | * @post none | ||
| 88 | */ | ||
| 89 | int getValue() const | ||
| 90 | { | ||
| 91 | return m_value; | ||
| 92 | } | ||
| 93 | |||
| 94 | /** | ||
| 95 | * @method operator int | ||
| 96 | * @brief convert to int | ||
| 97 | * @param - | ||
| 98 | * @return int | ||
| 99 | * @globalvars none | ||
| 100 | * @exception none | ||
| 101 | * @pre none | ||
| 102 | * @post none | ||
| 103 | */ | ||
| 104 | operator int() | ||
| 105 | { | ||
| 106 | return m_value; | ||
| 107 | } | ||
| 108 | |||
| 109 | /** | ||
| 110 | * @method operator< | ||
| 111 | * @brief implementation of operator < | ||
| 112 | * @param x reference to CDatN | ||
| 113 | * @return true if cdat is less than object x | ||
| 114 | * @globalvars none | ||
| 115 | * @exception none | ||
| 116 | * @pre none | ||
| 117 | * @post none | ||
| 118 | */ | ||
| 119 | bool operator<(const CDatN& x) const | ||
| 120 | { | ||
| 121 | return m_value < x.m_value; | ||
| 122 | } | ||
| 123 | |||
| 124 | /** | ||
| 125 | * @method operator== | ||
| 126 | * @brief implementation of operator == | ||
| 127 | * @param x reference to CDatN | ||
| 128 | * @return true if cdat equals object x | ||
| 129 | * @globalvars none | ||
| 130 | * @exception none | ||
| 131 | * @pre none | ||
| 132 | * @post none | ||
| 133 | */ | ||
| 134 | bool operator==(const CDatN& x) const | ||
| 135 | { | ||
| 136 | return m_value == x.m_value; | ||
| 137 | } | ||
| 138 | |||
| 139 | /** | ||
| 140 | * @method operator= | ||
| 141 | * @brief implementation of operator = | ||
| 142 | * @param x reference to int | ||
| 143 | * @return refecence to int | ||
| 144 | * @globalvars none | ||
| 145 | * @exception none | ||
| 146 | * @pre none | ||
| 147 | * @post none | ||
| 148 | */ | ||
| 149 | CDatN &operator=(const int& newval) | ||
| 150 | { | ||
| 151 | m_value = newval; | ||
| 152 | align(); | ||
| 153 | return *this; | ||
| 154 | } | ||
| 155 | |||
| 156 | /** | ||
| 157 | * @method operator+= | ||
| 158 | * @brief implementation of operator += | ||
| 159 | * @param x reference to CDatN | ||
| 160 | * @return refecence to CDatN | ||
| 161 | * @globalvars none | ||
| 162 | * @exception none | ||
| 163 | * @pre none | ||
| 164 | * @post none | ||
| 165 | */ | ||
| 166 | CDatN& operator+=(const CDatN& x) | ||
| 167 | { | ||
| 168 | m_value += x.m_value; | ||
| 169 | align(); | ||
| 170 | return *this; | ||
| 171 | } | ||
| 172 | |||
| 173 | /** | ||
| 174 | * @method operator-= | ||
| 175 | * @brief implementation of operator -= | ||
| 176 | * @param x reference to CDatN | ||
| 177 | * @return refecence to CDatN | ||
| 178 | * @globalvars none | ||
| 179 | * @exception none | ||
| 180 | * @pre none | ||
| 181 | * @post none | ||
| 182 | */ | ||
| 183 | CDatN& operator-=(const CDatN& x) | ||
| 184 | { | ||
| 185 | m_value -= x.m_value; | ||
| 186 | align(); | ||
| 187 | return *this; | ||
| 188 | } | ||
| 189 | |||
| 190 | /** | ||
| 191 | * @method operator*= | ||
| 192 | * @brief implementation of operator *= | ||
| 193 | * @param x reference to CDatN | ||
| 194 | * @return refecence to CDatN | ||
| 195 | * @globalvars none | ||
| 196 | * @exception none | ||
| 197 | * @pre none | ||
| 198 | * @post none | ||
| 199 | */ | ||
| 200 | CDatN& operator*=(const CDatN& x) | ||
| 201 | { | ||
| 202 | m_value *= x.m_value; | ||
| 203 | align(); | ||
| 204 | return *this; | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | ||
| 208 | * @method operator/= | ||
| 209 | * @brief implementation of operator /= | ||
| 210 | * @param x reference to CDatN | ||
| 211 | * @return refecence to CDatN | ||
| 212 | * @globalvars none | ||
| 213 | * @exception none | ||
| 214 | * @pre none | ||
| 215 | * @post none | ||
| 216 | */ | ||
| 217 | CDatN& operator/=(const CDatN& x) | ||
| 218 | { | ||
| 219 | m_value /= x.m_value; | ||
| 220 | align(); | ||
| 221 | return *this; | ||
| 222 | } | ||
| 223 | |||
| 224 | /** | ||
| 225 | * @method operator%= | ||
| 226 | * @brief implementation of operator %= | ||
| 227 | * @param x reference to CDatN | ||
| 228 | * @return refecence to CDatN | ||
| 229 | * @globalvars none | ||
| 230 | * @exception none | ||
| 231 | * @pre none | ||
| 232 | * @post none | ||
| 233 | */ | ||
| 234 | CDatN& operator%=(const CDatN& x) | ||
| 235 | { | ||
| 236 | m_value %= x.m_value; | ||
| 237 | align(); | ||
| 238 | return *this; | ||
| 239 | } | ||
| 240 | |||
| 241 | /** | ||
| 242 | * @method operator|= | ||
| 243 | * @brief implementation of operator |= | ||
| 244 | * @param x reference to CDatN | ||
| 245 | * @return refecence to CDatN | ||
| 246 | * @globalvars none | ||
| 247 | * @exception none | ||
| 248 | * @pre none | ||
| 249 | * @post none | ||
| 250 | */ | ||
| 251 | CDatN& operator|=(const CDatN& x) | ||
| 252 | { | ||
| 253 | m_value |= x.m_value; | ||
| 254 | align(); | ||
| 255 | return *this; | ||
| 256 | } | ||
| 257 | |||
| 258 | /** | ||
| 259 | * @method operator&= | ||
| 260 | * @brief implementation of operator &= | ||
| 261 | * @param x reference to CDatN | ||
| 262 | * @return refecence to CDatN | ||
| 263 | * @globalvars none | ||
| 264 | * @exception none | ||
| 265 | * @pre none | ||
| 266 | * @post none | ||
| 267 | */ | ||
| 268 | CDatN& operator&=(const CDatN& x) | ||
| 269 | { | ||
| 270 | m_value &= x.m_value; | ||
| 271 | align(); | ||
| 272 | return *this; | ||
| 273 | } | ||
| 274 | |||
| 275 | /** | ||
| 276 | * @method operator^= | ||
| 277 | * @brief implementation of operator ^= | ||
| 278 | * @param x reference to CDatN | ||
| 279 | * @return refecence to CDatN | ||
| 280 | * @globalvars none | ||
| 281 | * @exception none | ||
| 282 | * @pre none | ||
| 283 | * @post none | ||
| 284 | */ | ||
| 285 | CDatN& operator^=(const CDatN& x) | ||
| 286 | { | ||
| 287 | m_value ^= x.m_value; | ||
| 288 | align(); | ||
| 289 | return *this; | ||
| 290 | } | ||
| 291 | |||
| 292 | /** | ||
| 293 | * @method operator++ | ||
| 294 | * @brief implementation of operator ++ | ||
| 295 | * @param - | ||
| 296 | * @return refecence to CDatN | ||
| 297 | * @globalvars none | ||
| 298 | * @exception none | ||
| 299 | * @pre none | ||
| 300 | * @post none | ||
| 301 | */ | ||
| 302 | CDatN& operator++() | ||
| 303 | { | ||
| 304 | m_value++; | ||
| 305 | align(); | ||
| 306 | return *this; | ||
| 307 | } | ||
| 308 | |||
| 309 | /** | ||
| 310 | * @method operator-- | ||
| 311 | * @brief implementation of operator -- | ||
| 312 | * @param - | ||
| 313 | * @return refecence to CDatN | ||
| 314 | * @globalvars none | ||
| 315 | * @exception none | ||
| 316 | * @pre none | ||
| 317 | * @post none | ||
| 318 | */ | ||
| 319 | CDatN& operator--() | ||
| 320 | { | ||
| 321 | m_value--; | ||
| 322 | return *this; | ||
| 323 | } | ||
| 324 | |||
| 325 | /** | ||
| 326 | * @method operator<< | ||
| 327 | * @brief Shift/output operator for outputstream | ||
| 328 | * @param stream reference to outputstream | ||
| 329 | * @param cdat object which will be printed to stream | ||
| 330 | * @return reference to outputstream | ||
| 331 | * @globalvars none | ||
| 332 | * @exception none | ||
| 333 | * @pre none | ||
| 334 | * @post none | ||
| 335 | */ | ||
| 336 | friend std::ostream& operator<<(std::ostream& stream, CDatN cdat) | ||
| 337 | { | ||
| 338 | stream << cdat.m_value; | ||
| 339 | return stream; | ||
| 340 | } | ||
| 341 | |||
| 342 | /** | ||
| 343 | * @method operator>> | ||
| 344 | * @brief Shift/read operator for inputstream | ||
| 345 | * @param stream reference to inputstream | ||
| 346 | * @param cdat reference to object which will be read from stream | ||
| 347 | * @return reference to inputstream | ||
| 348 | * @globalvars none | ||
| 349 | * @exception none | ||
| 350 | * @pre none | ||
| 351 | * @post none | ||
| 352 | */ | ||
| 353 | friend std::istream& operator>>(std::istream & stream, CDatN& cdat) | ||
| 354 | { | ||
| 355 | stream >> cdat.m_value; | ||
| 356 | cdat.align(); | ||
| 357 | return stream; | ||
| 358 | } | ||
| 359 | |||
| 360 | protected: | ||
| 361 | /** | ||
| 362 | * @method align | ||
| 363 | * @brief aligns value by width | ||
| 364 | * @return - | ||
| 365 | * @globalvars none | ||
| 366 | * @exception none | ||
| 367 | * @pre none | ||
| 368 | * @post none | ||
| 369 | */ | ||
| 370 | inline void align() | ||
| 371 | { | ||
| 372 | m_value &= ((1 << m_width) - 1); | ||
| 373 | } | ||
| 374 | |||
| 375 | /* members */ | ||
| 376 | int m_value; | ||
| 377 | unsigned m_width; | ||
| 378 | }; | ||
| 379 | |||
| 380 | #endif | ||
| 381 | |||
| 382 | /* vim: set et sw=2 ts=2: */ | ||
