// CREATORS explicit UsageType(char c, bslma::Allocator *basicAllocator = 0) : d_data_p(0) , d_allocator_p(bslma::Default::allocator(basicAllocator)) { d_data_p = (char *)d_allocator_p->allocate(sizeof(char)); *d_data_p = c; }
//.. // Finally, we implement 'my_FastCstrArray::operator=' using a // 'bdlma::AutoReleaser' proctor to preserve exception neutrality: //.. // // my_fastcstrarray.cpp // #include <my_fastcstrarray.h> // // // ... // // MANIPULATORS my_FastCstrArray& my_FastCstrArray::operator=(const my_FastCstrArray& rhs) { if (&rhs != this) { d_strPool.release(); d_length = 0; if (rhs.d_length > d_capacity) { char **tmp = d_array_p; d_array_p = (char **)d_allocator_p->allocate( rhs.d_length * sizeof *d_array_p); d_capacity = rhs.d_length; d_allocator_p->deallocate(tmp); } bdlma::AutoReleaser<my_StrPool> autoReleaser(&d_strPool); for (int i = 0; i < rhs.d_length; ++i) { const int size = bsl::strlen(rhs.d_array_p[i]) + 1; d_array_p[i] = (char *)d_strPool.allocate(size); bsl::memcpy(d_array_p[i], rhs.d_array_p[i], size); } d_length = rhs.d_length; autoReleaser.release(); } return *this; }
// CREATORS inline my_Id::my_Id(const char *id, bslma::Allocator *basicAllocator) : d_allocator_p(bslma::Default::allocator(basicAllocator)) { d_buffer_p = (char *)d_allocator_p->allocate(strlen(id) + 1); strcpy(d_buffer_p, id); }
explicit TestType(char c, bslma::Allocator *ba = 0) : d_data_p(0) , d_allocator_p(bslma::Default::allocator(ba)) { ++numCharCtorCalls; d_data_p = (char *)d_allocator_p->allocate(sizeof(char)); *d_data_p = c; }
// CREATORS explicit TestType(bslma::Allocator *basicAllocator = 0) : d_data_p(0) , d_allocator_p(bslma::Default::allocator(basicAllocator)) { ++numDefaultCtorCalls; d_data_p = (char *)d_allocator_p->allocate(sizeof(char)); *d_data_p = '?'; }
explicit TestType(const TestType& original, bslma::Allocator *ba = 0) : d_data_p(0) , d_allocator_p(bslma::Default::allocator(ba)) { ++numCopyCtorCalls; if (&original != this) { d_data_p = (char *)d_allocator_p->allocate(sizeof(char)); *d_data_p = *original.d_data_p; } }
// MANIPULATORS TestType& operator=(const TestType& rhs) { ++numAssignmentCalls; if (&rhs != this) { char *newData = (char *)d_allocator_p->allocate(sizeof(char)); *d_data_p = '_'; d_allocator_p->deallocate(d_data_p); d_data_p = newData; *d_data_p = *rhs.d_data_p; } return *this; }
void testBlobBufferFactory::allocate(btlb::BlobBuffer *buffer) { bsl::shared_ptr<char> shptr( (char *) d_allocator_p->allocate(d_currentBufferSize), d_allocator_p); buffer->reset(shptr, d_currentBufferSize); if (d_growFlag && d_currentBufferSize < 1024) { d_currentBufferSize *= 2; } }
// MANIPULATORS inline void MyClass::setDescription(const char *value) { BSLS_ASSERT_SAFE(value); size_t size = strlen(value) + 1; if (size > d_capacity) { char *newMemory = (char *) d_allocator_p->allocate(size); d_allocator_p->deallocate(d_description_p); d_description_p = newMemory; d_capacity = size; } memcpy(d_description_p, value, size); }
// MANIPULATOR bool insert(const TYPE& value) // If 'value' isn't contained in this 'ListSet', add it and return // 'true', otherwise, return 'false' with no change to the 'ListSet'. { if (count(value)) { return false; // RETURN } Node *node = (Node *) d_allocator_p->allocate(sizeof(Node)); bslalg::ScalarPrimitives::copyConstruct(&node->d_value, value, d_allocator_p); node->d_next = d_nodeList; d_nodeList = node; return true; }
// CREATORS HashCrossReference(const TYPE *valuesArray, size_t numValues, bslma::Allocator *allocator = 0) // Create a hash cross reference referring to the array of value. : d_values(valuesArray) , d_numValues(numValues) , d_hasher() , d_valid(true) , d_allocator_p(bslma::Default::allocator(allocator)) { size_t bucketArrayLength = 4; while (bucketArrayLength < numValues * 4) { bucketArrayLength *= 2; BSLS_ASSERT_OPT(bucketArrayLength); } d_bucketArrayMask = bucketArrayLength - 1; d_bucketArray = (const TYPE **) d_allocator_p->allocate( bucketArrayLength * sizeof(TYPE **)); memset(d_bucketArray, 0, bucketArrayLength * sizeof(TYPE *)); for (unsigned i = 0; i < numValues; ++i) { const TYPE& value = d_values[i]; size_t idx; if (lookup(&idx, value, d_hasher(value))) { // Duplicate value. Fail. printf("Error: entries %u and %u have the same value\n", i, (unsigned) (d_bucketArray[idx] - d_values)); d_valid = false; // don't return, continue reporting other redundant entries. } else { d_bucketArray[idx] = &d_values[i]; } } }
// MANIPULATORS void *my_Allocator::allocate(size_type size) { return d_allocator_p->allocate(size); }
my_Type(int size, bslma::Allocator *basicAllocator) : d_allocator_p(basicAllocator) { d_stuff_p = (char *) d_allocator_p->allocate(size); }