OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreVectorSetImpl.h
Go to the documentation of this file.
1 /*
2  * -----------------------------------------------------------------------------
3  * This source file is part of OGRE
4  * (Object-oriented Graphics Rendering Engine)
5  * For the latest info, see http://www.ogre3d.org/
6  *
7  * Copyright (c) 2000-2014 Torus Knot Software Ltd
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  * -----------------------------------------------------------------------------
27  */
28 
29 #ifndef _VectorSetImpl_H__
30 #define _VectorSetImpl_H__
31 
32 #include "OgreVectorSet.h"
33 
34 #include "OgreException.h" // for OgreAssert
35 
36 namespace Ogre
37 {
38 
39  template<typename T, unsigned S>
40  void VectorSet<T, S>::addNotExists(const T& item)
41  {
42  OgreAssert(find(item) == this->end(), "");
43  this->push_back(item);
44  }
45 
46  template<typename T, unsigned S>
48  {
49  // Thats my trick to remove an item from the vector very fast!
50  // It works similar to the heap_pop().
51  // It swaps the removable item to the back, then pops it.
52  *it = this->back();
53  this->pop_back();
54  }
55 
56  template<typename T, unsigned S>
58  {
59  iterator it = find(item);
60  if (it == this->end()) {
61  this->push_back(item);
62  return this->end();
63  }
64  return it;
65  }
66 
67  template<typename T, unsigned S>
68  void VectorSet<T, S>::removeExists(const T& item)
69  {
70  iterator it = find(item);
71  OgreAssert(it != this->end(), "");
72  remove(it);
73  }
74 
75  template<typename T, unsigned S>
76  bool VectorSet<T, S>::remove(const T& item)
77  {
78  iterator it = find(item);
79  if (it != this->end()) {
80  remove(it);
81  return true;
82  } else {
83  return false;
84  }
85  }
86 
87  template<typename T, unsigned S>
88  void VectorSet<T, S>::replaceExists(const T& oldItem, const T& newItem)
89  {
90  iterator it = find(oldItem);
91  OgreAssert(it != this->end(), "");
92  *it = newItem;
93  }
94 
95  template<typename T, unsigned S>
96  bool VectorSet<T, S>::has(const T& item)
97  {
98  return find(item) != this->end();
99  }
100 
101  template<typename T, unsigned S>
103  {
104  return std::find(this->begin(), this->end(), item);
105  }
106 
107  template<typename T, unsigned S>
109  const T& item)
110  {
111  iterator it = find(item);
112  OgreAssert(it != this->end(), "");
113  return it;
114  }
115 
116 }
117 #endif
iterator find(const T &item)
void removeExists(const T &item)
void addNotExists(const T &item)
#define OgreAssert(a, b)
Definition: OgreException.h:60
void replaceExists(const T &oldItem, const T &newItem)
bool has(const T &item)
iterator findExists(const T &item)
iterator add(const T &item)
void remove(iterator it)
SmallVector< T, S >::iterator iterator
Definition: OgreVectorSet.h:46