dma.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // dma.cpp --dma class methods
  2. #include "dma.h"
  3. #include <cstring>
  4. // baseDMA methods
  5. baseDMA::baseDMA(const char * l, int r)
  6. {
  7. label = new char[std::strlen(l) + 1];
  8. std::strcpy(label, l);
  9. rating = r;
  10. }
  11. baseDMA::baseDMA(const baseDMA & rs)
  12. {
  13. label = new char[std::strlen(rs.label) + 1];
  14. std::strcpy(label, rs.label);
  15. rating = rs.rating;
  16. }
  17. baseDMA::~baseDMA()
  18. {
  19. delete [] label;
  20. }
  21. baseDMA & baseDMA::operator=(const baseDMA & rs)
  22. {
  23. if (this == &rs)
  24. return *this;
  25. delete [] label;
  26. label = new char[std::strlen(rs.label) + 1];
  27. std::strcpy(label, rs.label);
  28. rating = rs.rating;
  29. return *this;
  30. }
  31. std::ostream & operator<<(std::ostream & os, const baseDMA & rs)
  32. {
  33. os << "Label: " << rs.label << std::endl;
  34. os << "Rating: " << rs.rating << std::endl;
  35. return os;
  36. }
  37. // lacksDMA methods
  38. lacksDMA::lacksDMA(const char * c, const char * l, int r)
  39. : baseDMA(l, r)
  40. {
  41. std::strncpy(color, c, 39);
  42. color[39] = '\0';
  43. }
  44. lacksDMA::lacksDMA(const char * c, const baseDMA & rs)
  45. : baseDMA(rs)
  46. {
  47. std::strncpy(color, c, COL_LEN - 1);
  48. color[COL_LEN - 1] = '\0';
  49. }
  50. std::ostream & operator<<(std::ostream & os, const lacksDMA & ls)
  51. {
  52. os << (const baseDMA &) ls;
  53. os << "Color: " << ls.color << std::endl;
  54. return os;
  55. }
  56. // hasDMA methods
  57. hasDMA::hasDMA(const char * s, const char * l, int r)
  58. : baseDMA(l, r)
  59. {
  60. style = new char[std::strlen(s) + 1];
  61. std::strcpy(style, s);
  62. }
  63. hasDMA::hasDMA(const char * s, const baseDMA & rs)
  64. : baseDMA(rs)
  65. {
  66. style = new char[std::strlen(s) + 1];
  67. std::strcpy(style, s);
  68. }
  69. hasDMA::hasDMA(const hasDMA & hs)
  70. : baseDMA(hs) // invoke base class copy constructor
  71. {
  72. style = new char[std::strlen(hs.style) + 1];
  73. std::strcpy(style, hs.style);
  74. }
  75. hasDMA::~hasDMA()
  76. {
  77. delete [] style;
  78. }
  79. hasDMA & hasDMA::operator=(const hasDMA & hs)
  80. {
  81. if (this == &hs)
  82. return *this;
  83. baseDMA::operator=(hs); // copy base portion
  84. delete [] style; // prepare for new style
  85. style = new char[std::strlen(hs.style) + 1];
  86. std::strcpy(style, hs.style);
  87. return *this;
  88. }
  89. std::ostream & operator<<(std::ostream & os, const hasDMA & hs)
  90. {
  91. os << (const baseDMA &) hs;
  92. os << "Style: " << hs.style << std::endl;
  93. return os;
  94. }