diff options
| author | 2014-04-08 19:25:03 -0400 | |
|---|---|---|
| committer | 2014-04-08 19:25:03 -0400 | |
| commit | 63e46abdb8764bc97e91bae862c8d461e61b1965 (patch) | |
| tree | e73f4aa25d7b4015a265e7bbfb6004dab7561027 /src/common/fixed_size_queue.h | |
| parent | fixed some license headers that I missed (diff) | |
| download | yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.tar.gz yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.tar.xz yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.zip | |
got rid of 'src' folders in each sub-project
Diffstat (limited to 'src/common/fixed_size_queue.h')
| -rw-r--r-- | src/common/fixed_size_queue.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/common/fixed_size_queue.h b/src/common/fixed_size_queue.h new file mode 100644 index 000000000..1f507f4ae --- /dev/null +++ b/src/common/fixed_size_queue.h | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | |||
| 6 | #ifndef _FIXED_SIZE_QUEUE_H_ | ||
| 7 | #define _FIXED_SIZE_QUEUE_H_ | ||
| 8 | |||
| 9 | // STL-look-a-like interface, but name is mixed case to distinguish it clearly from the | ||
| 10 | // real STL classes. | ||
| 11 | |||
| 12 | // Not fully featured, no safety checking yet. Add features as needed. | ||
| 13 | |||
| 14 | // TODO: "inline" storage? | ||
| 15 | |||
| 16 | template <class T, int N> | ||
| 17 | class fixed_size_queue.h | ||
| 18 | { | ||
| 19 | T *storage; | ||
| 20 | int head; | ||
| 21 | int tail; | ||
| 22 | int count; // sacrifice 4 bytes for a simpler implementation. may optimize away in the future. | ||
| 23 | |||
| 24 | // Make copy constructor private for now. | ||
| 25 | fixed_size_queue.h(fixed_size_queue.h &other) { } | ||
| 26 | |||
| 27 | public: | ||
| 28 | fixed_size_queue.h() | ||
| 29 | { | ||
| 30 | storage = new T[N]; | ||
| 31 | clear(); | ||
| 32 | } | ||
| 33 | |||
| 34 | ~fixed_size_queue.h() | ||
| 35 | { | ||
| 36 | delete [] storage; | ||
| 37 | } | ||
| 38 | |||
| 39 | void clear() { | ||
| 40 | head = 0; | ||
| 41 | tail = 0; | ||
| 42 | count = 0; | ||
| 43 | } | ||
| 44 | |||
| 45 | void push(T t) { | ||
| 46 | storage[tail] = t; | ||
| 47 | tail++; | ||
| 48 | if (tail == N) | ||
| 49 | tail = 0; | ||
| 50 | count++; | ||
| 51 | } | ||
| 52 | |||
| 53 | void pop() { | ||
| 54 | head++; | ||
| 55 | if (head == N) | ||
| 56 | head = 0; | ||
| 57 | count--; | ||
| 58 | } | ||
| 59 | |||
| 60 | T pop_front() { | ||
| 61 | const T &temp = storage[head]; | ||
| 62 | pop(); | ||
| 63 | return temp; | ||
| 64 | } | ||
| 65 | |||
| 66 | T &front() { return storage[head]; } | ||
| 67 | const T &front() const { return storage[head]; } | ||
| 68 | |||
| 69 | size_t size() const { | ||
| 70 | return count; | ||
| 71 | } | ||
| 72 | }; | ||
| 73 | |||
| 74 | #endif // _FIXED_SIZE_QUEUE_H_ | ||
| 75 | |||