mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / src / kernel / vm / SectionReader.cpp
blobf01ee0112189d6cb7c4b1fb44249bdb3c67d4bcb
1 /* Copyright (c) 2003-2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #include <SectionReader.hpp>
17 #include <TransporterDefinitions.hpp>
18 #include "LongSignal.hpp"
20 #if 0
21 Uint32 m_len;
22 class SectionSegmentPool & m_pool;
23 class SectionSegment * m_head;
24 class SectionSegment * m_currentPos;
25 #endif
27 SectionReader::SectionReader
28 (struct SegmentedSectionPtr & ptr, class SectionSegmentPool & pool)
29 : m_pool(pool)
31 if(ptr.p == 0){
32 m_pos = 0;
33 m_len = 0;
34 m_head = 0;
35 m_currentSegment = 0;
36 } else {
37 m_pos = 0;
38 m_len = ptr.p->m_sz;
39 m_head = ptr.p;
40 m_currentSegment = ptr.p;
44 void
45 SectionReader::reset(){
46 m_pos = 0;
47 m_currentSegment = m_head;
50 bool
51 SectionReader::step(Uint32 len){
52 if(m_pos + len >= m_len) {
53 m_pos++;
54 return false;
56 while(len > SectionSegment::DataLength){
57 m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
59 len -= SectionSegment::DataLength;
60 m_pos += SectionSegment::DataLength;
63 Uint32 ind = m_pos % SectionSegment::DataLength;
64 while(len > 0){
65 len--;
66 m_pos++;
68 ind++;
69 if(ind == SectionSegment::DataLength){
70 ind = 0;
71 m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
74 return true;
77 bool
78 SectionReader::getWord(Uint32 * dst){
79 if (peekWord(dst)) {
80 step(1);
81 return true;
83 return false;
86 bool
87 SectionReader::peekWord(Uint32 * dst) const {
88 if(m_pos < m_len){
89 Uint32 ind = m_pos % SectionSegment::DataLength;
90 * dst = m_currentSegment->theData[ind];
91 return true;
93 return false;
96 bool
97 SectionReader::peekWords(Uint32 * dst, Uint32 len) const {
98 if(m_pos + len > m_len)
99 return false;
101 Uint32 ind = (m_pos % SectionSegment::DataLength);
102 Uint32 left = SectionSegment::DataLength - ind;
103 SectionSegment * p = m_currentSegment;
105 while(len > left){
106 memcpy(dst, &p->theData[ind], 4 * left);
107 dst += left;
108 len -= left;
109 ind = 0;
110 left = SectionSegment::DataLength;
111 p = m_pool.getPtr(p->m_nextSegment);
114 memcpy(dst, &p->theData[ind], 4 * len);
115 return true;
118 bool
119 SectionReader::getWords(Uint32 * dst, Uint32 len){
120 if(m_pos + len > m_len)
121 return false;
123 Uint32 ind = (m_pos % SectionSegment::DataLength);
124 Uint32 left = SectionSegment::DataLength - ind;
125 SectionSegment * p = m_currentSegment;
127 while(len > left){
128 memcpy(dst, &p->theData[ind], 4 * left);
129 dst += left;
130 len -= left;
131 ind = 0;
132 left = SectionSegment::DataLength;
133 p = m_pool.getPtr(p->m_nextSegment);
136 memcpy(dst, &p->theData[ind], 4 * len);
138 m_pos += len;
139 m_currentSegment = p;
140 return true;