Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxRepContainer.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 CXREPCONTAINER_H
34 #define CXREPCONTAINER_H
35 
36 #include "cxResourceVisualizationExport.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 typedef std::map<QString, RepPtr> RepMap;
48 typedef std::map<QString, VolumetricBaseRepPtr> VolumetricRepMap;
49 typedef boost::shared_ptr<class RepContainer> RepContainerPtr;
50 
60 class cxResourceVisualization_EXPORT RepContainer
61 {
62 public:
63  RepContainer(std::vector<RepPtr> reps) : mReps(reps) {}
64 
65  template<class REP>
66  boost::shared_ptr<REP> findFirst(ToolPtr tool)
67  {
68  for (unsigned i = 0; i < mReps.size(); ++i)
69  {
70  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
71  if (rep && rep->hasTool(tool))
72  {
73  return rep;
74  }
75  }
76  return boost::shared_ptr<REP>();
77  }
78 // template<class REP>
79 // static boost::shared_ptr<REP> findFirstRep(std::vector<RepPtr> reps, ToolPtr tool)
80 // {
81 // for (unsigned i = 0; i < reps.size(); ++i)
82 // {
83 // boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
84 // if (rep && rep->hasTool(tool))
85 // {
86 // return rep;
87 // }
88 // }
89 // return boost::shared_ptr<REP>();
90 // }
91 
92  template<class REP>
93  boost::shared_ptr<REP> findFirst(DataPtr data)
94  {
95  for (unsigned i = 0; i < mReps.size(); ++i)
96  {
97  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
98  if (rep && rep->hasData(data))
99  return rep;
100  }
101  return boost::shared_ptr<REP>();
102  }
103 // template<class REP>
104 // static boost::shared_ptr<REP> findFirstRep(std::vector<RepPtr> reps, DataPtr data)
105 // {
106 // for (unsigned i = 0; i < reps.size(); ++i)
107 // {
108 // boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
109 // if (rep && rep->hasData(data))
110 // return rep;
111 // }
112 // return boost::shared_ptr<REP>();
113 // }
114 
115  template<class REP>
116  boost::shared_ptr<REP> findFirst()
117  {
118  for (unsigned i = 0; i < mReps.size(); ++i)
119  {
120  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
121  if (rep)
122  return rep;
123  }
124  return boost::shared_ptr<REP>();
125  }
126 // template<class REP>
127 // static boost::shared_ptr<REP> findFirstRep(std::vector<RepPtr> reps)
128 // {
129 // for (unsigned i = 0; i < reps.size(); ++i)
130 // {
131 // boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
132 // if (rep)
133 // return rep;
134 // }
135 // return boost::shared_ptr<REP>();
136 // }
137 
138  template<class REP>
139  static std::vector<boost::shared_ptr<REP> > findReps(std::vector<RepPtr> reps)
140  {
141  std::vector<boost::shared_ptr<REP> > retval;
142  for (unsigned i = 0; i < reps.size(); ++i)
143  {
144  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
145  if (rep)
146  retval.push_back(rep);
147  }
148  return retval;
149  }
150 
151 private:
152  std::vector<RepPtr> mReps;
153 };
154 
155 
156 } //namespace cx
157 
158 #endif // CXREPCONTAINER_H
std::map< QString, RepPtr > RepMap
Definition: cxRepManager.h:51
boost::shared_ptr< REP > findFirst()
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class RepContainer > RepContainerPtr
boost::shared_ptr< REP > findFirst(ToolPtr tool)
std::map< QString, VolumetricBaseRepPtr > VolumetricRepMap
Definition: cxRepManager.h:52
boost::shared_ptr< REP > findFirst(DataPtr data)
static std::vector< boost::shared_ptr< REP > > findReps(std::vector< RepPtr > reps)
boost::shared_ptr< class Rep > RepPtr
Definition: cxRepManager.h:45
boost::shared_ptr< class Tool > ToolPtr
RepContainer(std::vector< RepPtr > reps)