Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

shared_vector_base.hpp

Go to the documentation of this file.
00001 // -*- mode: c++; -*-
00002 //
00003 //The Biomolecule Toolkit (BTK) is a C++ library for use in the
00004 //modeling, analysis, and design of biological macromolecules.
00005 //Copyright (C) 2004, Christopher Saunders <ctsa@users.sourceforge.net>
00006 //
00007 //This program is free software; you can redistribute it and/or modify
00008 //it under the terms of the GNU Lesser General Public License as published
00009 //by the Free Software Foundation; either version 2.1 of the License, or (at
00010 //your option) any later version.
00011 //
00012 //This program is distributed in the hope that it will be useful,  but
00013 //WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 //Lesser General Public License for more details. 
00016 //
00017 //You should have received a copy of the GNU Lesser General Public License 
00018 //along with this program; if not, write to the Free Software Foundation, 
00019 //Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 
00022 #include <boost/concept_check.hpp>
00023 
00024 #include <algorithm>
00025 #include <iterator>
00026 
00027 
00028 template <typename T>
00029 template <typename InputIterator>
00030 BTK::SharedVectorBase<T>::
00031 SharedVectorBase(InputIterator first,
00032                  InputIterator last){
00034 //  
00035 //  typedef typename std::iterator_traits<InputIterator>::value_type InputT;
00036 //  boost::function_requires<boost::ConvertibleConcept<InputT,value_type> >();
00037   
00038   for (;first!=last;++first) { push_back(static_cast<value_type>(*first)); }
00039 }
00040 
00041 template <typename T>
00042 void 
00043 BTK::SharedVectorBase<T>::
00044 insert(iterator pos,
00045        size_type s,
00046        const value_type& x){
00047   direct_iterator _pos = pos.base();
00048   for(;s>0;--s){
00049     shared_pointer p(new value_type(x));
00050     _pos = _vector.insert(_pos,p);
00051     _pos++;
00052   }
00053 }
00054 
00055 template <typename T>
00056 template <typename InputIterator>
00057 void 
00058 BTK::SharedVectorBase<T>::
00059 insert(iterator pos,
00060        InputIterator first,
00061        InputIterator last){
00062   direct_iterator _pos = pos.base();
00063   while(first != last){
00064     shared_pointer p(new value_type(*first));
00065     _pos = _vector.insert(_pos,p);
00066     ++_pos; ++first;
00067   }
00068 }
00069 
00070 template <typename T>
00071 template <typename T2>
00072 void 
00073 BTK::SharedVectorBase<T>::
00074 deep_copy(const SharedVectorBase<T2>& source) {
00075   boost::function_requires<boost::ConvertibleConcept<T2,value_type> >();
00076 
00077   clear();
00078   reserve(source.size());
00079   typename SharedVectorBase<T2>::const_iterator i=source.begin(),i_end=source.end();
00080   for(;i!=i_end;++i){
00081     push_back(*i);
00082   }
00083 #if 0
00084   // ctsa:
00085   // I can't get this code:
00086   // Polymer<Monomer<Atom> > m;
00087   // Polymer<Monomer<MonomerAtom> > m2;
00088   // m = m2;
00089   // ...to work using std copy, the atom types up-convert just fine in the code above
00090   std::copy(source.begin(),
00091       source.end(),
00092       std::back_insert_iterator<self_type>(*this));
00093 #endif
00094 }
00095 
00096 template <typename T>
00097 void 
00098 BTK::SharedVectorBase<T>::
00099 shallow_copy(const self_type& source){
00100   clear();
00101   reserve(source.size());
00102   std::copy(source._vector.begin(),
00103       source._vector.end(),
00104       std::back_insert_iterator<container_type>(_vector));
00105 }
00106 
00107 

Generated on Wed Apr 14 00:43:18 2004 for BTK by doxygen 1.3.6