Пример #1
0
char* FILE_LINE_READER::ReadLine() throw( IO_ERROR )
{
    length = 0;

    for(;;)
    {
        if( length >= maxLineLength )
            THROW_IO_ERROR( _( "Maximum line length exceeded" ) );

        if( length >= capacity )
            expandCapacity( capacity * 2 );

        // faster, POSIX compatible fgetc(), no locking.
        int cc = getc_unlocked( fp );
        if( cc == EOF )
            break;

        line[ length++ ] = (char) cc;

        if( cc == '\n' )
            break;
    }

    line[ length ] = 0;

    // lineNum is incremented even if there was no line read, because this
    // leads to better error reporting when we hit an end of file.
    ++lineNum;

    return length ? line : NULL;
}
Пример #2
0
char* STRING_LINE_READER::ReadLine() throw( IO_ERROR )
{
    size_t  nlOffset = lines.find( '\n', ndx );

    if( nlOffset == std::string::npos )
        length = lines.length() - ndx;
    else
        length = nlOffset - ndx + 1;     // include the newline, so +1

    if( length )
    {
        if( length >= maxLineLength )
            THROW_IO_ERROR( _("Line length exceeded") );

        if( length+1 > capacity )   // +1 for terminating nul
            expandCapacity( length+1 );

        wxASSERT( ndx + length <= lines.length() );

        memcpy( line, &lines[ndx], length );

        ndx += length;
    }

    ++lineNum;      // this gets incremented even if no bytes were read

    line[length] = 0;

    return length ? line : NULL;
}
Пример #3
0
char* INPUTSTREAM_LINE_READER::ReadLine() throw( IO_ERROR )
{
    length  = 0;

    for(;;)
    {
        if( length >= maxLineLength )
            THROW_IO_ERROR( _( "Maximum line length exceeded" ) );

        if( length + 1 > capacity )
            expandCapacity( capacity * 2 );

        // this read may fail, docs say to test LastRead() before trusting cc.
        char cc = m_stream->GetC();

        if( !m_stream->LastRead() )
            break;

        line[ length++ ] = cc;

        if( cc == '\n' )
            break;
    }

    line[ length ] = 0;

    // lineNum is incremented even if there was no line read, because this
    // leads to better error reporting when we hit an end of file.
    ++lineNum;

    return length ? line : NULL;
}
void Graph:: addEdge(string from, string to, int distance){
	int IndexFrom = findIndex(from);
	int IndexTo = findIndex(to);
	if(IndexFrom != -1 && IndexTo != -1){
		this->AdjacencyMatrix[IndexFrom][IndexTo] = distance;
		this->AdjacencyMatrix[IndexTo][IndexFrom] = distance;
	}
	else{
		if((this->Capacity - this->nrOfCities) < 3){//gör en koll så att det finns mer platser än 1 ifall man måste lägga in from och to
			expandCapacity();
		}
		if(IndexFrom == -1){
			this->Cities[this->nrOfCities] = from;
			this->nrOfCities++;
		}
		if(IndexTo == -1){
			this->Cities[this->nrOfCities] = to;
			this->nrOfCities++;
		}
		IndexFrom = findIndex(from);
		IndexTo = findIndex(to);
		this->AdjacencyMatrix[IndexFrom][IndexTo] = distance;
		this->AdjacencyMatrix[IndexTo][IndexFrom] = distance;
	}
}
Пример #5
0
template<class T> T* Stack<T>::push_back()
{
	if (m_size == m_capacity) {
		expandCapacity();			
	}
	T* res = &m_array[m_size];
	m_size++;
	return res;
}
Пример #6
0
UString &UString::append(const char *t)
{
  int thisSize = size();
  int thisOffset = rep->offset;
  int tSize = strlen(t);
  int length = thisSize + tSize;

  // possible cases:
  if (thisSize == 0) {
    // this is empty
    *this = t;
  } else if (tSize == 0) {
    // t is empty, we'll just return *this below.
  } else if (!rep->baseString && rep->rc == 1) {
    // this is direct and has refcount of 1 (so we can just alter it directly)
    expandCapacity(thisOffset + length);
    UChar *d = const_cast<UChar *>(data());
    for (int i = 0; i < tSize; ++i)
      d[thisSize+i] = t[i];
    rep->len = length;
    rep->_hash = 0;
  } else if (thisOffset + thisSize == usedCapacity()) {
    // this string reaches the end of the buffer - extend it
    expandCapacity(thisOffset + length);
    UChar *d = const_cast<UChar *>(data());
    for (int i = 0; i < tSize; ++i)
      d[thisSize+i] = t[i];
    Rep *newRep = Rep::create(rep, 0, length);
    release();
    rep = newRep;
  } else {
    // this is shared with someone using more capacity, gotta make a whole new string
    int newCapacity = expandedSize(length, 0);
    UChar *d = static_cast<UChar *>(malloc(sizeof(UChar) * newCapacity));
    memcpy(d, data(), thisSize * sizeof(UChar));
    for (int i = 0; i < tSize; ++i)
      d[thisSize+i] = t[i];
    release();
    rep = Rep::create(d, length);
    rep->capacity = newCapacity;
  }

  return *this;
}
Пример #7
0
	void PQueue<ElemType>::enqueue(ElemType newValue) {
		if (count == capacity) expandCapacity();
		arr[count++] = newValue;
		int child = count - 1, parent = count / 2 - 1;
		while (parent >= 0 && cmp(arr[child], arr[parent]) > 0) {
			swap(arr[child], arr[parent]);
			child = parent;
			parent = (child + 1) / 2 - 1; 
		}
	}
Пример #8
0
void sMap<ValueType>::put(std::string key, ValueType value) {
        int index = findKey(key);
        if (index == -1) {
                if (count == capacity) expandCapacity();
                index = count++;
                array[index].key = key;
        }

        array[index].value = value;
}
Пример #9
0
UString &UString::append(unsigned short c)
{
  int thisOffset = rep->offset;
  int length = size();

  // possible cases:
  if (length == 0) {
    // this is empty - must make a new rep because we don't want to pollute the shared empty one 
    int newCapacity = expandedSize(1, 0);
    UChar *d = static_cast<UChar *>(malloc(sizeof(UChar) * newCapacity));
    d[0] = c;
    release();
    rep = Rep::create(d, 1);
    rep->capacity = newCapacity;
  } else if (!rep->baseString && rep->rc == 1) {
    // this is direct and has refcount of 1 (so we can just alter it directly)
    expandCapacity(thisOffset + length + 1);
    UChar *d = const_cast<UChar *>(data());
    d[length] = c;
    rep->len = length + 1;
    rep->_hash = 0;
  } else if (thisOffset + length == usedCapacity()) {
    // this reaches the end of the string - extend it and share
    expandCapacity(thisOffset + length + 1);
    UChar *d = const_cast<UChar *>(data());
    d[length] = c;
    Rep *newRep = Rep::create(rep, 0, length + 1);
    release();
    rep = newRep;
  } else {
    // this is shared with someone using more capacity, gotta make a whole new string
    int newCapacity = expandedSize((length + 1), 0);
    UChar *d = static_cast<UChar *>(malloc(sizeof(UChar) * newCapacity));
    memcpy(d, data(), length * sizeof(UChar));
    d[length] = c;
    release();
    rep = Rep::create(d, length);
    rep->capacity = newCapacity;
  }

  return *this;
}
Пример #10
0
inline void DOMBuffer::
append (const XMLCh* const chars, const XMLSize_t count)
{
  if (fIndex + count >= fCapacity)
    expandCapacity(count);

  memcpy(&fBuffer[fIndex], chars, count * sizeof(XMLCh));
  fIndex += count;

  // Keep it null terminated
  fBuffer[fIndex] = 0;
}
Пример #11
0
inline void DOMBuffer::
set (const XMLCh* const chars, const XMLSize_t count)
{
  fIndex = 0;
  if (count >= fCapacity)
    expandCapacity(count);

  memcpy(fBuffer, chars, count * sizeof(XMLCh));
  fIndex = count;

  // Keep it null terminated
  fBuffer[fIndex] = 0;
}
Пример #12
0
StringBuffer *StringBuffer::append(char *str) {
    pthread_mutex_lock(&mutex_lock);
    if (str == NULL) {
        str = "null";
    }
    int len, newcount;
    klee_make_symbolic(&len, sizeof(len), "len");
	len = strlen(str);
	newcount = buffcount + len;//newcount = count + len;  //Nuno
	if (newcount > value_length)
	    expandCapacity(newcount);
    //memcpy(value + count, str, len);
	// count = newcount;
    buffcount = newcount;  //Nuno
	pthread_mutex_unlock(&mutex_lock);
	return this;
}
Пример #13
0
StringBuffer *StringBuffer::append(StringBuffer *sb) {
    pthread_mutex_lock(&mutex_lock);
    if (sb == NULL) {
        sb = new StringBuffer("null");
    }
    int len, newcount;
    klee_make_symbolic(&len, sizeof(len), "len");
    len = sb->length();
    newcount = sbcount + len; //newcount = count + len;  //Nuno
    if (newcount > value_length)
        expandCapacity(newcount);
    sb->getChars(0, len, value, sbcount); //Nuno
   // count = newcount;
    sbcount = newcount;  //Nuno
    pthread_mutex_unlock(&mutex_lock);
    return this;
}