示例#1
0
int pstring_t<F>::pcmp(const pstring_t &right) const
{
	std::size_t l = std::min(blen(), right.blen());
	if (l == 0)
	{
		if (blen() == 0 && right.blen() == 0)
			return 0;
		else if (right.blen() == 0)
			return 1;
		else
			return -1;
	}
	auto si = this->begin();
	auto ri = right.begin();
	while (si != this->end() && *si == *ri)
	{
		ri++;
		si++;
	}
	int ret = (si == this->end() ? 0 : *si - *ri);
	if (ret == 0)
	{
		if (this->blen() > right.blen())
			ret = 1;
		else if (this->blen() < right.blen())
			ret = -1;
	}
	return ret;
}
int filebuf::underflow()
{
    if( ! opened  ||  (mode & (ios::in | ios::out)) == ios::out )
        return EOF;

    if( in_avail() )    // no action needed
        return (unsigned char) *gptr();

    int c;  // the return value
    int count;  // input character count

    if ( ! unbuffered()  &&  base() )
        {     // this is buffered

        if (sync() != 0)
                return EOF;

        // find buffer data
        int pb = (blen() > 8) ? 4 : 1;  // putback area size
        char *b = base();

        // read in a new buffer
        count = ::read(xfd, b+pb, blen()-pb);
        if( count == OS_err )
            return EOF;

        // set up get and put areas
        setg(b, b+pb, b+pb+count);
        setp(b+pb, b+pb);

        if( count )
            c = (unsigned char) *gptr();
        }
    else
        {     // this is not buffered
        count = ::read(xfd, lahead, 1);
        if( count == OS_err)
            {
            c = EOF;
            setg(0, 0, 0);
            }
        else
            {
            c = (unsigned char)lahead[0];
            setg(lahead, lahead, lahead+1);
            }
        }

    if( ! count )
        c = EOF;    // end of file

    return c;
}
int
Mystreambuf::sync (void)
{
    if (!unbuffered())
    {
        overflow ();                // Force output
        char * gp = base();
        setp (gp, gp + blen() / 2);
        gp = base() + blen() / 2;
        setg (0, 0, 0);
    }
    return 0;
}
示例#4
0
int	
PRfilebuf::underflow()
{
    int count;
    unsigned char tbuf;

    if (in_avail())
        return (int)(unsigned char) *gptr();

    if (allocate()==EOF)        // make sure there is a reserve area
        return EOF;
    if (PRfilebuf::sync()==EOF)
        return EOF;

    if (unbuffered())
        {
        if (PR_Read(_fd,(void *)&tbuf,1)<=0)
            return EOF;
        return (int)tbuf;
        }

    if ((count=PR_Read(_fd,(void *)base(),blen())) <= 0)
        return EOF;     // reached EOF
    setg(base(),base(),base()+count);
    return (int)(unsigned char) *gptr();
}
示例#5
0
int _ALControlStream::overflow( int ch )
{
    if ( !base() ) {
        if ( allocate() == EOF )
            return EOF;
        setg( 0, 0, 0 );
    } else {
        if ( out_waiting() ) {
            if ( sync() == EOF )
                return EOF;
        }
    }
    int bl = blen();
    setp( base(), base() + bl - 2 );
    if ( pptr() < epptr() ) {
        *pptr() = (char) ch;
        pbump( 1 );
    } else {
        *pptr() = (char ) ch;
        pbump( 1 );
        *pptr() = '\0';
        pbump( 1 );
        SendMessage( hWindow,
                     EM_REPLACESEL,
                     0,
                     (LPARAM) ( (LPSTR) pbase() ) );
    }
    return 0;
}
示例#6
0
int gzfilebuf::overflow( int c ) {

  if ( !is_open() || !(mode & ios::out) )
    return EOF;

  if ( !base() ) {
    if ( allocate() == EOF )
      return EOF;
    setg(0,0,0);
  } else {
    if (in_avail()) {
	return EOF;
    }
    if (out_waiting()) {
      if (flushbuf() == EOF)
	return EOF;
    }
  }

  int bl = blen();
  setp( base(), base() + bl);

  if ( c != EOF ) {

    *pptr() = c;
    pbump(1);

  }

  return 0;

}
示例#7
0
bool pstring_t<F>::endsWith(const pstring_t &arg) const
{
	if (arg.blen() > blen())
		return false;
	else
		return std::equal(arg.c_str(), arg.c_str() + arg.blen(), c_str()+this->blen()-arg.blen());
}
示例#8
0
    static void unpack_envelope(MPI_Datatype type, flat_repr& f) {
        int num_ints, num_addr, num_dt, comb;
        MPI_Type_get_envelope(type, &num_ints, &num_addr, &num_dt, &comb);

        if (comb == MPI_COMBINER_NAMED) {
            //std::cout << "Type: " << builtin_typename_map::get_typeid_name(type) << std::endl;
            f.m.emplace(f.cur_offset, type);
            return;
        }

        // allocate the output for get_contents
        std::vector<int> ints; ints.resize(num_ints);
        std::vector<MPI_Aint> addrs; addrs.resize(num_addr);
        std::vector<MPI_Datatype> types; types.resize(num_dt);

        MPI_Type_get_contents(type, num_ints, num_addr, num_dt,
                              &ints[0], &addrs[0], &types[0]);

        switch(comb) {
          case MPI_COMBINER_DUP:
            MXX_ASSERT(num_ints == 0 && num_addr == 0 && num_dt == 1);
            unpack_envelope(types[0], f);
            break;
          case MPI_COMBINER_CONTIGUOUS:
            std::cout << "Contiguous: " << ints[0] << " x ";
            unpack_envelope(types[0], f);
            break;
          case MPI_COMBINER_VECTOR:
          case MPI_COMBINER_HVECTOR:
          case MPI_COMBINER_INDEXED:
          case MPI_COMBINER_HINDEXED:
          case MPI_COMBINER_INDEXED_BLOCK:
          case MPI_COMBINER_HINDEXED_BLOCK:
            std::cout << "NOT YET SUPPORTED vector/indexed/indexed_block" << std::endl;
            break;
          case MPI_COMBINER_STRUCT:
            {
                int count = ints[0];
                std::vector<int> blen(&ints[1], &ints[0]+count);
                std::vector<MPI_Aint> displ = addrs;
                std::cout << "Struct: " << std::endl;
                MPI_Aint offset = f.cur_offset;
                for (int i = 0; i < count; ++i) {
                    f.cur_offset = offset + displ[i];
                    unpack_envelope(types[i], f);
                }
                f.cur_offset = offset;
            }
            break;
          case MPI_COMBINER_RESIZED:
            // TODO
            std::cout << "resized to [" << addrs[0] << "," << addrs[1] << "): " << std::endl;
            unpack_envelope(types[0], f);
            break;
          case MPI_COMBINER_SUBARRAY:
          case MPI_COMBINER_DARRAY:
            std::cout << "NOT YET SUPPORTED subarray/darray" << std::endl;
            break;
        }
    }
示例#9
0
文件: pstring.cpp 项目: NULUSIOS/mame
pstring_t<F> pstring_t<F>::replace(const pstring_t &search, const pstring_t &replace) const
{
	// FIXME: use this pstringbuffer ret = "";
	pstring_t ret = "";
	const int slen = search.blen();
	const int tlen = blen();

	if (slen == 0 || tlen < slen )
		return *this;
	int i = 0;
	while (i < tlen - slen + 1)
	{
		if (memcmp(cstr()+i,search.cstr(),slen) == 0)
		{
			ret += replace;
			i += slen;
		}
		else
		{
			/* avoid adding a code, cat a string ... */
			mem_t buf[2] = { *(cstr() + i), 0 };
			ret = ret.cat(buf);
			i++;
		}
	}
	ret = ret.cat(cstr() + i);
	return ret;
}
int strstreambuf::doallocate()
{
    char * bptr;
    int size;
    size = __max(x_bufmin,blen() + __max(x_bufmin,1));
    long offset = 0;

    if (x_alloc)
        {
        bptr = (char*)(*x_alloc)(size);
        }
    else
        {
        bptr = _new_crt char[size];
        }
    if (!bptr)
        return EOF;

    if (blen())
        {
        memcpy(bptr, base(), blen());
        offset = bptr - base(); // amount to adjust pointers by
        }
    if (x_free)
        {
        (*x_free)(base());
        }
    else
        {
        delete base();
        }
    setb(bptr,bptr+size,0);     // we handle deallocation

    // adjust get/put pointers too, if necessary
    if (offset)
        if (egptr())
            {
            setg(eback()+offset,gptr()+offset,egptr()+offset);
            }
        if (epptr())
            {
            size = pptr() - pbase();
            setp(pbase()+offset,epptr()+offset);
            pbump(size);
        }
    return(1);
}
示例#11
0
文件: pstring.cpp 项目: NULUSIOS/mame
const pstring_t<F> pstring_t<F>::ucase() const
{
	pstring_t ret = *this;
	ret.pcopy(cstr(), blen());
	for (unsigned i=0; i<ret.len(); i++)
		ret.m_ptr->str()[i] = toupper((unsigned) ret.m_ptr->str()[i]);
	return ret;
}
filebuf* filebuf::open(const char* name, int m, int prot)
{
    if( opened  || ! m )
        return 0;

    // set up "how" parameter to system ::open()
    // we let the OS decide whether the combination is legal
    int how;
    if( m & ios::out )
        {
        if( m & ios::in )
            how = O_rdwr;
        else
            how = O_wronly;
        if( ! (m & ios::nocreate) )
            {
            how |= O_create;
            if( m & ios::noreplace )
                how |= O_excl;
            }
        if( m & ios::trunc )
            how |= O_trunc;
        }
    else if( m & ios::in )
        how = O_rdonly;
    else
        return 0;   // must specfify in, out, or in/out
    if( m & ios::binary )
        how |= O_BINARY;
    else
        how |= O_TEXT;
    if( m & ios::app )
        how |= O_append;

    // now try to open
    int f = ::open(name, how, prot);
    if( f == OS_err )
        return 0;

    // finish up
    xfd = f;
    opened = 1;
    mode = m;
    last_seek = ::lseek(f, 0L, (m & ios::ate) ? L_end : L_set);
    if( last_seek == long(OS_err) )
        return 0;

    char *b = base();       // buffer address
    int pb = b ? ((blen() > 8) ? 4 : 1) : 0;    // putback area size
    setp(b+pb, b+pb);
    setg(b, b+pb, b+pb);

    return this;
}
示例#13
0
文件: pstring.cpp 项目: NULUSIOS/mame
int pstring_t<F>::pcmp(const pstring_t &right) const
{
	long l = std::min(blen(), right.blen());
	if (l == 0)
	{
		if (blen() == 0 && right.blen() == 0)
			return 0;
		else if (right.blen() == 0)
			return 1;
		else
			return -1;
	}
	int ret = memcmp(m_ptr->str(), right.cstr(), l);
	if (ret == 0)
		ret = this->blen() - right.blen();
	if (ret < 0)
		return -1;
	else if (ret > 0)
		return 1;
	else
		return 0;
}
int
Mystreambuf::underflow (void)
{
    int bytes;

        // Handle an unbuffered stream

    if (unbuffered())
    {
        bytes = mptr->read (&_back[1], 1);
        if (!bytes)
        {
            setg (0, 0, 0);
            return EOF;
        }
        setg (_back, _back + 1, _back + 2);
        return (unsigned char)_back[1];
    }

        // Handle a buffered stream

    if (!base())        // Need to allocate a buffer
        allocate();

    if (base())
    {
        char * gp = base() + blen() / 2;
        if (gptr() >= egptr())
        {                   // Read into the buffer from stream
            overflow ();    // Flush output in case we need it
            bytes = mptr->read (gp + 1, blen() / 2 - 1);
            setg (gp, gp + 1, gp + bytes + 1);
        }
        if (gptr() < egptr())   // Get from buffer
            return (unsigned char) *gptr();
    }
    return EOF;
}
int filebuf::overflow(int c)
{
    if( ! opened  ||  (mode & (ios::in | ios::out)) == ios::in )
        return EOF;

    if( unbuffered()  ||  ! base() )
        {
        if( c != EOF )
            {
            char b = c;
            if( ::write(xfd, &b, 1) != 1 )
                return EOF;
            }
        }
    else
        {
        // now we know this is buffered and state is not bad

        // resets get and put areas
        if (sync() != 0)
                return EOF;

        // reset get and put areas
        int pb = (blen() > 8) ? 4 : 1;  // putback area size
        char *b = base();
        setp(b+pb, b+blen());
        setg(b, b+pb, b+pb);

        if( c != EOF )
            {
            sputc(c);
            gbump(1);       // pptr and gptr must be the same
            }
        }
    return 1;
}
示例#16
0
void path_recalculate(unsigned pathid)
{
    path* const pth = pathstructarray[pathid];
    if (!pth) return;
    pth->total_length = 0;
    pth->pointoffset.clear();
    if (!pth->pointarray.size()) return;

    const size_t pc = pth->pointarray.size();
    const path_point& start = pth->closed ? pth->pointarray[pc-1] : pth->pointarray[0];
    const path_point& end  =  pth->closed ? pth->pointarray[0] : pth->pointarray[pc-1];
    //const path_point& beforestart  =  pth->closed ? pth->pointarray[pc-2] : pth->pointarray[0];
    //const path_point& afterend  =  pth->closed ? pth->pointarray[1] : pth->pointarray[pc-1];
    double minx=DBL_MAX,miny=DBL_MAX,maxx=-DBL_MAX,maxy=-DBL_MAX;
    for (size_t i = 0; i < pc; i++)
    {
        const double len =
            (pth->smooth) ?
            //blen(i==0 ? &beforestart : (i==1 ? &start : &pth->pointarray[i-2]), i==0 ? &start : &pth->pointarray[i-1], &pth->pointarray[i])
            //blen(&pth->pointarray[i], i==pc-1 ? &end : &pth->pointarray[i+1], i==pc-2 ? &afterend : (i==pc-1 ? &end : &pth->pointarray[i+2]))
            blen(i==0 ? &start : &pth->pointarray[i-1], &pth->pointarray[i], i+1==pc ? &end : &pth->pointarray[i+1])
            //blen((i==0 || i==1) ? &start : &pth->pointarray[i-2], (i==0) ? &start : &pth->pointarray[i-1], i+1==pc ? &end : &pth->pointarray[i])
            :
            llen(i==0 ? &start : &pth->pointarray[i-1], &pth->pointarray[i]);
        pth->pointarray[i].length = len;
        pth->total_length += len;

        minx = pth->pointarray[i].x<minx ? pth->pointarray[i].x : minx;
        miny = pth->pointarray[i].y<miny ? pth->pointarray[i].y : miny;
        maxx = pth->pointarray[i].x>maxx ? pth->pointarray[i].x : maxx;
        maxy = pth->pointarray[i].y>maxy ? pth->pointarray[i].y : maxy;
    }

    pth->centerx = minx + (maxx-minx)/2;
    pth->centery = miny + (maxy-miny)/2;

    double position = 0;
    for (size_t i = 0; i < pc; i++)
    {
        //if (pth->pointarray[i].length) {
        pth->pointoffset[position/pth->total_length] = i;
        position += pth->pointarray[i].length;
        //std::cout << "Position: " << position << " i: " << i << " length: " << pth->pointarray[i].length << std::endl;
        //}
    }
    //std::cout << "size of pointoffset: " << pth->pointoffset.size() << std::endl;
    //for (ppi_t i = pth->pointoffset.begin(); i != pth->pointoffset.end(); i++) std::cout << i->first << "=>" << i->second << std::endl;
}
示例#17
0
int gzfilebuf::fillbuf() {

  int required;
  char *p;

  p = base();

  required = blen();

  int t = gzread( file, p, required );

  if ( t <= 0) return EOF;

  setg( base(), base(), base()+t);

  return t;

}
int
Mystreambuf::overflow (int c)
{
    int written;

        // Handle unbuffered stream

    if (unbuffered())       // Handle the simple case first
    {
        if (c == EOF)   // Special case, this only flushes
            return 0;
        char ch = char(c);  // Write the byte directly
        written = mptr->write (&ch, 1);
        return (written) ? c : EOF;
    }

        // Handle buffered stream

    if (!base())        // Need to allocate a buffer
        allocate();

    if (base())         // Test for memory allocation error
    {
        char * ep = base() + (blen() / 2);
        if (!pbase())   // Set put pointers if not set up
            setp (base(), ep);
        int bytes = pptr() - pbase();   // Bytes to write
        if (bytes)
        {
            written = mptr->write (pbase(), bytes);
            if (!written)
                return EOF;
            bytes += written;
            if (bytes)  // Some is still waiting to be written
                memcpy (base(), base() + written, bytes);
        }
        setp (base() + bytes, ep);  // Reset 'put' pointers
        return (c == EOF) ? 0 : sputc (c);  // Put pending chr in buf
    }
    return EOF;
}
int stdiobuf::overflow(int c)
{
    if ( ferror(sio) )
        return EOF;

    char *p;
    int count = out_waiting();
    if( count > 0 )
        {
        p = pbase();
        do  {
            putc(*p, sio);
            ++p;
            } while( --count );
        }
    if( c != EOF )
        putc(c, sio);

    char *b = base();
    setp(b+4, b+blen());
    setg(b, b+4, b+4);

    return ferror(sio) ? EOF : 1;
}
示例#20
0
  int strstreambuf::doallocate() {

    char   *oldbuf;
    int     oldbufsize;
    char   *newbuf;
    int     newbufsize;
    size_t  base_offset, ptr_offset, end_offset;

    __lock_it( __b_lock );
    if( !__dynamic || __frozen ) {
        return( EOF );
    }
    oldbuf     = base();
    oldbufsize = blen();
    if( __allocation_size <= oldbufsize ) {
        newbufsize = oldbufsize + DEFAULT_MAINBUF_SIZE;
    } else {
        newbufsize = __allocation_size;
    }
    if( __alloc_fn == NULL ) {
        newbuf = new char [newbufsize];
    } else {
        newbuf = (char *) __alloc_fn( newbufsize );
    }
    if( newbuf == NULL ) {
        return( EOF );
    }
    setb( newbuf, newbuf + newbufsize, false );

    // Copy the get area. This can be done directly by copying bytes and
    // setting new pointers. The size of the get area does not change.
    if( eback() != NULL ) {
        base_offset = (__huge_ptr_int)(eback() - oldbuf);
        ptr_offset  = (__huge_ptr_int)(gptr()  - oldbuf);
        end_offset  = (__huge_ptr_int)(egptr() - oldbuf);
        ::memcpy( newbuf+base_offset, eback(), end_offset-base_offset );
        setg( newbuf+base_offset, newbuf+ptr_offset, newbuf+end_offset );
    }

    // Copy the put area. This can be done directly by copying bytes and
    // setting new pointers. Add the extra bytes allocated above to the
    // end of the put area.
    if( pbase() == NULL ) {
        setp( newbuf, newbuf + newbufsize );
    } else {
        base_offset = (__huge_ptr_int)(pbase() - oldbuf);
        ptr_offset  = (__huge_ptr_int)(pptr()  - oldbuf);
        end_offset  = (__huge_ptr_int)(epptr() - oldbuf);
        ::memcpy( newbuf+base_offset, pbase(), end_offset-base_offset );
        end_offset += newbufsize - oldbufsize;    // grow the put area
        setp( newbuf+base_offset, newbuf+end_offset );
        pbump( ptr_offset - base_offset );
    }

    // Free the old buffer.
    if( oldbuf != NULL ) {
        if( __free_fn == NULL ) {
            delete [] oldbuf;
        } else {
            __free_fn( oldbuf );
        }
    }
    return( __NOT_EOF );
  }