CustusX  2021.04.21-dev+develop.337f9
An IGT application
cxRepManager.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 CXREPMANAGER_H_
13 #define CXREPMANAGER_H_
14 
15 #include "org_custusx_core_view_Export.h"
16 
17 #include <QObject>
18 #include <map>
19 #include <vector>
20 #include "cxForwardDeclarations.h"
21 
22 namespace cx
23 {
24 typedef boost::shared_ptr<class Rep> RepPtr;
25 }
26 
27 namespace cx
28 {
29 
30 typedef std::map<QString, RepPtr> RepMap;
31 typedef std::map<QString, VolumetricBaseRepPtr> VolumetricRepMap;
32 
33 class Reporter;
34 
51 class org_custusx_core_view_EXPORT RepManager: public QObject
52 {
53 Q_OBJECT
54 
55 public:
56  static RepManager* getInstance();
57  static void destroyInstance();
58 
71  template<class REP>
72  boost::shared_ptr<REP> getCachedRep(QString uid = "")
73  {
74  // look for existing value:
75  for (RepMultiMap::iterator iter = mRepCache.begin(); iter != mRepCache.end(); ++iter)
76  {
77  if (iter->first != uid)
78  continue;
79  int uc = iter->second.use_count();
80  if (uc >1)
81  {
82 // std::cout << "cached rep in use: " << uid.toStdString() << ", use count: " << uc << std::endl;
83  continue;
84  }
85 
86  boost::shared_ptr<REP> retval = boost::dynamic_pointer_cast<REP>(iter->second);
87  if (retval)
88  {
89 // std::cout << "reusing cached rep: " << uid.toStdString() << ", use count: " << uc << std::endl;
90  return retval;
91  }
92  }
93 
94  // create new value, store and return:
95  boost::shared_ptr<REP> retval = REP::New(uid);
96  mRepCache.insert(std::make_pair(uid, retval));
97 
98  return retval;
99  }
100 
101 protected:
103 
104  typedef std::multimap<QString, RepPtr> RepMultiMap;
105  RepMultiMap mRepCache;
106 
107 private:
108  RepManager();
109  virtual ~RepManager();
110  RepManager(RepManager const&);
111  RepManager& operator=(RepManager const&);
112 };
113 
114 
118 } //namespace cx
119 
120 #endif /* CXREPMANAGER_H_ */
std::map< QString, RepPtr > RepMap
Definition: cxRepManager.h:30
Rep caching and utilities.
Definition: cxRepManager.h:51
static RepManager * mTheInstance
the only instance of this class
Definition: cxRepManager.h:102
boost::shared_ptr< REP > getCachedRep(QString uid="")
Definition: cxRepManager.h:72
std::multimap< QString, RepPtr > RepMultiMap
Definition: cxRepManager.h:104
std::map< QString, VolumetricBaseRepPtr > VolumetricRepMap
Definition: cxRepManager.h:31
RepMultiMap mRepCache
Definition: cxRepManager.h:105
boost::shared_ptr< class Rep > RepPtr
Definition: cxRepManager.h:24
Namespace for all CustusX production code.