$extrastylesheet
parameter_vector.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 #ifndef LIBMESH_PARAMETER_VECTOR_H
00021 #define LIBMESH_PARAMETER_VECTOR_H
00022 
00023 
00024 // Local Includes -----------------------------------
00025 #include "libmesh/libmesh_common.h"
00026 #include "libmesh/parameter_pointer.h"
00027 
00028 // C++ Includes   -----------------------------------
00029 #include <vector>
00030 
00031 namespace libMesh
00032 {
00033 
00034 
00039 class ParameterVector
00040 {
00041 public:
00045   ParameterVector() : _is_shallow_copy(false) {}
00046 
00050   explicit
00051   ParameterVector(const std::vector<Number *> &params);
00052 
00056   ~ParameterVector();
00057 
00062   void deep_copy(ParameterVector &target) const;
00063 
00068   void shallow_copy(ParameterVector &target) const;
00069 
00075   void value_copy(ParameterVector &target) const;
00076 
00080   void clear();
00081 
00085   std::size_t size() const { return _params.size(); }
00086 
00092   void resize(unsigned int s);
00093 
00098   void deep_resize(unsigned int s);
00099 
00103   const ParameterAccessor<Number>& operator[](unsigned int i) const;
00104 
00111   ParameterAccessor<Number>& operator[](unsigned int i);
00112 
00116   ParameterVector& operator *= (const Number a);
00117 
00122   ParameterVector& operator += (const ParameterVector& a);
00123 
00124 private:
00128   std::vector<ParameterAccessor<Number> *> _params;
00129 
00133   std::vector<Number> _my_data;
00134 
00139   bool _is_shallow_copy;
00140 };
00141 
00142 
00143 
00144 // ------------------------------------------------------------
00145 // ParameterVector inline methods
00146 
00147 inline
00148 ParameterVector::ParameterVector(const std::vector<Number *> &params)
00149   : _is_shallow_copy(false)
00150 {
00151   _params.reserve(params.size());
00152 
00153   for (unsigned int i=0; i != params.size(); ++i)
00154     _params.push_back(new ParameterPointer<Number>(params[i]));
00155 }
00156 
00157 
00158 inline
00159 ParameterVector::~ParameterVector()
00160 {
00161   this->clear();
00162 }
00163 
00164 
00165 inline
00166 void
00167 ParameterVector::clear()
00168 {
00169   if (_is_shallow_copy)
00170     for (unsigned int i=0; i != _params.size(); ++i)
00171       delete _params[i];
00172 
00173   _params.clear();
00174   _my_data.clear();
00175 }
00176 
00177 
00178 
00179 inline
00180 const ParameterAccessor<Number>& ParameterVector::operator[] (unsigned int i) const
00181 {
00182   libmesh_assert_greater (_params.size(), i);
00183 
00184   return *_params[i];
00185 }
00186 
00187 
00188 
00189 inline
00190 ParameterAccessor<Number>& ParameterVector::operator[] (unsigned int i)
00191 {
00192   libmesh_assert_greater (_params.size(), i);
00193 
00194   return *_params[i];
00195 }
00196 
00197 } // namespace libMesh
00198 
00199 #endif // LIBMESH_PARAMETER_VECTOR_H