Last change
on this file since 888 was
888,
checked in by Maciej Komosinski, 5 years ago
|
More explicit code to fix compiler warnings
|
File size:
1.3 KB
|
Rev | Line | |
---|
[840] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/
|
---|
| 2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski.
|
---|
| 3 | // See LICENSE.txt for details.
|
---|
| 4 |
|
---|
| 5 | #ifndef _UTIL_STL_H_
|
---|
| 6 | #define _UTIL_STL_H_
|
---|
| 7 |
|
---|
| 8 | #include "nonstd_stl.h"
|
---|
| 9 |
|
---|
| 10 | template<typename T, std::size_t N> void push_back(vector<T>& v, T(&d)[N])
|
---|
| 11 | {
|
---|
| 12 | for (unsigned int i = 0; i < N; i++)
|
---|
| 13 | v.push_back(d[i]);
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | template<typename T> void erase(vector<T>& v, const T& e)
|
---|
| 17 | {
|
---|
| 18 | typename vector<T>::iterator it = std::find(v.begin(), v.end(), e);
|
---|
| 19 | if (it != v.end())
|
---|
| 20 | v.erase(it);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | template<typename T> void deleteVectorElements(vector<T*>& v)
|
---|
| 24 | {
|
---|
| 25 | for (typename vector<T*>::iterator it = v.begin(); it != v.end(); it++)
|
---|
| 26 | delete *it;
|
---|
| 27 | v.clear();
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | template<typename T> int findIndex(vector<T>& v, const T& e)
|
---|
| 31 | {
|
---|
| 32 | typename vector<T>::iterator it = find(v.begin(), v.end(), e);
|
---|
| 33 | if (it != v.end())
|
---|
[888] | 34 | return int(&*it - &v.front());
|
---|
[840] | 35 | return -1;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | template<class T> class DeletingVector // deletes the elements (pointers) in destructor
|
---|
| 39 | {
|
---|
| 40 | public:
|
---|
| 41 | std::vector<T*> vector;
|
---|
| 42 | ~DeletingVector()
|
---|
| 43 | {
|
---|
[888] | 44 | for (int i = (int)vector.size() - 1; i >= 0; i--)
|
---|
[840] | 45 | delete vector[i];
|
---|
| 46 | }
|
---|
| 47 | T* operator[](int i) { return vector[i]; }
|
---|
| 48 | int size() { return vector.size(); }
|
---|
| 49 | void push_back(T* x) { vector.push_back(x); }
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | #endif
|
---|
Note: See
TracBrowser
for help on using the repository browser.