00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00025 
00026 #ifndef BTK_MOLECULES_MONOMER_HPP
00027 #define BTK_MOLECULES_MONOMER_HPP
00028 
00029 #include <boost/operators.hpp>
00030 
00031 #include <btk/core/molecules/atomic_structure.hpp>
00032 
00033 namespace BTK {
00034 namespace MOLECULES {
00035 
00036 template <typename AtomType,
00037           typename ChemicalTypeSystemType =
00038             typename AtomType::chemical_type_system,
00039           typename DictionaryType =
00040             typename ChemicalTypeSystemType::monomer_dictionary,
00041           typename StorageStrategy = std::vector<AtomType> >
00042 class Monomer : 
00043     public AtomicStructure<AtomType,
00044                            ChemicalTypeSystemType,
00045                            DictionaryType,
00046                            StorageStrategy>,
00047     public boost::less_than_comparable<Monomer<AtomType,
00048                                                ChemicalTypeSystemType,
00049                                                DictionaryType,
00050                                                StorageStrategy> >
00051 {
00052   typedef AtomicStructure<AtomType,
00053                           ChemicalTypeSystemType,
00054                           DictionaryType,
00055                           StorageStrategy> base_type;
00056   typedef Monomer<AtomType,
00057                   ChemicalTypeSystemType,
00058                   DictionaryType,
00059                   StorageStrategy> self_type;
00060 public:
00061   IMPORT_ATOMIC_STRUCTURE_TYPES(base_type);
00062   typedef id_type monomer_id_type;
00063 
00064   Monomer(unsigned n = 0,
00065           atom_type const & a = atom_type(),
00066           id_type type = id_type(),
00067           int number = 0) : 
00068     base_type(n,a,type), _number(number), _selected(false) {}
00069   
00070   template <typename AtomIterator>
00071   Monomer(AtomIterator i, AtomIterator j,
00072           monomer_id_type type,
00073           int number) : 
00074     base_type(i,j,type), _number(number), _selected(false) {}
00075 
00076   Monomer(self_type const & source) : 
00077     base_type(source), _number(source._number), _selected(false) {}
00078 
00079   virtual ~Monomer() {}
00080 
00081   
00082   
00083   
00084   IMPORT_BTK_CONTAINER_METHODS(base_type);
00085 
00086   
00087   
00088   
00089   atom_iterator monomer_begin() { return base_type::structure_begin(); }
00090   const_atom_iterator monomer_begin() const 
00091   { 
00092     return base_type::structure_begin();
00093   }
00094 
00095   atom_iterator monomer_end() { return base_type::structure_end(); }
00096   const_atom_iterator monomer_end() const 
00097   { 
00098     return base_type::structure_end();
00099   }
00100 
00101   reverse_atom_iterator monomer_rbegin() { return base_type::structure_rbegin(); }
00102   const_reverse_atom_iterator monomer_rbegin() const 
00103   { 
00104     return base_type::structure_rbegin();
00105   }
00106 
00107   reverse_atom_iterator monomer_rend() { return base_type::structure_rend(); }
00108   const_reverse_atom_iterator monomer_rend() const 
00109   { 
00110     return base_type::structure_rend();
00111   }
00112 
00113   int number() const { return _number; }
00114   void set_number(int number) { _number = number; }
00115 
00116   bool selected() const { return _selected; }
00117   void select(bool s = true) const 
00118   { 
00119     _selected = s; 
00120     const_atom_iterator end = base_type::structure_end();
00121 
00122     for (const_atom_iterator i = base_type::structure_begin(); i != end; ++i)
00123       i->select(s);
00124   }
00125 
00126   virtual dictionary const & get_dictionary() const 
00127   {
00128     return base_type::get_chemical_type_system().get_monomer_dictionary();
00129   }
00130 
00131   virtual dictionary & get_dictionary() 
00132   {
00133     return base_type::get_chemical_type_system().get_monomer_dictionary();
00134   }
00135 
00136   void swap(self_type & b)
00137   {
00138     base_type::swap(b);
00139     std::swap(_number,b._number);
00140     std::swap(_selected,b._selected);
00141   }
00142 
00143   self_type const & operator=(self_type const & rhs)
00144   {
00145     if (this == &rhs) return *this;
00146     base_type::operator=(rhs);
00147     _number = rhs._number;
00148     _selected = rhs._selected;
00149     return *this;
00150   }
00151 
00152   bool operator==(self_type const & rhs) const 
00153   {
00154     return (_number == rhs._number &&
00155             base_type::operator==(rhs));
00156   }
00157 
00158   bool operator!=(self_type const & rhs) const
00159   {
00160     return !(operator==(rhs));
00161   }
00162 
00163   bool operator<(self_type const & rhs) const
00164   {
00165     return (_number < rhs._number || 
00166             (_number == rhs._number && base_type::operator<(rhs)));
00167   }
00168 
00169 private:
00170   int _number;
00171   mutable bool _selected;
00172 };
00173 
00174 #define IMPORT_MONOMER_TYPES(MonomerType)                          \
00175   IMPORT_ATOMIC_STRUCTURE_TYPES(MonomerType)                       \
00176   typedef typename MonomerType::monomer_id_type monomer_id_type;
00177 
00178 } 
00179 } 
00180 
00181 #endif //BTK_MOLECULES_MONOMER_HPP