source: src/libcfa/containers/vector @ 0583064b

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 0583064b 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
Line 
1//
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.
6//
7// vector --
8//
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
14//
15
16#ifndef VECTOR_H
17#define VECTOR_H
18
19extern "C" {
20#include <stdbool.h>
21}
22
23//------------------------------------------------------------------------------
24//Declaration
25trait allocator_c(otype T, otype allocator_t)
26{
27        void realloc_storage(allocator_t*, size_t);
28        T* data(allocator_t*);
29};
30
31forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
32struct vector;
33
34//------------------------------------------------------------------------------
35//Initialization
36forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
37void ?{}(vector(T, allocator_t)* this);
38
39forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
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};
54
55//------------------------------------------------------------------------------
56//Capacity
57forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
58static inline bool empty(vector(T, allocator_t)* this)
59{
60        return this->size == 0;
61}
62
63forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
64static inline size_t size(vector(T, allocator_t)* this)
65{
66        return this->size;
67}
68
69forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
70static inline void reserve(vector(T, allocator_t)* this, size_t size)
71{
72        realloc_storage(&this->storage, this->size+1);
73}
74
75//------------------------------------------------------------------------------
76//Element access
77forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
78static inline T at(vector(T, allocator_t)* this, size_t index)
79{
80        return data(&this->storage)[index];
81}
82
83forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
84static inline T ?[?](vector(T, allocator_t)* this, size_t index)
85{
86        return data(&this->storage)[index];
87}
88
89forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
90static inline T front(vector(T, allocator_t)* this)
91{
92        return data(&this->storage)[0];
93}
94
95forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
96static inline T back(vector(T, allocator_t)* this)
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))
104void push_back(vector(T, allocator_t)* this, T value);
105
106forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
107void pop_back(vector(T, allocator_t)* this);
108
109forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
110void clear(vector(T, allocator_t)* this);
111
112//------------------------------------------------------------------------------
113//Iterators
114forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
115static inline T* begin(vector(T, allocator_t)* this)
116{
117        return data(&this->storage);
118}
119
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// }
125
126forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
127static inline T* end(vector(T, allocator_t)* this)
128{
129        return data(&this->storage) + this->size;
130}
131
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// }
137
138//------------------------------------------------------------------------------
139//Allocator
140forall(otype T)
141struct heap_allocator
142{
143        T* storage;
144        size_t capacity;
145};
146
147forall(otype T)
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);
155
156forall(otype T)
157void ^?{}(heap_allocator(T)* this);
158
159forall(otype T)
160void realloc_storage(heap_allocator(T)* this, size_t size);
161
162forall(otype T)
163static inline T* data(heap_allocator(T)* this)
164{
165        return this->storage;
166}
167
168#endif // VECTOR_H
169
170// Local Variables: //
171// mode: c //
172// tab-width: 4 //
173// End: //
Note: See TracBrowser for help on using the repository browser.