00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_ITERATOR_HH
00020 #define OST_ITERATOR_HH
00021
00022 #include <map>
00023
00024
00025 #include <ost/mol/chain_handle.hh>
00026 #include <ost/mol/chain_view.hh>
00027 #include <ost/mol/residue_handle.hh>
00028 #include <ost/mol/residue_view.hh>
00029 #include <ost/mol/atom_handle.hh>
00030 #include <ost/mol/atom_view.hh>
00031 #include <ost/mol/entity_handle.hh>
00032 #include <ost/mol/entity_view.hh>
00033 #include <ost/mol/impl/entity_impl_fw.hh>
00034 #include <ost/mol/impl/chain_impl_fw.hh>
00035 #include <ost/mol/impl/residue_impl_fw.hh>
00036 #include <ost/mol/impl/pointer_iterator.hh>
00037
00038 namespace ost { namespace mol {
00039
00050 template <typename I>
00051 class IterRange {
00052 public:
00053 typedef I iterator_type;
00054 typedef typename I::value_type value_type;
00055 IterRange() {}
00056 IterRange(I beg, I end)
00057 : end_(end), cur_(beg) {
00058 }
00060 bool AtEnd() const {
00061 return cur_==end_;
00062 }
00064 IterRange<I>& Next() {
00065 ++cur_;
00066 return *this;
00067 }
00068 typename I::value_type& Get() {
00069 return *cur_;
00070 }
00071 IterRange<I>& operator++() {
00072 ++cur_;
00073 return *this;
00074 }
00075 typename I::value_type& operator*() {
00076 return this->Get();
00077 }
00078 private:
00079 I end_;
00080 I cur_;
00081 };
00082
00083
00084 namespace impl {
00085
00086 typedef std::vector<ChainImplPtr> ChainImplList;
00087 }
00088
00089 class DLLEXPORT_OST_MOL ChainHandleIter : public std::iterator<std::forward_iterator_tag,
00090 ChainHandle> {
00091 public:
00092 ChainHandleIter(impl::ChainImplList::iterator chain_it)
00093 : cur_(chain_it) {
00094 }
00095 public:
00096 ChainHandle operator*() {
00097 return ChainHandle(*cur_);
00098 }
00099
00100 ChainHandleIter& operator++() {
00101 ++cur_;
00102 return *this;
00103 }
00104
00105 bool operator==(const ChainHandleIter& rhs) const {
00106 return cur_==rhs.cur_;
00107 }
00108
00109 bool operator!=(const ChainHandleIter& rhs) const {
00110 return !this->operator==(rhs);
00111 }
00112 private:
00113 impl::ChainImplList::iterator cur_;
00114 };
00115
00116 class DLLEXPORT_OST_MOL ResidueHandleIter : public std::iterator<std::forward_iterator_tag,
00117 ResidueHandle> {
00118 public:
00119 ResidueHandleIter(): cur_chain_(NULL), cur_res_(NULL) { }
00120 ResidueHandleIter(impl::pointer_it<impl::ChainImplPtr> chain_it,
00121 impl::pointer_it<impl::ResidueImplPtr> res_it,
00122 impl::EntityImplPtr ent, bool skip_empty);
00123
00124 bool operator==(const ResidueHandleIter& rhs) const
00125 {
00126 return cur_res_==rhs.cur_res_;
00127 }
00128
00129 void SkipEmpty();
00130
00131 bool operator!=(const ResidueHandleIter& rhs) const
00132 {
00133 return !this->operator==(rhs);
00134 }
00135 ResidueHandleIter& operator++();
00136
00137 ResidueHandle operator*();
00138
00139 private:
00140 impl::pointer_it<impl::ChainImplPtr> cur_chain_;
00141 impl::pointer_it<impl::ResidueImplPtr> cur_res_;
00142 impl::EntityImplPtr ent_;
00143 };
00144
00145 class DLLEXPORT_OST_MOL ResidueViewIter : public std::iterator<std::forward_iterator_tag,
00146 ResidueView> {
00147 public:
00148 ResidueViewIter(): cur_chain_(NULL), cur_res_(NULL) { }
00149
00150 ResidueViewIter(impl::pointer_it<ChainView> chain_it,
00151 impl::pointer_it<ResidueView> res_it,
00152 EntityView ent, bool skip_empty);
00153
00154 bool operator==(const ResidueViewIter& rhs) const {
00155 return cur_res_==rhs.cur_res_;
00156 }
00157 void SkipEmpty();
00158
00159 bool operator!=(const ResidueViewIter& rhs) const {
00160 return !this->operator==(rhs);
00161 }
00162 ResidueViewIter& operator++();
00163
00164 ResidueView operator*();
00165
00166 private:
00167 impl::pointer_it<ChainView> cur_chain_;
00168 impl::pointer_it<ResidueView> cur_res_;
00169 EntityView ent_;
00170 };
00171
00172 class DLLEXPORT_OST_MOL AtomHandleIter : public std::iterator<std::forward_iterator_tag,
00173 AtomHandle> {
00174 public:
00175 AtomHandleIter(): cur_chain_(NULL), cur_res_(NULL), cur_atom_(NULL) { }
00176
00177 AtomHandleIter(impl::pointer_it<impl::ChainImplPtr> chain_it,
00178 impl::pointer_it<impl::ResidueImplPtr> res_it,
00179 impl::pointer_it<impl::AtomImplPtr> atom_it,
00180 impl::EntityImplPtr ent, bool skip_empty);
00181
00182 bool operator==(const AtomHandleIter& rhs) const
00183 {
00184 return cur_atom_==rhs.cur_atom_;
00185 }
00186
00187 bool operator!=(const AtomHandleIter& rhs) const
00188 {
00189 return !this->operator==(rhs);
00190 }
00191
00192 AtomHandleIter& operator++();
00193
00194 AtomHandle operator*();
00195 private:
00196 void SkipEmpty();
00197 impl::pointer_it<impl::ChainImplPtr> cur_chain_;
00198 impl::pointer_it<impl::ResidueImplPtr> cur_res_;
00199 impl::pointer_it<impl::AtomImplPtr> cur_atom_;
00200 impl::EntityImplPtr ent_;
00201 };
00202
00203 class DLLEXPORT_OST_MOL AtomViewIter : public std::iterator<std::forward_iterator_tag,
00204 AtomView> {
00205 public:
00206 AtomViewIter(): cur_chain_(NULL), cur_res_(NULL), cur_atom_(NULL) { }
00207
00208 AtomViewIter(impl::pointer_it<ChainView> chain_it,
00209 impl::pointer_it<ResidueView> res_it,
00210 impl::pointer_it<AtomView> atom_it,
00211 EntityView ent, bool skip_empty);
00212
00213 bool operator==(const AtomViewIter& rhs) const
00214 {
00215 return cur_atom_==rhs.cur_atom_;
00216 }
00217
00218 bool operator!=(const AtomViewIter& rhs) const
00219 {
00220 return !this->operator==(rhs);
00221 }
00222
00223 AtomViewIter& operator++();
00224
00225 AtomView operator*();
00226 private:
00227 void SkipEmpty();
00228 impl::pointer_it<ChainView> cur_chain_;
00229 impl::pointer_it<ResidueView> cur_res_;
00230 impl::pointer_it<AtomView> cur_atom_;
00231 EntityView ent_;
00232 };
00233
00234 }}
00235
00236
00237 #endif