FrontPage|FindPage|TitleIndex|RecentChanges|RSS source_buffer.cc
 
/*----------------------------------------------------------
 buffer.cc by biscuit@actoz.com 
 for Linux 2.6.x

 v1.1 06/24/2004 View ÇÔ¼ö ±¸ÇöÁß ¹ö±×¼öÁ¤
 v1.0 06/24/2004 first release

---------------------------------------------------------- */
#include <string.h>
#include "buffer.h"

int TBinQueue::Push(const int nsize, const char *buffer)
{
    if(tail + nsize >= maxsize) return -1; // overflow

    memcpy(&buf[tail], buffer, nsize);
    tail += nsize;

    return (tail - head); // stored data size
}

int TBinQueue::Skip(const int skipsize)
{
    head += skipsize;

    if(head == tail){
        head = tail = 0;
    }

    return (tail - head);
}

int TBinQueue::Pop(const int maxsize, char *outbuffer)
{
    int viewsize = View(maxsize, outbuffer);
    Skip(viewsize); // recalc head & tail

    return viewsize;
}

int TBinQueue::View(const int maxsize, char *outbuffer) const
{
    int copysize = maxsize;
    int datasize = (tail - head);

    if( datasize < maxsize ) copysize = datasize;
    if( copysize < 1) return 0;

    memcpy(outbuffer, &buf[head], copysize);

    return copysize;
} 

last modified 2004-06-24 15:21:09
EditText|FindPage|DeletePage|LikePages|