btk_sequence.hpp

Go to the documentation of this file.
00001 // -*- mode: c++; indent-tabs-mode: nil; -*-
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) 2006, Tim Robertson <kid50@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 
00023 
00024 #ifndef BTK_UTILITY_BTK_SEQUENCE_HPP
00025 #define BTK_UTILITY_BTK_SEQUENCE_HPP
00026 
00027 #include <btk/core/utility/btk_container.hpp>
00028 
00029 namespace BTK {
00030 namespace UTILITY {
00031   
00032 template <typename T, typename StorageStrategy>
00033 class BTKSequence : public BTKContainer<T,StorageStrategy>
00034 {
00035   BOOST_CLASS_REQUIRE(StorageStrategy,boost,SequenceConcept);
00036   typedef BTKSequence<T,StorageStrategy> self_type;
00037   typedef BTKContainer<T,StorageStrategy> base_type;
00038 
00039 public:
00040   IMPORT_BTK_CONTAINER_TYPES(base_type);
00041 
00043 
00044   
00045   BTKSequence(self_type const & source) : base_type(source) {}
00046   virtual ~BTKSequence() {}
00047 
00049 
00051 
00052   BTKSequence(size_type n = 0, const_reference t = value_type()) : 
00053     base_type(n,t) {}
00054   
00055   template <typename InputIterator>
00056   BTKSequence(InputIterator i, InputIterator j) : base_type(i,j) {}
00057 
00059 
00061 
00062   
00063   reference front() { return base_type::_storage.front(); }
00064   const_reference front() const { return base_type::_storage.front(); }
00065   
00066   virtual iterator insert(iterator p, const_reference t) 
00067   {
00068     return base_type::_storage.insert(p,t);
00069   }
00070 
00071   virtual void insert(iterator p, size_type n, const_reference t) 
00072   {
00073     base_type::_storage.insert(p,n,t);
00074   }
00075 
00076   template <typename InputIterator>
00077   void insert(iterator p, InputIterator i, InputIterator j)
00078   {
00079     boost::function_requires<boost::InputIteratorConcept<InputIterator> >();
00080     base_type::_storage.insert(p,i,j);
00081   }
00082 
00083   virtual iterator erase(iterator p) { return base_type::_storage.erase(p); }
00084   virtual iterator erase(iterator p, iterator q) 
00085   { return base_type::_storage.erase(p,q); }
00086 
00087   virtual void clear() { base_type::_storage.clear(); }
00088 
00089   virtual void resize(size_type n, const_reference t = value_type()) 
00090   { base_type::_storage.resize(n,t); }
00091   
00093 };
00094 
00095 // The declaration of the template function in this macro is a workaround
00096 // for g++ versions < 4, b/c they get pissy about using declarations w/
00097 // template member functions.
00098 #define IMPORT_BTK_SEQUENCE_METHODS(Sequence)                       \
00099   using Sequence::front;                                            \
00100   using Sequence::insert;                                           \
00101   template <typename InputIterator>                                 \
00102   void insert(iterator p, InputIterator i, InputIterator j)         \
00103   { Sequence::insert(p,i,j); }                                      \
00104   using Sequence::erase;                                            \
00105   using Sequence::clear;                                            \
00106   using Sequence::resize;
00107 
00108 } // namespace UTILITY
00109 } // namespace BTK
00110 
00111 #endif // BTK_UTILITY_BTK_SEQUENCE_HPP

Generated on Sun Jul 15 20:46:24 2007 for BTK Core by  doxygen 1.5.1