source: src/libcfa/containers/vector @ 8191203

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 8191203 was 6dc78dee, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Removed unsing cbegin/cend routines which caused constness warnings

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[60aa49a7]1//
[a6151ba]2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
[60aa49a7]6//
7// vector --
8//
[a6151ba]9// Author           : Thierry Delisle
10// Created On       : Tue Jul  5 18:00:07 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Jul  5 18:01:35 2016
13// Update Count     : 2
[60aa49a7]14//
[a6151ba]15
[17e5e2b]16#ifndef VECTOR_H
17#define VECTOR_H
[df4aea7]18
[00b7cd3]19extern "C" {
[f1e42c1]20#include <stdbool.h>
[00b7cd3]21}
[c44e622]22
[eb38dd5]23//------------------------------------------------------------------------------
24//Declaration
[df4aea7]25trait allocator_c(otype T, otype allocator_t)
26{
[bd34fc87]27        void realloc_storage(allocator_t*, size_t);
28        T* data(allocator_t*);
[c44e622]29};
30
[385c130]31forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]32struct vector;
[4ef8fb3]33
34//------------------------------------------------------------------------------
35//Initialization
36forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]37void ?{}(vector(T, allocator_t)* this);
[4ef8fb3]38
39forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]40void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
41
42forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
43vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
44
45forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
46void ^?{}(vector(T, allocator_t)* this);
47
48forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
49struct vector
50{
51        allocator_t storage;
52        size_t size;
53};
[4ef8fb3]54
55//------------------------------------------------------------------------------
56//Capacity
57forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]58static inline bool empty(vector(T, allocator_t)* this)
[4ef8fb3]59{
60        return this->size == 0;
61}
62
63forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]64static inline size_t size(vector(T, allocator_t)* this)
[4ef8fb3]65{
66        return this->size;
67}
68
69forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]70static inline void reserve(vector(T, allocator_t)* this, size_t size)
[4ef8fb3]71{
[60aa49a7]72        realloc_storage(&this->storage, this->size+1);
[4ef8fb3]73}
74
75//------------------------------------------------------------------------------
76//Element access
77forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]78static inline T at(vector(T, allocator_t)* this, size_t index)
[4ef8fb3]79{
80        return data(&this->storage)[index];
81}
82
83forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]84static inline T ?[?](vector(T, allocator_t)* this, size_t index)
[4ef8fb3]85{
86        return data(&this->storage)[index];
87}
88
89forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]90static inline T front(vector(T, allocator_t)* this)
[4ef8fb3]91{
92        return data(&this->storage)[0];
93}
94
95forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]96static inline T back(vector(T, allocator_t)* this)
[4ef8fb3]97{
98        return data(&this->storage)[this->size - 1];
99}
100
101//------------------------------------------------------------------------------
102//Modifiers
103forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]104void push_back(vector(T, allocator_t)* this, T value);
[4ef8fb3]105
106forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]107void pop_back(vector(T, allocator_t)* this);
[4ef8fb3]108
109forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]110void clear(vector(T, allocator_t)* this);
[4ef8fb3]111
112//------------------------------------------------------------------------------
113//Iterators
114forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]115static inline T* begin(vector(T, allocator_t)* this)
[4ef8fb3]116{
117        return data(&this->storage);
118}
119
[6dc78dee]120// forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
121// static inline const T* cbegin(const vector(T, allocator_t)* this)
122// {
123//      return data(&this->storage);
124// }
[4ef8fb3]125
126forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
[bd34fc87]127static inline T* end(vector(T, allocator_t)* this)
[4ef8fb3]128{
129        return data(&this->storage) + this->size;
130}
131
[6dc78dee]132// forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
133// static inline const T* cend(const vector(T, allocator_t)* this)
134// {
135//      return data(&this->storage) + this->size;
136// }
[4ef8fb3]137
138//------------------------------------------------------------------------------
139//Allocator
140forall(otype T)
141struct heap_allocator
142{
143        T* storage;
144        size_t capacity;
145};
146
147forall(otype T)
[bd34fc87]148void ?{}(heap_allocator(T)* this);
149
150forall(otype T)
151void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);
152
153forall(otype T)
154heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);
[4ef8fb3]155
156forall(otype T)
[bd34fc87]157void ^?{}(heap_allocator(T)* this);
[4ef8fb3]158
159forall(otype T)
[bd34fc87]160void realloc_storage(heap_allocator(T)* this, size_t size);
[4ef8fb3]161
162forall(otype T)
[bd34fc87]163static inline T* data(heap_allocator(T)* this)
[4ef8fb3]164{
165        return this->storage;
166}
[a6151ba]167
[17e5e2b]168#endif // VECTOR_H
169
[a6151ba]170// Local Variables: //
171// mode: c //
172// tab-width: 4 //
173// End: //
Note: See TracBrowser for help on using the repository browser.