root/version_0/ext2/page.cpp

Revision 635, 1.8 kB (checked in by blackhedd, 1 year ago)

temporary branch to hold some code that isn't ready for prime time yet.
This will be deleted when no longer needed.

Line 
1 /*****************************************************************************
2
3 $Id: page.cpp 318 2007-05-22 22:06:24Z blackhedd $
4
5 File:     page.cpp
6 Date:     30Apr06
7
8 Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9 Gmail: blackhedd
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of either: 1) the GNU General Public License
13 as published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version; or 2) Ruby's License.
15
16 See the file COPYING for complete licensing information.
17
18 *****************************************************************************/
19
20
21 #include "project.h"
22
23
24 /******************
25 PageList::PageList
26 ******************/
27
28 PageList::PageList()
29 {
30 }
31
32
33 /*******************
34 PageList::~PageList
35 *******************/
36
37 PageList::~PageList()
38 {
39         while (HasPages())
40                 PopFront();
41 }
42
43
44 /***************
45 PageList::Front
46 ***************/
47
48 void PageList::Front (const char **page, int *length)
49 {
50         assert (page && length);
51
52         if (HasPages()) {
53                 Page p = Pages.front();
54                 *page = p.Buffer;
55                 *length = p.Size;
56         }
57         else {
58                 *page = NULL;
59                 *length = 0;
60         }
61 }
62
63
64 /******************
65 PageList::PopFront
66 ******************/
67
68 void PageList::PopFront()
69 {
70         if (HasPages()) {
71                 Page p = Pages.front();
72                 Pages.pop_front();
73                 if (p.Buffer)
74                         free ((void*)p.Buffer);
75         }
76 }
77
78
79 /******************
80 PageList::HasPages
81 ******************/
82
83 bool PageList::HasPages()
84 {
85         return (Pages.size() > 0) ? true : false;
86 }
87
88
89 /**************
90 PageList::Push
91 **************/
92
93 void PageList::Push (const char *buf, int size)
94 {
95         if (buf && (size > 0)) {
96                 char *copy = (char*) malloc (size);
97                 if (!copy)
98                         throw runtime_error ("no memory in pagelist");
99                 memcpy (copy, buf, size);
100                 Pages.push_back (Page (copy, size));
101         }
102 }
103
104
105
106
107
Note: See TracBrowser for help on using the browser.