1
/* Copyright (C) 2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include <SimpleProperties.hpp>
17
#include <TransporterDefinitions.hpp>
18
#include "LongSignal.hpp"
20
SimplePropertiesSectionReader::SimplePropertiesSectionReader
21
(struct SegmentedSectionPtr & ptr, class SectionSegmentPool & pool)
33
m_currentSegment = ptr.p;
39
SimplePropertiesSectionReader::reset(){
41
m_currentSegment = m_head;
45
SimplePropertiesSectionReader::step(Uint32 len){
46
if(m_pos + len >= m_len) {
50
while(len > SectionSegment::DataLength){
51
m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
53
len -= SectionSegment::DataLength;
54
m_pos += SectionSegment::DataLength;
57
Uint32 ind = m_pos % SectionSegment::DataLength;
63
if(ind == SectionSegment::DataLength){
65
m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
72
SimplePropertiesSectionReader::getWord(Uint32 * dst){
81
SimplePropertiesSectionReader::peekWord(Uint32 * dst) const {
83
Uint32 ind = m_pos % SectionSegment::DataLength;
84
* dst = m_currentSegment->theData[ind];
91
SimplePropertiesSectionReader::peekWords(Uint32 * dst, Uint32 len) const {
92
if(m_pos + len > m_len){
95
Uint32 ind = (m_pos % SectionSegment::DataLength);
96
Uint32 left = (SectionSegment::DataLength - ind);
97
SectionSegment * p = m_currentSegment;
100
memcpy(dst, &p->theData[ind], 4 * left);
104
left = SectionSegment::DataLength;
105
p = m_pool.getPtr(p->m_nextSegment);
108
memcpy(dst, &p->theData[ind], 4 * len);
113
SimplePropertiesSectionReader::getWords(Uint32 * dst, Uint32 len){
114
if(peekWords(dst, len)){
121
SimplePropertiesSectionWriter::SimplePropertiesSectionWriter(class SectionSegmentPool & pool)
124
Ptr<SectionSegment> first;
125
if(m_pool.seize(first)){
130
m_currentSegment = 0;
137
m_head->m_lastSegment = first.i;
138
m_currentSegment = first.p;
143
SimplePropertiesSectionWriter::reset(){
152
SimplePropertiesSectionWriter::putWord(Uint32 val){
153
return putWords(&val, 1);
157
SimplePropertiesSectionWriter::putWords(const Uint32 * src, Uint32 len){
158
Uint32 left = SectionSegment::DataLength - m_pos;
161
memcpy(&m_currentSegment->theData[m_pos], src, 4 * left);
162
Ptr<SectionSegment> next;
163
if(m_pool.seize(next)){
165
m_prevPtrI = m_currentSegment->m_lastSegment;
166
m_currentSegment->m_nextSegment = next.i;
167
next.p->m_lastSegment = next.i;
168
m_currentSegment = next.p;
174
left = SectionSegment::DataLength;
182
memcpy(&m_currentSegment->theData[m_pos], src, 4 * len);
186
assert(m_pos < (int)SectionSegment::DataLength);
192
SimplePropertiesSectionWriter::getPtr(struct SegmentedSectionPtr & dst){
193
// Set last ptr and size
196
dst.i = m_head->m_lastSegment;
199
m_head->m_lastSegment = m_currentSegment->m_lastSegment;
201
if((m_pos % SectionSegment::DataLength) == 0){
202
m_pool.release(m_currentSegment->m_lastSegment);
203
m_head->m_lastSegment = m_prevPtrI;
208
m_head = m_currentSegment = 0;
216
m_pool.release(m_head->m_lastSegment);
220
m_head = m_currentSegment = 0;