Пример #1
0
	void string::resize(size_t n, char c)
	{
		if (n < size())
		{
			dataAllocator::destroy(start_ + n, finish_);
			finish_ = start_ + n;
		}
		else if (n > size() && n <= capacity())
		{
			auto lengthOfInsert = n - size();
			finish_ = mystl::uninitialized_fill_n(finish_, lengthOfInsert, c);
		}
		else if (n > capacity())
		{
			auto lengthOfInsert = n - size();
			iterator newStart = dataAllocator::allocate(getNewCapacity(lengthOfInsert));
			iterator newFinish = mystl::uninitialized_copy(begin(), end(), newStart);
			newFinish = mystl::uninitialized_fill_n(newFinish, lengthOfInsert, c);

			destroyAndDeallocate();
			start_ = newStart;
			finish_ = newFinish;
			endOfStorage_ = start_ + n;
		}
	}
Пример #2
0
// MANIPULATORS
void DatumMapBuilder::append(const DatumMapEntry *entries,
                             SizeType             size)
{
    BSLS_ASSERT(0 != entries && 0 != size);

    // Get the new map capacity.

    SizeType newCapacity = d_capacity ?
                      getNewCapacity(d_capacity, *d_mapping.size() + size) :
                      getNewCapacity(d_capacity, size);

    // If the initial capacity was zero, create an empty map with the new
    // capacity.

    if (!d_capacity) {
        d_capacity = newCapacity;
        createMapStorage(&d_mapping, d_capacity, d_allocator_p);
        *d_mapping.sorted() = d_sorted;
    }
    if (newCapacity != d_capacity) {
        // Capacity has to be increased.

        d_capacity = newCapacity;

        // Create a new map with the higher capacity.

        DatumMutableMapRef mapping;
        createMapStorage(&mapping, d_capacity, d_allocator_p);

        // Copy the existing data and dispose the old map.

        *mapping.size() = *d_mapping.size();
        bsl::memcpy(mapping.data(),
                    d_mapping.data(),
                    sizeof(DatumMapEntry) * (*d_mapping.size()));
        Datum::disposeUninitializedMap(d_mapping, d_allocator_p);
        d_mapping = mapping;
    }

    // Copy the new elements.

    bsl::memcpy(d_mapping.data() + *d_mapping.size(),
                entries,
                sizeof(DatumMapEntry) * size);
    *d_mapping.size() += size;
}
Пример #3
0
 string::iterator string::insert_aux_filln(iterator p, size_t n, value_type c){
     auto newCapacity = getNewCapacity(n);
     iterator newStart = dataAllocator::allocate(newCapacity);
     iterator newFinish = std::uninitialized_fill_n(start_, n, c);
     auto res = newFinish;
     newFinish = std::uninitialized_copy(p,finish_,newFinish);
     destroyAndDeallocate();
     start_ = newStart;
     finish_ = newFinish;
     endOfStorage_ = start_ + newCapacity;
     return res;
     
 }
Пример #4
0
// MANIPULATORS
void DatumArrayBuilder::append(const Datum *values, SizeType length)
{
    BSLS_ASSERT(0 == d_capacity || 0 != d_array.data());

    // Get the new array capacity.
    SizeType newCapacity = d_capacity ?
                       getNewCapacity(d_capacity, *d_array.length() + length) :
                       getNewCapacity(d_capacity, length);

    // If the initial capacity was zero, create an array with the new capacity.
    if (!d_capacity) {
        createArrayStorage(&d_array, newCapacity, d_allocator_p);
        d_capacity = newCapacity;
    }
    else if (d_capacity < newCapacity) {
        // Create a new array with the higher capacity.
        DatumMutableArrayRef array;
        createArrayStorage(&array, newCapacity, d_allocator_p);

        // Copy the existing data and dispose the old array.
        *array.length() = *d_array.length();
        bsl::memcpy(array.data(),
                    d_array.data(),
                    sizeof(Datum) * (*d_array.length()));
        Datum::disposeUninitializedArray(d_array, d_allocator_p);

        d_array    = array;
        d_capacity = newCapacity;
    }

    // Copy the new elements.
    bsl::memcpy(d_array.data() + *d_array.length(),
                values,
                sizeof(Datum) * length);
    *d_array.length() += length;
}