/
Record.cpp
70 lines (57 loc) · 1.32 KB
/
Record.cpp
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
/** Credit: David Fox **/
#include "Record.h"
Record::Record ( ){}
Record::Record ( const DataType& d, const KeyType& k )
:data(d), key(k){}
Record::Record ( const Record& r )
:data(r.data), key(r.key){}
Record::~Record(){}
Record& Record::operator= ( const Record& r )
{
data = r.data;
key = r.key;
return *this;
}
DataType Record::Data ( ) const { return data; }
KeyType Record::Key ( ) const { return key; }
DataType& Record::Data ( ) { return data; }
KeyType& Record::Key ( ) { return key; }
bool Record::operator== ( const Record& r ) const
{
return ( key == r.key );
}
bool Record::operator!= ( const Record& r ) const
{
return !(*this == r );
}
bool Record::operator< ( const Record& r ) const
{
return ( key < r.key );
}
bool Record::operator> ( const Record& r ) const
{
return ( key > r.key );
}
bool Record::operator<= ( const Record& r ) const
{
return ! ( *this > r );
}
bool Record::operator>= ( const Record& r ) const
{
return !( *this < r );
}
ostream& operator<< ( ostream& os, const Record& r )
{
os << "Data: " << r.data<< " Key: " << r.key;
return os;
}
void Record::write ( ostream& out ) const
{
data.write( out );
key.write( out );
}
void Record::read ( istream& in )
{
data.read( in );
key.read( in );
}