Ejemplo n.º 1
0
//..
// 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;
}
 // 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;
 }
Ejemplo n.º 3
0
    // 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);
    }
Ejemplo n.º 4
0
 // 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);
 }
Ejemplo n.º 5
0
    inline
    MyClass::~MyClass()
    {
        BSLS_ASSERT_SAFE(0 <= d_capacity);

        d_allocator_p->deallocate(d_description_p);
    }
 ~TestType()
 {
     ++numDestructorCalls;
     *d_data_p = '_';
     d_allocator_p->deallocate(d_data_p);
     d_data_p = 0;
 }
 // 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;
 }
 // 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(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;
 }
 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;
 }
 }
Ejemplo n.º 11
0
    ~ListSet()
        // Release all memory used by this 'ListSet'
    {
        for (Node *node = d_nodeList; node; ) {
            Node *toDelete = node;
            node = node->d_next;

            d_allocator_p->deleteObject(toDelete);
        }
    }
Ejemplo n.º 12
0
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;
    }
}
Ejemplo n.º 13
0
    // 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;
    }
Ejemplo n.º 14
0
    // 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];
            }
        }
    }
Ejemplo n.º 15
0
 ~UsageType()
 {
     *d_data_p = '_';
     d_allocator_p->deallocate(d_data_p);
     d_data_p = 0;
 }
Ejemplo n.º 16
0
void MySharedDatetimeRepImpl::disposeRep() {
    d_allocator_p->deallocate(this);
}
Ejemplo n.º 17
0
 my_Type(int size, bslma::Allocator *basicAllocator)
 : d_allocator_p(basicAllocator)
 {
     d_stuff_p = (char *) d_allocator_p->allocate(size);
 }
void my_Allocator::deallocate(void *address)
{
    d_allocator_p->deallocate(address);
}
// MANIPULATORS
void *my_Allocator::allocate(size_type size)
{
    return d_allocator_p->allocate(size);
}
Ejemplo n.º 20
0
 ~my_Type()
 {
     d_allocator_p->deallocate(d_stuff_p);
 }
Ejemplo n.º 21
0
 inline
 my_Id::~my_Id()
 {
     d_allocator_p->deallocate(d_buffer_p);
 }
Ejemplo n.º 22
0
 ~HashCrossReference()
     // Free up memory used by this cross-reference.
 {
     d_allocator_p->deallocate(d_bucketArray);
 }