PLearn 0.1
Public Types | Public Member Functions | Private Attributes
PLearn::ArrayAllocatorTrivial< T, SizeBits > Class Template Reference

This allocator solely performs allocation. More...

#include <ArrayAllocatorTrivial.h>

Collaboration diagram for PLearn::ArrayAllocatorTrivial< T, SizeBits >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef ArrayAllocatorTrivial
< T, SizeBits > 
self
typedef T value_type
typedef size_t size_type
typedef ptrdiff_t difference_type
typedef T * pointer
typedef const T * const_pointer
typedef T & reference
typedef const T & const_reference
typedef unsigned index_base
typedef ArrayAllocatorIndex
< index_base, SizeBits > 
index_type

Public Member Functions

 ArrayAllocatorTrivial (unsigned numberObjects)
pointer allocate (size_t n)
 Default copy ctor, dtor, op=.
void deallocate (pointer p, size_type n)
 "Deallocate" pointer (no-op)
void deallocate (index_type)
void resize (size_type newMaxObjs)
 Change the maximum number of objects.
size_type max_size () const
void swap (self &)
 Interchange two allocators.
index_type toIndex (pointer p, size_type n)
 Index/pointer conversion.
pointer toPointer (index_type)

Private Attributes

vector< T > arr
index_base free_point

Detailed Description

template<class T, unsigned SizeBits>
class PLearn::ArrayAllocatorTrivial< T, SizeBits >

This allocator solely performs allocation.

Definition at line 60 of file ArrayAllocatorTrivial.h.


Member Typedef Documentation

template<class T, unsigned SizeBits>
typedef const T* PLearn::ArrayAllocatorTrivial< T, SizeBits >::const_pointer

Definition at line 69 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef const T& PLearn::ArrayAllocatorTrivial< T, SizeBits >::const_reference

Definition at line 71 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef ptrdiff_t PLearn::ArrayAllocatorTrivial< T, SizeBits >::difference_type

Definition at line 66 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef unsigned PLearn::ArrayAllocatorTrivial< T, SizeBits >::index_base

Definition at line 73 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef ArrayAllocatorIndex<index_base, SizeBits> PLearn::ArrayAllocatorTrivial< T, SizeBits >::index_type

Definition at line 74 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef T* PLearn::ArrayAllocatorTrivial< T, SizeBits >::pointer

Definition at line 68 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef T& PLearn::ArrayAllocatorTrivial< T, SizeBits >::reference

Definition at line 70 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef ArrayAllocatorTrivial<T,SizeBits> PLearn::ArrayAllocatorTrivial< T, SizeBits >::self

Definition at line 63 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef size_t PLearn::ArrayAllocatorTrivial< T, SizeBits >::size_type

Definition at line 65 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
typedef T PLearn::ArrayAllocatorTrivial< T, SizeBits >::value_type

Definition at line 64 of file ArrayAllocatorTrivial.h.


Constructor & Destructor Documentation

template<class T , unsigned SizeBits>
PLearn::ArrayAllocatorTrivial< T, SizeBits >::ArrayAllocatorTrivial ( unsigned  numberObjects)

Definition at line 111 of file ArrayAllocatorTrivial.h.

    : arr(numberObjects), free_point(1)
{}

Member Function Documentation

template<class T , unsigned SizeBits>
T * PLearn::ArrayAllocatorTrivial< T, SizeBits >::allocate ( size_t  n)

Default copy ctor, dtor, op=.

Allocate N objects of type T and return a (memory) pointer to it

Definition at line 125 of file ArrayAllocatorTrivial.h.

References n, and PLERROR.

{
    if(free_point + n > arr.size()) {
        PLERROR("Size of memory pool exceeded (%d objects)", arr.size());
        return 0;
    }
    T* p = &arr[free_point];
    free_point += n;
    return p;
}
template<class T, unsigned SizeBits>
void PLearn::ArrayAllocatorTrivial< T, SizeBits >::deallocate ( pointer  p,
size_type  n 
) [inline]

"Deallocate" pointer (no-op)

Definition at line 84 of file ArrayAllocatorTrivial.h.

{}
template<class T, unsigned SizeBits>
void PLearn::ArrayAllocatorTrivial< T, SizeBits >::deallocate ( index_type  ) [inline]

Definition at line 85 of file ArrayAllocatorTrivial.h.

{}
template<class T, unsigned SizeBits>
size_type PLearn::ArrayAllocatorTrivial< T, SizeBits >::max_size ( ) const [inline]

Definition at line 89 of file ArrayAllocatorTrivial.h.

                               {
        return arr.size();
    }
template<class T , unsigned SizeBits>
void PLearn::ArrayAllocatorTrivial< T, SizeBits >::resize ( size_type  newMaxObjs)

Change the maximum number of objects.

Definition at line 117 of file ArrayAllocatorTrivial.h.

References PLearn::max(), and PLearn::min().

{
    arr.resize(newMaxObjs);
    free_point = max(1, min(free_point, arr.size()));
}

Here is the call graph for this function:

template<class T , unsigned SizeBits>
void PLearn::ArrayAllocatorTrivial< T, SizeBits >::swap ( self other)

Interchange two allocators.

Definition at line 138 of file ArrayAllocatorTrivial.h.

References PLearn::swap().

{
    arr.swap(other);
    swap(free_point, other.free_point);
}

Here is the call graph for this function:

template<class T , unsigned SizeBits>
ArrayAllocatorTrivial< T, SizeBits >::index_type PLearn::ArrayAllocatorTrivial< T, SizeBits >::toIndex ( pointer  p,
size_type  n 
) [inline]

Index/pointer conversion.

Definition at line 148 of file ArrayAllocatorTrivial.h.

{
    if (p)
        return index_type(p-&arr[0], n);
    else
        return index_type(0,0);
}
template<class T , unsigned SizeBits>
ArrayAllocatorTrivial< T, SizeBits >::pointer PLearn::ArrayAllocatorTrivial< T, SizeBits >::toPointer ( index_type  i) [inline]

Definition at line 160 of file ArrayAllocatorTrivial.h.

References PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::index, and PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::isNull().

{
    if (i.isNull())
        return 0;
    else
        return &arr[0] + i.index;
}

Here is the call graph for this function:


Member Data Documentation

template<class T, unsigned SizeBits>
vector<T> PLearn::ArrayAllocatorTrivial< T, SizeBits >::arr [private]

Definition at line 102 of file ArrayAllocatorTrivial.h.

template<class T, unsigned SizeBits>
index_base PLearn::ArrayAllocatorTrivial< T, SizeBits >::free_point [private]

Definition at line 103 of file ArrayAllocatorTrivial.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines