-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpf_pagehandle.cc
125 lines (110 loc) · 3.02 KB
/
pf_pagehandle.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// File: pf_pagehandle.cc
// Description: PF_PageHandle class implementation
// Authors: Hugo Rivero ([email protected])
// Dallan Quass ([email protected])
//
#include "pf_internal.h"
//
// Defines
//
#define INVALID_PAGE (-1)
//
// PF_PageHandle
//
// Desc: Default constructor for a page handle object
// A page handle object provides access to the contents of a page
// and the page's page number. The page handle object is constructed
// here but it must be passed to one of the PF_FileHandle methods to
// have it refer to a pinned page before it can be used to access the
// contents of a page. Remember to call PF_FileHandle::UnpinPage()
// to unpin the page when you are finished accessing it.
//
PF_PageHandle::PF_PageHandle()
{
pageNum = INVALID_PAGE;
pPageData = NULL;
}
//
// ~PF_PageHandle
//
// Desc: Destroy the page handle object.
// If the page handle object refers to a pinned page, the page will
// NOT be unpinned.
//
PF_PageHandle::~PF_PageHandle()
{
// Don't need to do anything
}
//
// PF_PageHandle
//
// Desc: Copy constructor
// If the incoming page handle object refers to a pinned page,
// the page will NOT be pinned again.
// In: pageHandle - page handle object from which to construct this object
//
PF_PageHandle::PF_PageHandle(const PF_PageHandle &pageHandle)
{
// Just copy the local variables since there is no local memory
// allocation involved
this->pageNum = pageHandle.pageNum;
this->pPageData = pageHandle.pPageData;
}
//
// operator=
//
// Desc: overload = operator
// If the page handle object on the rhs refers to a pinned page,
// the page will NOT be pinned again.
// In: pageHandle - page handle object to set this object equal to
// Ret: reference to *this
//
PF_PageHandle& PF_PageHandle::operator= (const PF_PageHandle &pageHandle)
{
// Check for self-assignment
if (this != &pageHandle) {
// Just copy the pointers since there is no local memory
// allocation involved
this->pageNum = pageHandle.pageNum;
this->pPageData = pageHandle.pPageData;
}
// Return a reference to this
return (*this);
}
//
// GetData
//
// Desc: Access the contents of a page. The page handle object must refer
// to a pinned page.
// Out: pData - Set pData to point to the page contents
// Ret: PF return code
//
RC PF_PageHandle::GetData(char *&pData) const
{
// Page must refer to a pinned page
if (pPageData == NULL)
return (PF_PAGEUNPINNED);
// Set pData to point to page contents (after PF header)
pData = pPageData;
// Return ok
return (0);
}
//
// GetPageNum
//
// Desc: Access the page number. The page handle object must refer to
// a pinned page.
// Out: pageNum - contains the page number
// Ret: PF return code
//
RC PF_PageHandle::GetPageNum(PageNum &_pageNum) const
{
// Page must refer to a pinned page
if (pPageData == NULL)
return (PF_PAGEUNPINNED);
// Set page number
_pageNum = this->pageNum;
// Return ok
return (0);
}