18 #ifndef DATA_BUFFER2_HPP
19 #define DATA_BUFFER2_HPP
27 template <U
int32 sz,
typename Pool>
34 NdbOut& print(NdbOut& out){
35 out <<
"[DataBuffer<" << sz <<
">::Segment this="
36 <<
this << dec <<
" nextPool= "
53 void init() { used = 0; firstItem = lastItem = RNIL; }
71 this->used = src.used;
72 this->firstItem = src.firstItem;
73 this->lastItem = src.lastItem;
100 void print(FILE*)
const;
111 void print(FILE* out) {
112 fprintf(out,
"[DataBufferIterator curr.i=%d, data=%p, ind=%d, pos=%d]\n",
113 curr.i, (
void*) data, ind, pos);
117 inline bool isNull()
const {
return curr.isNull();}
118 inline void setNull() { curr.setNull(); data = 0; ind = pos = RNIL;}
129 inline bool isNull()
const {
return curr.isNull();}
130 inline void setNull() { curr.setNull(); data = 0; ind = pos = RNIL;}
173 bool append(
const Uint32* src, Uint32 len);
175 static void createRecordInfo(
Record_info & ri, Uint32 type_id);
185 bool import(Uint32 pos,
const Uint32* src, Uint32 len);
188 template<U
int32 sz,
typename Pool>
205 template<U
int32 sz,
typename Pool>
211 template<U
int32 sz,
typename Pool>
214 return (it.pos + len < head.used);
217 template<U
int32 sz,
typename Pool>
231 template<U
int32 sz,
typename Pool>
235 const Uint32* src, Uint32 len)
237 Uint32 ind = (it.pos % sz);
238 Uint32 left = sz - ind;
243 memcpy(p->data+ind, src, 4 * left);
253 p =
static_cast<Segment*
>(thePool.getPtr(p->nextPool));
254 memcpy(p->data, src, 4 * sz);
261 p =
static_cast<Segment*
>(thePool.getPtr(p->nextPool));
262 memcpy(p->data, src, 4 * len);
268 template<U
int32 sz,
typename Pool>
275 Uint32 pos = head.used;
281 if(
position(it, pos) &&
import(it, src, len)){
288 template<U
int32 sz,
typename Pool>
291 fprintf(out,
"[DataBuffer used=%d words, segmentsize=%d words",
294 if (head.firstItem == RNIL) {
295 fprintf(out,
": No segments seized.]\n");
302 ptr.i = head.firstItem;
305 for(; ptr.i != RNIL; ){
306 ptr.p = (
Segment*)thePool.getPtr(ptr.i);
307 const Uint32 * rest = ptr.p->data;
308 for(Uint32
i = 0;
i<sz;
i++){
309 fprintf(out,
" H'%.8x", rest[
i]);
315 ptr.i = ptr.p->nextPool;
317 fprintf(out,
" ]\n");
320 template<U
int32 sz,
typename Pool>
325 template<U
int32 sz,
typename Pool>
331 if(head.firstItem == RNIL)
337 rest = (sz - (head.used % sz)) % sz;
341 ndbout_c(
"seize(%u) used: %u rest: %u firstItem: 0x%x",
342 n, head.used, rest, head.firstItem);
350 Uint32 used = head.used +
n;
354 first.nextPool = RNIL;
359 if (thePool.seize(tmp))
361 currPtr.p->nextPool = tmp.i;
363 currPtr.p =
static_cast<Segment*
>(tmp.p);
375 if (thePool.seize(tmp))
377 currPtr.p->nextPool = tmp.i;
379 currPtr.p =
static_cast<Segment*
>(tmp.p);
387 if (head.firstItem == RNIL)
389 head.firstItem = first.nextPool;
393 Segment* lastPtr =
static_cast<Segment*
>(thePool.getPtr(head.lastItem));
394 lastPtr->nextPool = first.nextPool;
398 head.lastItem = currPtr.i;
399 currPtr.p->nextPool = RNIL;
403 currPtr.i = first.nextPool;
404 while (currPtr.i != RNIL)
406 currPtr.p =
static_cast<Segment*
>(thePool.getPtr(currPtr.i));
410 currPtr.i = currPtr.p->nextPool;
411 thePool.release(tmp);
416 template<U
int32 sz,
typename Pool>
421 tmp.i = head.firstItem;
422 while (tmp.i != RNIL)
424 tmp.p = thePool.getPtr(tmp.i);
425 Uint32 next =
static_cast<Segment*
>(tmp.p)->nextPool;
426 thePool.release(tmp);
431 template<U
int32 sz,
typename Pool>
438 template<U
int32 sz,
typename Pool>
444 bool ret = first(tmp);
449 template<U
int32 sz,
typename Pool>
453 ConstDataBufferIterator tmp;
455 bool ret = next(tmp);
460 template<U
int32 sz,
typename Pool>
464 ConstDataBufferIterator tmp;
466 bool ret = next(tmp, hops);
471 template<U
int32 sz,
typename Pool>
475 it.curr.i = head.firstItem;
476 if(it.curr.i == RNIL){
480 it.curr.p =
static_cast<Segment*
>(thePool.getPtr(it.curr.i));
481 it.data = &it.curr.p->data[0];
487 template<U
int32 sz,
typename Pool>
494 if(it.ind < sz && it.pos < head.used){
498 if(it.pos < head.used){
499 it.curr.i = it.curr.p->nextPool;
501 if(it.curr.i == RNIL){
511 ErrorReporter::handleAssert(
"DataBuffer2<sz, Pool>::next", __FILE__, __LINE__);
514 it.curr.p =
static_cast<Segment*
>(thePool.getPtr(it.curr.i));
515 it.data = &it.curr.p->data[0];
523 template<U
int32 sz,
typename Pool>
528 for (Uint32
i=0;
i<hops;
i++) {
534 if(it.pos + hops < head.used){
536 it.curr.i = it.curr.p->nextPool;
537 it.curr.p =
static_cast<Segment*
>(thePool.getPtr(it.curr.i));
545 it.data = &it.curr.p->data[it.ind];
549 it.curr.i = it.curr.p->nextPool;
550 it.curr.p =
static_cast<Segment*
>(thePool.getPtr(it.curr.i));
552 it.data = &it.curr.p->data[it.ind];
560 template<U
int32 sz,
typename Pool>
567 template<U
int32 sz,
typename Pool>
571 return (head.used == 0);
574 template<U
int32 sz,
typename Pool>
580 const char * off_base = (
char*)&tmp;
581 const char * off_next = (
char*)&tmp.nextPool;
582 const char * off_magic = (
char*)&tmp.magic;
584 ri.m_size =
sizeof(tmp);
585 ri.m_offset_next_pool = Uint32(off_next - off_base);
586 ri.m_offset_magic = Uint32(off_magic - off_base);
587 ri.m_type_id = type_id;
590 template<U
int32 sz,
typename Pool>
595 this->curr.i = src.curr.i;
596 this->curr.p =
const_cast<Segment*
>(src.curr.p);
597 this->data =
const_cast<Uint32*
>(src.data);
602 template<U
int32 sz,
typename Pool>
607 this->curr.i = src.curr.i;
608 this->curr.p = src.curr.p;
609 this->data = src.data;