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