Core: Stream::GetPtr

git-svn-id: svn://ultimatepp.org/upp/trunk@5843 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-02-20 08:27:48 +00:00
parent 59273a7990
commit 0abe3c1471
2 changed files with 11 additions and 1 deletions

View file

@ -84,6 +84,7 @@ public:
int Get() { return ptr < rdlim ? *ptr++ : _Get(); } int Get() { return ptr < rdlim ? *ptr++ : _Get(); }
const byte *PeekPtr(int size = 1){ ASSERT(size > 0); return ptr + size <= rdlim ? ptr : NULL; } const byte *PeekPtr(int size = 1){ ASSERT(size > 0); return ptr + size <= rdlim ? ptr : NULL; }
const byte *GetPtr(int size = 1) { ASSERT(size > 0); if(ptr + size <= rdlim) { byte *p = ptr; ptr += size; return p; }; return NULL; }
byte *PutPtr(int size = 1) { ASSERT(size > 0); if(ptr + size <= wrlim) { byte *p = ptr; ptr += size; return p; }; return NULL; } byte *PutPtr(int size = 1) { ASSERT(size > 0); if(ptr + size <= wrlim) { byte *p = ptr; ptr += size; return p; }; return NULL; }
void Put(const void *data, int size) { ASSERT(size >= 0); if(ptr + size <= wrlim) { memcpy(ptr, data, size); ptr += size; } else _Put(data, size); } void Put(const void *data, int size) { ASSERT(size >= 0); if(ptr + size <= wrlim) { memcpy(ptr, data, size); ptr += size; } else _Put(data, size); }

View file

@ -383,7 +383,16 @@ nt]_[*@3 size]_`=_[@3 1])&]
[s2; This is a special optimization method; it might return a pointer [s2; This is a special optimization method; it might return a pointer
to data of [%-*@3 size] bytes at current position in the stream, to data of [%-*@3 size] bytes at current position in the stream,
but it is allowed to return NULL `- in that case you need to but it is allowed to return NULL `- in that case you need to
load data into buffer using Get.&] use Get to load data. PeekPtr does not move the position forward,
you need to use some of Seek methods to do that.&]
[s3; &]
[s4;%- &]
[s5;:Stream`:`:GetPtr`(int`):%- [@(0.0.255) const]_[_^byte^ byte]_`*[* GetPtr]([@(0.0.255) in
t]_[*@3 size]_`=_[@3 1])&]
[s2; This is a special optimization method; it might return a pointer
to data of [%-*@3 size] bytes at current position in the stream,
but it is allowed to return NULL `- in that case you need to
use Get to load data. Unlike PeekPtr, it advances stream by [%-*@3 size].&]
[s3; &] [s3; &]
[s4;%- &] [s4;%- &]
[s5;:Stream`:`:PutPtr`(int`):%- [_^byte^ byte]_`*[* PutPtr]([@(0.0.255) int]_[*@3 size]_`=_[@3 1 [s5;:Stream`:`:PutPtr`(int`):%- [_^byte^ byte]_`*[* PutPtr]([@(0.0.255) int]_[*@3 size]_`=_[@3 1