author | rubidium |
Wed, 16 Apr 2008 20:39:35 +0000 | |
changeset 10208 | 98dc9f65629e |
parent 10207 | 0bdc24d88198 |
child 10429 | 1b99254f9607 |
permissions | -rw-r--r-- |
10205
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
2 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
3 |
/* @file smallvec.h */ |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
4 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
5 |
#ifndef SMALLVEC_H |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
6 |
#define SMALLVEC_H |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
7 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
8 |
template <typename T, uint S> struct SmallVector { |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
9 |
T *data; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
10 |
uint items; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
11 |
uint capacity; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
12 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
13 |
SmallVector() : data(NULL), items(0), capacity(0) { } |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
14 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
15 |
~SmallVector() |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
16 |
{ |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
17 |
free(data); |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
18 |
} |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
19 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
20 |
/** |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
21 |
* Append an item and return it. |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
22 |
*/ |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
23 |
T *Append() |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
24 |
{ |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
25 |
if (items == capacity) { |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
26 |
capacity += S; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
27 |
data = ReallocT(data, capacity); |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
28 |
} |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
29 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
30 |
return &data[items++]; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
31 |
} |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
32 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
33 |
const T *Begin() const |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
34 |
{ |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
35 |
return data; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
36 |
} |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
37 |
|
10207
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
38 |
T *Begin() |
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
39 |
{ |
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
40 |
return data; |
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
41 |
} |
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
42 |
|
10205
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
43 |
const T *End() const |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
44 |
{ |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
45 |
return &data[items]; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
46 |
} |
10207
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
47 |
|
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
48 |
T *End() |
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
49 |
{ |
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
50 |
return &data[items]; |
0bdc24d88198
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
10205
diff
changeset
|
51 |
} |
10208
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
52 |
|
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
53 |
const T *Get(size_t index) const |
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
54 |
{ |
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
55 |
return &data[index]; |
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
56 |
} |
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
57 |
|
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
58 |
T *Get(size_t index) |
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
59 |
{ |
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
60 |
return &data[index]; |
98dc9f65629e
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
10207
diff
changeset
|
61 |
} |
10205
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
62 |
}; |
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
63 |
|
d37e906c7070
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
diff
changeset
|
64 |
#endif /* SMALLVEC_H */ |