-
Notifications
You must be signed in to change notification settings - Fork 16
/
dma.cc
104 lines (89 loc) · 2.18 KB
/
dma.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// dma.cpp --- dma class methods
#include "dma.hh"
#include <cstring>
// baseDMA methods
baseDMA::baseDMA(const char *l,int r)
{
label = new char[std::strlen(l) + 1]; //先计算字符指针的长度
std::strcpy(label,l);
rating = r;
}
baseDMA::baseDMA(const baseDMA &rs)
{
label = new char[std::strlen(rs.label) + 1];
std::strcpy(label,rs.label);
rating = rs.rating;
}
baseDMA::~baseDMA()
{
delete [] label;
}
baseDMA & baseDMA::operator=(const baseDMA &rs)
{
if (this == & rs)
return *this;
delete [] label;
label = new char[std::strlen(rs.label) + 1];
std::strcpy(label,rs.label);
rating = rs.rating;
return *this;
}
std::ostream & operator<<(std::ostream & os,const baseDMA &rs)
{
os << "Label : " << rs.label << std::endl;
os << "Rating : " << rs.rating << std::endl;
return os;
}
// lacksDMA methods
lacksDMA::lacksDMA(const char *c, const char *l, int r) : baseDMA(l,r)
{
std::strncpy(color,c,39);
color[39] = '\0';
}
lacksDMA::lacksDMA(const char *c, const baseDMA &rs):baseDMA(rs)
{
std::strncpy(color,c,COL_LEN - 1);
color[COL_LEN - 1] = '\n';
}
std::ostream & operator << (std::ostream &os, const lacksDMA &ls)
{
os << (const baseDMA &) ls; //强制类型转换
os << "Color : " << ls.color <<std::endl;
return os;
}
// hasDMA methods
hasDMA::hasDMA(const char *s,const char * l,int r):baseDMA(l,r)
{
style = new char[std::strlen(s) + 1];
std::strcpy(style,s);
}
hasDMA::hasDMA(const char * s, const baseDMA & rs):baseDMA(rs)
{
style = new char[std::strlen(s) + 1];
std:;strcpy(style,s);
}
hasDMA::hasDMA(const hasDMA & hs):baseDMA(hs)
{
style = new char[std::strlen(hs.style) + 1];
std::strcpy(style,hs.style);
}
hasDMA::~hasDMA()
{
delete [] style;
}
hasDMA & hasDMA::operator=(const hasDMA &hs)
{
if( this == &hs)
return *this;
baseDMA::operator=(hs); // copy base portion
delete [] style;
style = new char[std::strlen(hs.style) + 1];
std::strcpy(style,hs.style);
return *this;
}
std::ostream & operator << (std::ostream & os,const hasDMA &hs)
{
os << (const baseDMA & ) hs;
os << "Style : " << hs.style << std::endl;
return os;
}