Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes
morkSpool Class Reference

#include <morkSink.h>

Inheritance diagram for morkSpool:
Inheritance graph
[legend]
Collaboration diagram for morkSpool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void FlushSink (morkEnv *ev)
virtual void SpillPutc (morkEnv *ev, int c)
virtual ~morkSpool ()
 morkSpool (morkEnv *ev, morkCoil *ioCoil)
mork_bool Seek (morkEnv *ev, mork_pos inPos)
mork_bool Write (morkEnv *ev, const void *inBuf, mork_size inSize)
mork_bool PutBuf (morkEnv *ev, const morkBuf &inBuffer)
mork_bool PutString (morkEnv *ev, const char *inString)
void Putc (morkEnv *ev, int c)

Static Public Member Functions

static void BadSpoolCursorOrderError (morkEnv *ev)
static void NilSpoolCoilError (morkEnv *ev)

Public Attributes

morkCoilmSpool_Coil
mork_u1mSink_At
mork_u1mSink_End

Detailed Description

Definition at line 146 of file morkSink.h.


Constructor & Destructor Documentation

morkSpool::~morkSpool ( ) [virtual]

Definition at line 171 of file morkSink.cpp.

{
  mSink_At = 0;
  mSink_End = 0;
  mSpool_Coil = 0;
}
morkSpool::morkSpool ( morkEnv ev,
morkCoil ioCoil 
)

Definition at line 181 of file morkSink.cpp.

: morkSink()
, mSpool_Coil( 0 )
{
  mSink_At = 0; // set correctly later in Seek()
  mSink_End = 0; // set correctly later in Seek()
  
  if ( ev->Good() )
  {
    if ( ioCoil )
    {
      mSpool_Coil = ioCoil;
      this->Seek(ev, /*pos*/ 0);
    }
    else
      ev->NilPointerError();
  }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 204 of file morkSink.cpp.

{
  ev->NewError("bad morkSpool cursor order");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void morkSpool::FlushSink ( morkEnv ev) [virtual]

Implements morkSink.

Definition at line 67 of file morkSink.cpp.

{
  morkCoil* coil = mSpool_Coil;
  if ( coil )
  {
    mork_u1* body = (mork_u1*) coil->mBuf_Body;
    if ( body )
    {
      mork_u1* at = mSink_At;
      mork_u1* end = mSink_End;
      if ( at >= body && at <= end ) // expected cursor order?
      {
        mork_fill fill = (mork_fill) (at - body); // current content size
        if ( fill <= coil->mBlob_Size )
          coil->mBuf_Fill = fill;
        else
        {
          coil->BlobFillOverSizeError(ev);
          coil->mBuf_Fill = coil->mBlob_Size; // make it safe
        }
      }
      else
        this->BadSpoolCursorOrderError(ev);
    }
    else
      coil->NilBufBodyError(ev);
  }
  else
    this->NilSpoolCoilError(ev);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 210 of file morkSink.cpp.

{
  ev->NewError("nil mSpool_Coil");
}

Here is the call graph for this function:

Here is the caller graph for this function:

mork_bool morkSpool::PutBuf ( morkEnv ev,
const morkBuf inBuffer 
) [inline]

Definition at line 183 of file morkSink.h.

  { return this->Write(ev, inBuffer.mBuf_Body, inBuffer.mBuf_Fill); }

Here is the call graph for this function:

void morkSink::Putc ( morkEnv ev,
int  c 
) [inline, inherited]

Definition at line 127 of file morkSink.h.

  { 
    if ( mSink_At < mSink_End )
      *mSink_At++ = (mork_u1) c;
    else
      this->SpillPutc(ev, c);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

mork_bool morkSpool::PutString ( morkEnv ev,
const char *  inString 
)

Definition at line 312 of file morkSink.cpp.

{
  if ( inString )
  {
    mork_size size = MORK_STRLEN(inString);
    this->Write(ev, inString, size);
  }
  return ev->Good();
}

Here is the call graph for this function:

mork_bool morkSpool::Seek ( morkEnv ev,
mork_pos  inPos 
)

Definition at line 216 of file morkSink.cpp.

{
  morkCoil* coil = mSpool_Coil;
  if ( coil )
  {
    mork_size minSize = (mork_size) (inPos + 64);
    
    if ( coil->mBlob_Size < minSize )
      coil->GrowCoil(ev, minSize);
      
    if ( ev->Good() )
    {
      coil->mBuf_Fill = (mork_fill) inPos;
      mork_u1* body = (mork_u1*) coil->mBuf_Body;
      if ( body )
      {
        mSink_At = body + inPos;
        mSink_End = body + coil->mBlob_Size;
      }
      else
        coil->NilBufBodyError(ev);
    }
  }
  else
    this->NilSpoolCoilError(ev);
    
  return ev->Good();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void morkSpool::SpillPutc ( morkEnv ev,
int  c 
) [virtual]

Implements morkSink.

Definition at line 99 of file morkSink.cpp.

{
  morkCoil* coil = mSpool_Coil;
  if ( coil )
  {
    mork_u1* body = (mork_u1*) coil->mBuf_Body;
    if ( body )
    {
      mork_u1* at = mSink_At;
      mork_u1* end = mSink_End;
      if ( at >= body && at <= end ) // expected cursor order?
      {
        mork_size size = coil->mBlob_Size;
        mork_fill fill = (mork_fill) (at - body); // current content size
        if ( fill <= size ) // less content than medium size?
        {
          coil->mBuf_Fill = fill;
          if ( at >= end ) // need to grow the coil?
          {
            if ( size > 2048 ) // grow slower over 2K?
              size += 512;
            else
            {
              mork_size growth = ( size * 4 ) / 3; // grow by 33%
              if ( growth < 64 ) // grow faster under (64 * 3)?
                growth = 64;
              size += growth;
            }
            if ( coil->GrowCoil(ev, size) ) // made coil bigger?
            {
              body = (mork_u1*) coil->mBuf_Body;
              if ( body ) // have a coil body?
              {
                mSink_At = at = body + fill;
                mSink_End = end = body + coil->mBlob_Size;
              }
              else
                coil->NilBufBodyError(ev);
            }
          }
          if ( ev->Good() ) // seem ready to write byte c?
          {
            if ( at < end ) // morkSink::Putc() would succeed?
            {
              *at++ = (mork_u1) c;
              mSink_At = at;
              coil->mBuf_Fill = fill + 1;
            }
            else
              this->BadSpoolCursorOrderError(ev);
          }
        }
        else // fill exceeds size
        {
          coil->BlobFillOverSizeError(ev);
          coil->mBuf_Fill = coil->mBlob_Size; // make it safe
        }
      }
      else
        this->BadSpoolCursorOrderError(ev);
    }
    else
      coil->NilBufBodyError(ev);
  }
  else
    this->NilSpoolCoilError(ev);
}

Here is the call graph for this function:

mork_bool morkSpool::Write ( morkEnv ev,
const void inBuf,
mork_size  inSize 
)

Definition at line 248 of file morkSink.cpp.

{
  // This method is conceptually very similar to morkStream::Write(),
  // and this code was written while looking at that method for clues.
 
  morkCoil* coil = mSpool_Coil;
  if ( coil )
  {
    mork_u1* body = (mork_u1*) coil->mBuf_Body;
    if ( body )
    {
      if ( inBuf && inSize ) // anything to write?
      {
        mork_u1* at = mSink_At;
        mork_u1* end = mSink_End;
        if ( at >= body && at <= end ) // expected cursor order?
        {
          // note coil->mBuf_Fill can be stale after morkSink::Putc():
          mork_pos fill = at - body; // current content size
          mork_num space = (mork_num) (end - at); // space left in body
          if ( space < inSize ) // not enough to hold write?
          {
            mork_size minGrowth = space + 16;
            mork_size minSize = coil->mBlob_Size + minGrowth;
            if ( coil->GrowCoil(ev, minSize) )
            {
              body = (mork_u1*) coil->mBuf_Body;
              if ( body )
              {
                mSink_At = at = body + fill;
                mSink_End = end = body + coil->mBlob_Size;
                space = (mork_num) (end - at); // space left in body
              }
              else
                coil->NilBufBodyError(ev);
            }
          }
          if ( ev->Good() )
          {
            if ( space >= inSize ) // enough room to hold write?
            {
              MORK_MEMCPY(at, inBuf, inSize); // into body
              mSink_At = at + inSize; // advance past written bytes
              coil->mBuf_Fill = fill + inSize; // "flush" to fix fill
            }
            else
              ev->NewError("insufficient morkSpool space");
          }
        }
        else
          this->BadSpoolCursorOrderError(ev);
      }
    }
    else
      coil->NilBufBodyError(ev);
  }
  else
    this->NilSpoolCoilError(ev);
  
  return ev->Good();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 113 of file morkSink.h.

Definition at line 114 of file morkSink.h.

Definition at line 158 of file morkSink.h.


The documentation for this class was generated from the following files: