]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Store a vector<shared_ptr<Object> > rather than a vector<Object>. This change is...
authorhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 27 May 2003 14:59:24 +0000 (14:59 +0000)
committerhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 27 May 2003 14:59:24 +0000 (14:59 +0000)
git-svn-id: https://svn.dealii.org/trunk@7676 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/mg_level_object.h

index f381bf4d733e6fee990c73a1039ee62229e9da9c..f3ddd24d1ea167f5c5f95e82eaa7ced1974bd356 100644 (file)
@@ -17,6 +17,8 @@
 #include <vector>
 
 
+#include <boost_local/shared_ptr.hpp>
+
 
 /**
  * An array with an object for each level.  The purpose of this class
@@ -95,7 +97,7 @@ class MGLevelObject : public Subscriptor
                                     /**
                                      * Array of the objects to be held.
                                      */
-    std::vector<Object> objects;
+    std::vector<boost::shared_ptr<Object> > objects;
 };
 
 
@@ -118,7 +120,7 @@ MGLevelObject<Object>::operator[] (const unsigned int i)
 {
   Assert((i>=minlevel) && (i<minlevel+objects.size()),
         ExcIndexRange (i, minlevel, minlevel+objects.size()));
-  return objects[i-minlevel];
+  return *objects[i-minlevel];
 }
 
 
@@ -128,7 +130,7 @@ MGLevelObject<Object>::operator[] (const unsigned int i) const
 {
   Assert((i>=minlevel) && (i<minlevel+objects.size()),
         ExcIndexRange (i, minlevel, minlevel+objects.size()));
-  return objects[i-minlevel];
+  return *objects[i-minlevel];
 }
 
 
@@ -138,10 +140,15 @@ MGLevelObject<Object>::resize (const unsigned int new_minlevel,
                               const unsigned int new_maxlevel)
 {
   Assert (new_minlevel <= new_maxlevel, ExcInternalError());
+                                  // note that on clear(), the
+                                  // shared_ptr class takes care of
+                                  // deleting the object it points to
+                                  // by itself
   objects.clear ();
 
   minlevel = new_minlevel;
-  objects.resize (new_maxlevel - new_minlevel + 1);
+  for (unsigned int i=0; i<new_maxlevel-new_minlevel+1; ++i)
+    objects.push_back(boost::shared_ptr<Object> (new Object)); 
 }
 
 
@@ -149,9 +156,9 @@ template<class Object>
 void
 MGLevelObject<Object>::clear ()
 {
-  typename std::vector<Object>::iterator v;
+  typename std::vector<boost::shared_ptr<Object> >::iterator v;
   for (v = objects.begin(); v != objects.end(); ++v)
-    v->clear();  
+    (*v)->clear();  
 }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.