predicates.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) 2005-2006, Tim Robertson <kid50@users.sourceforge.net>,
00006 //                         Chris Saunders <ctsa@users.sourceforge.net>
00007 //
00008 //This program is free software; you can redistribute it and/or modify
00009 //it under the terms of the GNU Lesser General Public License as published
00010 //by the Free Software Foundation; either version 2.1 of the License, or (at
00011 //your option) any later version.
00012 //
00013 //This program is distributed in the hope that it will be useful,  but
00014 //WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //Lesser General Public License for more details.
00017 //
00018 //You should have received a copy of the GNU Lesser General Public License
00019 //along with this program; if not, write to the Free Software Foundation,
00020 //Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00024 
00025 #ifndef BTK_ALGORITHMS_PREDICATES_HPP
00026 #define BTK_ALGORITHMS_PREDICATES_HPP
00027 
00028 #include <string>
00029 
00030 namespace BTK {
00031 namespace ALGORITHMS {
00032 
00035 struct is_any {
00036   template <typename T>
00037   bool operator()(T const & t){
00038     return true;
00039   }
00040 };
00041 
00044 struct is_selected {
00045   template <typename T>
00046   bool operator()(T const & t){
00047     return t.selected();
00048   }
00049 };
00050 
00053 struct is_not_selected {
00054   template <typename T>
00055   bool operator()(T const & t) {
00056     return !t.selected();
00057   }
00058 };
00059 
00063 struct is_named {
00064   is_named() {}
00065   is_named(std::string const & name) :
00066     _name(name) {}
00067   
00068   template <typename T>
00069   bool operator()(T const & t) {
00070     return (t.name() == _name);
00071   }
00072 
00073   template <typename T>
00074   bool operator()(T const & t, std::string const & s) {
00075     return (t.name() == s);
00076   }
00077   
00078   std::string _name;
00079 };
00080 
00086 template <typename IDType>
00087 struct type_is {
00088   type_is() {}
00089   type_is(IDType t) :
00090     _t(t) {}
00091 
00092   template <typename T>
00093   bool operator()(T const & t) {
00094     return (t.type() == _t);
00095   }
00096 
00097   template <typename T>
00098   bool operator()(T const & t, IDType const & id) {
00099     return (t.type() == id);
00100   }
00101   
00102   IDType _t;
00103 };
00104 
00108 struct chain_id_is {
00109   chain_id_is() {}
00110   chain_id_is(char chain_id) : _c(chain_id) {}
00111 
00112   template <typename T>
00113   bool operator()(T const & t) {
00114     return (t.chain_id() == _c);
00115   }
00116 
00117   template <typename T>
00118   bool operator()(T const & t, char c) {
00119     return (t.chain_id() == c); 
00120   }
00121   
00122   char _c;
00123 };
00124 
00127 template <typename NumType = int>
00128 struct number_is {
00129   
00130   number_is() {}
00131   number_is(NumType t) : _number(t) {}
00132   
00133   template <typename T>
00134   bool operator()(T const & t) {
00135     return (t.number() == _number);
00136   }
00137   
00138   template <typename T>
00139   bool operator()(T const & t, NumType const & n)
00140   {
00141     return (t.number() == n);
00142   }
00143                 
00144   NumType _number;
00145 };
00146 
00147 } // namespace ALGORITHMS
00148 } // namespace BTK
00149 
00150 #endif
00151 
00152 

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