Download | Plain Text | No Line Numbers


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