56 if (sz==0) sz = src.fullsize();
59 if ((sz <= rawsize()) && (sz <= src.rawsize())) {
60 ::memcpy(ptr(), src(), sz);
64 if (sz > src.fullsize()) {
65 EOUT(
"source pointer has no so much memory %u", (
unsigned) sz);
69 if (sz > fullsize()) {
70 EOUT(
"target pointer has no so much memory %u", (
unsigned) sz);
74 Pointer tgtptr(*
this), srcptr(src);
78 unsigned copylen = (tgtptr.rawsize() < srcptr.
rawsize()) ? tgtptr.rawsize() : srcptr.
rawsize();
79 if (copylen>sz) copylen = sz;
80 if (copylen==0)
break;
82 ::memcpy(tgtptr(), srcptr(), copylen);
86 tgtptr.shift(copylen);
87 srcptr.
shift(copylen);
95 return src.copyfrom(*
this, sz ? sz : fullsize());
102 if (sz <= rawsize()) {
103 ::memcpy(tgt, ptr(), sz);
114 if (sz > fullsize()) {
115 EOUT(
"target pointer has no so much memory %lu", sz);
119 if (sz==0)
return sz;
123 throw dabc::Exception(
ex_Pointer,
"Cannot copy memory outside current segment, use Buffer::copyfrom() method",
"Pointer");
125 ::memcpy(ptr(), src, sz);
131 return str ? copyfrom(str, len ? len : strlen(str)) : 0;
136 if (fBuf != child.
fBuf)
139 if (fSegm==child.
fSegm)
140 return (fPtr <= child.
fPtr) ? (child.
fPtr - fPtr) : -(fPtr - child.
fPtr);
152 return dist + (child.
fPtr - left.
fPtr);
158 return (bufsz == 0) ? 0. : 1. * distance_to_ownbuf() / bufsz;
unsigned NumSegments() const
Returns number of segment in buffer.
unsigned SegmentSize(unsigned n=0) const
Returns size on the segment, no any boundary checks.
void * SegmentPtr(unsigned n=0) const
Returns pointer on the segment, no any boundary checks.
Manipulator with dabc::Buffer class.
BufferSize_t shift(BufferSize_t sz)
BufferSize_t fRawSize
size of contiguous memory, pointed by fPtr
int distance_to(const Pointer &child) const
unsigned char * fPtr
pointer on the raw buffer
BufferSize_t copyfrom(const Pointer &src, BufferSize_t sz=0)
Returns actual size copied.
BufferSize_t copyto(void *tgt, BufferSize_t sz) const
void long_shift(BufferSize_t sz)
BufferSize_t copyfromstr(const char *str, unsigned len=0)
float consumed_size() const
Returns ratio between filled size and buffer size, 0 when exmpy.
BufferSize_t rawsize() const
Buffer fBuf
we keep reference on the buffer, could be only used in same thread
BufferSize_t fFullSize
full size of memory from pointer till the end