Fraxinus  18.10
An IGT application
cxViewCache.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXVIEWCACHE_H_
13 #define CXVIEWCACHE_H_
14 
15 #include "cxResourceVisualizationExport.h"
16 
17 #include <QWidget>
18 #include <QLayout>
19 #include <vector>
20 #include "cxTypeConversions.h"
21 #include "cxOSXHelper.h"
22 #include "cxViewWidget.h"
23 #include "cxRenderWindowFactory.h"
24 
25 namespace cx
26 {
45 template<class VIEW_TYPE>
46 class cxResourceVisualization_EXPORT ViewCache
47 {
48 public:
49  ViewCache(RenderWindowFactoryPtr factory, QWidget* widget, QString typeText) :
50  mRenderWindowFactory(factory),
51  mCentralWidget(widget),
52  mNameGenerator(0),
53  mTypeText(typeText)
54  {
55  }
58  VIEW_TYPE* retrieveView()
59  {
60  if (mCached.empty())
61  {
62  QString uid = QString("%1-%2-%3")
63  .arg(mTypeText)
64  .arg(mNameGenerator++)
65  .arg(reinterpret_cast<long>(this));
66  VIEW_TYPE* view = new VIEW_TYPE(mRenderWindowFactory, uid, uid, mCentralWidget);
67  mCached.push_back(view);
68  }
69 
70  VIEW_TYPE* retval = mCached.back();
71  mCached.pop_back();
72  mUsed.push_back(retval);
73  return retval;
74  }
79  {
80  std::copy(mUsed.begin(), mUsed.end(), back_inserter(mCached));
81  mUsed.clear();
82  }
86  void clearCache()
87  {
88  mCached.clear();
89  mUsed.clear();
90  }
91 
92 private:
93  QWidget* mCentralWidget;
94  int mNameGenerator;
95  QString mTypeText;
96  std::vector<VIEW_TYPE*> mCached;
97  std::vector<VIEW_TYPE*> mUsed;
98  RenderWindowFactoryPtr mRenderWindowFactory;
99 };
100 
101 
105 } // namespace cx
106 
107 #endif /* CXVIEWCACHE_H_ */
VIEW_TYPE * retrieveView()
Definition: cxViewCache.h:58
void clearUsedViews()
Definition: cxViewCache.h:78
ViewCache(RenderWindowFactoryPtr factory, QWidget *widget, QString typeText)
Definition: cxViewCache.h:49
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
void clearCache()
Definition: cxViewCache.h:86
Namespace for all CustusX production code.