CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXREPMANAGER_H_
34 #define CXREPMANAGER_H_
35 
36 #include "org_custusx_core_view_Export.h"
37 
38 #include <QObject>
39 #include <map>
40 #include <vector>
41 #include "cxForwardDeclarations.h"
42 
43 namespace cx
44 {
45 typedef boost::shared_ptr<class Rep> RepPtr;
46 }
47 
48 namespace cx
49 {
50 
51 typedef std::map<QString, RepPtr> RepMap;
52 typedef std::map<QString, VolumetricBaseRepPtr> VolumetricRepMap;
53 typedef boost::shared_ptr<class ThresholdPreview> ThresholdPreviewPtr;
54 
55 class Reporter;
56 
73 class org_custusx_core_view_EXPORT RepManager: public QObject
74 {
75 Q_OBJECT
76 
77 public:
78  static RepManager* getInstance();
79  static void destroyInstance();
80 
81  ThresholdPreviewPtr getThresholdPreview();
82 
95  template<class REP>
96  boost::shared_ptr<REP> getCachedRep(QString uid = "")
97  {
98  // look for existing value:
99  for (RepMultiMap::iterator iter = mRepCache.begin(); iter != mRepCache.end(); ++iter)
100  {
101  if (iter->first != uid)
102  continue;
103  int uc = iter->second.use_count();
104  if (uc >1)
105  {
106 // std::cout << "cached rep in use: " << uid.toStdString() << ", use count: " << uc << std::endl;
107  continue;
108  }
109 
110  boost::shared_ptr<REP> retval = boost::dynamic_pointer_cast<REP>(iter->second);
111  if (retval)
112  {
113 // std::cout << "reusing cached rep: " << uid.toStdString() << ", use count: " << uc << std::endl;
114  return retval;
115  }
116  }
117 
118  // create new value, store and return:
119  boost::shared_ptr<REP> retval = REP::New(uid);
120  mRepCache.insert(std::make_pair(uid, retval));
121 
122  return retval;
123  }
124 
125 protected:
127 
128  typedef std::multimap<QString, RepPtr> RepMultiMap;
130 
131 private:
132  RepManager();
133  virtual ~RepManager();
134  RepManager(RepManager const&);
135  RepManager& operator=(RepManager const&);
136  ThresholdPreviewPtr mThresholdPreview;
137 };
138 
139 
143 } //namespace cx
144 
145 #endif /* CXREPMANAGER_H_ */
std::map< QString, RepPtr > RepMap
Definition: cxRepManager.h:51
Rep caching and utilities.
Definition: cxRepManager.h:73
static RepManager * mTheInstance
the only instance of this class
Definition: cxRepManager.h:126
boost::shared_ptr< REP > getCachedRep(QString uid="")
Definition: cxRepManager.h:96
std::multimap< QString, RepPtr > RepMultiMap
Definition: cxRepManager.h:128
boost::shared_ptr< class ThresholdPreview > ThresholdPreviewPtr
Definition: cxRepManager.h:53
std::map< QString, VolumetricBaseRepPtr > VolumetricRepMap
Definition: cxRepManager.h:52
RepMultiMap mRepCache
Definition: cxRepManager.h:129
boost::shared_ptr< class Rep > RepPtr
Definition: cxRepManager.h:45