Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/vector.c

    rbd34fc87 r60aa49a7  
    1818#include <stdlib>
    1919
    20 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    21 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other);
    22 
    2320//------------------------------------------------------------------------------
    2421//Initialization
    2522forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    26 void ?{}(vector(T, allocator_t)* this)
     23void ctor(vector(T, allocator_t) *const this)
    2724{
    28         (&this->storage){};
     25        ctor(&this->storage);
    2926        this->size = 0;
    3027}
    3128
    3229forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    33 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
    34 {
    35         (&this->storage){ rhs.storage };
    36         copy_internal(this, &rhs);
    37 }
    38 
    39 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    40 // vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
    41 // {
    42 //      (&this->storage){};
    43 //      copy_internal(this, &rhs);
    44 //      return *this;
    45 // }
    46 
    47 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    48 void ^?{}(vector(T, allocator_t)* this)
     30void dtor(vector(T, allocator_t) *const this)
    4931{
    5032        clear(this);
    51         ^(&this->storage){};
     33        dtor(&this->storage);
    5234}
    5335
     
    5537//Modifiers
    5638forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    57 void push_back(vector(T, allocator_t)* this, T value)
     39void push_back(vector(T, allocator_t) *const this, T value)
    5840{
    5941        realloc_storage(&this->storage, this->size+1);
     
    6345
    6446forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    65 void pop_back(vector(T, allocator_t)* this)
     47void pop_back(vector(T, allocator_t) *const this)
    6648{
    6749        this->size--;
    68         ^(&data(&this->storage)[this->size]){};
     50        DESTROY(data(&this->storage)[this->size]);
    6951}
    7052
    7153forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    72 void clear(vector(T, allocator_t)* this)
     54void clear(vector(T, allocator_t) *const this)
    7355{
    7456        for(size_t i = 0; i < this->size; i++)
    7557        {
    76                 ^(&data(&this->storage)[this->size]){};
     58                DESTROY(data(&this->storage)[this->size]);
    7759        }
    7860        this->size = 0;
     
    8062
    8163//------------------------------------------------------------------------------
    82 //Internal Helpers
    83 
    84 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    85 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other)
    86 {
    87         this->size = other->size;
    88         for(size_t i = 0; i < this->size; i++) {
    89                 (&data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
    90         }
    91 }
    92 
    93 //------------------------------------------------------------------------------
    9464//Allocator
    9565forall(otype T)
    96 void ?{}(heap_allocator(T)* this)
     66void ctor(heap_allocator(T) *const this)
    9767{
    9868        this->storage = 0;
     
    10171
    10272forall(otype T)
    103 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs)
    104 {
    105         this->capacity = rhs.capacity;
    106         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
    107 }
    108 
    109 forall(otype T)
    110 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs)
    111 {
    112         this->capacity = rhs.capacity;
    113         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
    114         return *this;
    115 }
    116 
    117 forall(otype T)
    118 void ^?{}(heap_allocator(T)* this)
     73void dtor(heap_allocator(T) *const this)
    11974{
    12075        free(this->storage);
     
    12277
    12378forall(otype T)
    124 inline void realloc_storage(heap_allocator(T)* this, size_t size)
     79inline void realloc_storage(heap_allocator(T) *const this, size_t size)
    12580{
    12681        enum { GROWTH_RATE = 2 };
Note: See TracChangeset for help on using the changeset viewer.