author | rubidium |
Wed, 16 Apr 2008 20:01:04 +0000 | |
changeset 8951 | 618a0b1a5061 |
parent 8949 | 4c9fbf5ec359 |
child 8952 | be6bfd75e554 |
permissions | -rw-r--r-- |
8949
4c9fbf5ec359
(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$ */ |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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 */ |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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 |
4c9fbf5ec359
(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 |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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 { |
4c9fbf5ec359
(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; |
4c9fbf5ec359
(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; |
4c9fbf5ec359
(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; |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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) { } |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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() |
4c9fbf5ec359
(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 |
{ |
4c9fbf5ec359
(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); |
4c9fbf5ec359
(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 |
} |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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 |
/** |
4c9fbf5ec359
(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. |
4c9fbf5ec359
(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 |
*/ |
4c9fbf5ec359
(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() |
4c9fbf5ec359
(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 |
{ |
4c9fbf5ec359
(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) { |
4c9fbf5ec359
(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; |
4c9fbf5ec359
(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); |
4c9fbf5ec359
(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 |
} |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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++]; |
4c9fbf5ec359
(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 |
} |
4c9fbf5ec359
(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 |
|
4c9fbf5ec359
(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 |
4c9fbf5ec359
(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 |
{ |
4c9fbf5ec359
(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; |
4c9fbf5ec359
(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 |
} |
4c9fbf5ec359
(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 |
|
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
38 |
T *Begin() |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
39 |
{ |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
40 |
return data; |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
41 |
} |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
42 |
|
8949
4c9fbf5ec359
(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 |
4c9fbf5ec359
(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 |
{ |
4c9fbf5ec359
(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]; |
4c9fbf5ec359
(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 |
} |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
47 |
|
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
48 |
T *End() |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
49 |
{ |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
50 |
return &data[items]; |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8949
diff
changeset
|
51 |
} |
8949
4c9fbf5ec359
(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
|
52 |
}; |
4c9fbf5ec359
(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
|
53 |
|
4c9fbf5ec359
(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
|
54 |
#endif /* SMALLVEC_H */ |