VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtkSMPThreadLocalObject.h
Go to the documentation of this file.
1  /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSMPThreadLocalObject.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
76 #ifndef __vtkSMPThreadLocalObject_h
77 #define __vtkSMPThreadLocalObject_h
78 
79 #include <vtkSMPThreadLocal.h>
80 
81 template <typename T>
83 {
84  typedef vtkSMPThreadLocal<T*> TLS;
85  typedef typename vtkSMPThreadLocal<T*>::iterator TLSIter;
86 
87  // Hide the copy constructor for now and assignment
88  // operator for now.
90  void operator=(const vtkSMPThreadLocalObject&);
91 
92 public:
94 
95  vtkSMPThreadLocalObject() : Internal(0)
96  {
97  }
99 
101  {
102  iterator iter = this->begin();
103  while (iter != this->end())
104  {
105  if (*iter)
106  {
107  (*iter)->Delete();
108  }
109  ++iter;
110  }
111  }
112 
114 
117  T*& Local()
118  {
119  T*& vtkobject = this->Internal.Local();
120  if (!vtkobject)
121  {
122  vtkobject = T::New();
123  }
124  return vtkobject;
125  }
127 
129 
132  class iterator
133  {
134  public:
136  {
137  ++this->Iter;
138  return *this;
139  }
141 
142  bool operator!=(const iterator& other)
143  {
144  return this->Iter != other.Iter;
145  }
146 
147  T*& operator*()
148  {
149  return *this->Iter;
150  }
151 
152  private:
153  TLSIter Iter;
154 
155  friend class vtkSMPThreadLocalObject<T>;
156  };
157 
158  iterator begin()
159  {
160  iterator iter;
161  iter.Iter = this->Internal.begin();
162  return iter;
163  };
164 
165  iterator end()
166  {
167  iterator iter;
168  iter.Iter = this->Internal.end();
169  return iter;
170  }
171 
172 private:
173  TLS Internal;
174 };
175 
176 #endif
177 // VTK-HeaderTest-Exclude: vtkSMPThreadLocalObject.h
bool operator!=(const iterator &other)
Thread local storage for VTK objects.