MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WallHandler.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #include "WallHandler.h"
27 #include "BaseWall.h"
28 #include "CylindricalWall.h"
30 #include "FiniteWall.h"
31 #include "InfiniteWall.h"
32 #include "InfiniteWallWithHole.h"
33 #include "Screw.h"
34 #include "Walls/Coil.h"
35 
36 
38 {
39  clear();
40  #ifdef CONSTUCTOR_OUTPUT
41  std::cout << "WallHandler::WallHandler() finished" << std::endl;
42  #endif
43 }
44 
47 {
48  clear();
49  for (std::vector<BaseWall*>::const_iterator it=WH.begin();it!=WH.end();it++)
50  {
51  addWall((*it)->copy());
52  }
53  #ifdef CONSTUCTOR_OUTPUT
54  std::cout << "WallHandler::WallHandler(const WallHandler &WH) finished" << std::endl;
55  #endif
56 }
57 
60 {
61  if (this != &rhs)
62  {
63  clear();
64  for (std::vector<BaseWall*>::const_iterator it=rhs.begin();it!=rhs.end();it++)
65  {
66  addWall((*it)->copy());
67  }
68  }
69  #ifdef OPERATOR_OUTPUT
70  std::cout << "WallHandler WallHandler::operator = (const WallHandler& rhs) finished" << std::endl;
71  #endif
72  return *this;
73 }
74 
76 {
77  clear();
78  #ifdef DESTRUCTOR_OUTPUT
79  std::cout << "WallHandler::~WallHandler() finished" << std::endl;
80  #endif
81 }
82 
85 {
86  addWall(W.copy());
87 }
88 
91 {
92  addWall(W->copy());
93 }
94 
95 
98 {
99  walls_.push_back(W);
100 }
101 
104 void WallHandler::removeWall(const unsigned int id)
105 {
106  //Physically remove Wall
107  delete getWall(id);
108 
109  //If the Wall was the last Wall nothing has to be done, otherwise some additional work is neccesary
110  if (getWall(id) != getLastWall())
111  {
112  //Copy the pointer to the last Wall to position id
113  walls_[id] = getLastWall();
114  }
115  //Remove the (now double) reference to that last Wall
116  walls_.pop_back();
117 }
118 
120 {
121  //Physically removes Wall
122  delete getLastWall();
123  //Remove the (now double) reference to that last Wall
124  walls_.pop_back();
125 }
126 
128 {
129  walls_.clear();
130 }
131 
133 void WallHandler::readWall(std::istream& is)
134 {
135  std::string type;
136  is >> type;
137  if(type.compare("CylindricalWall")==0)
138  {
139  CylindricalWall cylindricalWall;
140  is>>cylindricalWall;
141  copyAndAddWall(cylindricalWall);
142  }
143  else if(type.compare("FiniteAxisSymmetricWall")==0)
144  {
145  FiniteAxisSymmetricWall finiteAxisSymmetricWall;
146  is>>finiteAxisSymmetricWall;
147  copyAndAddWall(finiteAxisSymmetricWall);
148  }
149  else if(type.compare("FiniteWall")==0)
150  {
151  FiniteWall finiteWall;
152  is>>finiteWall;
153  copyAndAddWall(finiteWall);
154  }
155  else if(type.compare("InfiniteWall")==0)
156  {
157  InfiniteWall infiniteWall;
158  is>>infiniteWall;
159  copyAndAddWall(infiniteWall);
160  }
161  else if(type.compare("InfiniteWallWithHole")==0)
162  {
163  InfiniteWallWithHole infiniteWallWithHole;
164  is>>infiniteWallWithHole;
165  copyAndAddWall(infiniteWallWithHole);
166  }
167  else if(type.compare("Screw")==0)
168  {
169  Screw screw;
170  is>>screw;
171  copyAndAddWall(screw);
172  }
173  else if(type.compare("Coil")==0)
174  {
175  Coil coil;
176  is>>coil;
177  copyAndAddWall(coil);
178  }
179  //for backward compatibility (before svnversion ~2360)
180  else if(type.compare("numFiniteWalls")==0)
181  {
182  int numFiniteWalls;
183  is >> numFiniteWalls;
184  if (numFiniteWalls) {
185  FiniteWall finiteWallInstance;
186  is>>finiteWallInstance;
187  copyAndAddWall(finiteWallInstance);
188  } else {
189  InfiniteWall infiniteWallInstance;
190  is>>infiniteWallInstance;
191  copyAndAddWall(infiniteWallInstance);
192  }
193  }
194  else
195  {
196  std::cerr<<"Wall type: "<<type<<" not understood in restart file"<<std::endl;
197  exit(-1);
198  }
199 }
200 
203 BaseWall* WallHandler::getWall(const unsigned int id) const
204 {
205  if (id<getNumberOfWalls())
206  {
207  return walls_[id];
208  }
209  else
210  {
211  std::cerr<<"In: BaseWall* WallHandler::getWall(const unsigned int id) const"<<std::endl;
212  std::cerr<<"No BaseWall exist with index "<<id<<" maximum index is "<<getNumberOfWalls()<<std::endl;
213  exit(-1);
214  }
215 }
216 
219 {
220  return walls_.back();
221 }
222 
224 unsigned int WallHandler::getNumberOfWalls() const
225 {
226  return walls_.size();
227 }
228 
231 {
232  return walls_.capacity();
233 }
234 
236 void WallHandler::setStorageCapacity(const unsigned int N)
237 {
238  walls_.reserve(N);
239 }
240 
242 const std::vector<BaseWall*>::const_iterator WallHandler::begin() const
243 {
244  return walls_.begin();
245 }
246 
248 const std::vector<BaseWall*>::iterator WallHandler::begin()
249 {
250  return walls_.begin();
251 }
252 
254 const std::vector<BaseWall*>::const_iterator WallHandler::end() const
255 {
256  return walls_.end();
257 }
258 
260 const std::vector<BaseWall*>::iterator WallHandler::end()
261 {
262  return walls_.end();
263 }
unsigned int getStorageCapacity() const
Gets the storage capacity of this WallHandler.
Definition: WallHandler.cc:230
void readWall(std::istream &is)
Reads BaseWall into the WallHandler from restart data.
Definition: WallHandler.cc:133
std::vector< BaseWall * > walls_
The actual list of Wall pointers.
Definition: WallHandler.h:101
This function defines a archimedes screw in the z-direction from a (constant) starting point...
Definition: Screw.h:41
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this WallHandler.
Definition: WallHandler.cc:236
BaseWall * getLastWall() const
Gets a pointer to the last BaseWall in this WallHandler.
Definition: WallHandler.cc:218
void removeLastWall()
Removes the last BaseWall from the WallHandler.
Definition: WallHandler.cc:119
const std::vector< BaseWall * >::const_iterator begin() const
Gets the begin of the const_iterator over all BaseWall in this WallHandler.
Definition: WallHandler.cc:242
const std::vector< BaseWall * >::const_iterator end() const
Gets the end of the const_iterator over all BaseWall in this WallHandler.
Definition: WallHandler.cc:254
void copyAndAddWall(const BaseWall &B)
Creates a copy of a BaseWall and adds it to the WallHandler.
Definition: WallHandler.cc:84
unsigned int getNumberOfWalls() const
Gets the number of BaseWalls in this WallHandler.
Definition: WallHandler.cc:224
WallHandler()
Default WallHandler constructor, it simply creates an empty WallHandler.
Definition: WallHandler.cc:37
void addWall(BaseWall *W)
Adds a new BaseWall to the WallHandler.
Definition: WallHandler.cc:97
Container to store all BaseWall.
Definition: WallHandler.h:36
This is a class defining walls.
Definition: InfiniteWall.h:42
WallHandler operator=(const WallHandler &rhs)
Assigns one WallHandler to another WallHandler.
Definition: WallHandler.cc:59
~WallHandler()
Destructor, it simply destructs the WallHandler and all BaseWall it contains.
Definition: WallHandler.cc:75
BaseWall * getWall(const unsigned int id) const
Gets a pointer to the BaseWall at the specified index in the WallHandler.
Definition: WallHandler.cc:203
This function defines a coil in the z-direction from a (constant) starting point, a (constant) length...
Definition: Coil.h:40
virtual BaseWall * copy() const =0
void clear()
Empties the whole WallHandler by removing all BaseWall.
Definition: WallHandler.cc:127
This is a class defining walls.
void removeWall(unsigned const int id)
Removes a BaseWall from the WallHandler.
Definition: WallHandler.cc:104