Skip to content
Snippets Groups Projects
Select Git revision
  • 6e60b71df07234c329fcf448ec67e26e5d84d525
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

export_sec_structure.cc

Blame
  • iterator.cc 5.89 KiB
    //------------------------------------------------------------------------------
    // This file is part of the OpenStructure project <www.openstructure.org>
    //
    // Copyright (C) 2008-2010 by the OpenStructure authors
    //
    // This library is free software; you can redistribute it and/or modify it under
    // the terms of the GNU Lesser General Public License as published by the Free
    // Software Foundation; either version 3.0 of the License, or (at your option)
    // any later version.
    // This library is distributed in the hope that it will be useful, but WITHOUT
    // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    // FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    // details.
    //
    // You should have received a copy of the GNU Lesser General Public License
    // along with this library; if not, write to the Free Software Foundation, Inc.,
    // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    //------------------------------------------------------------------------------
    #include <ost/mol/impl/residue_impl.hh>
    #include <ost/mol/impl/chain_impl.hh>
    #include <ost/mol/impl/entity_impl.hh>
    #include <ost/mol/impl/atom_impl.hh>
    
    #include "iterator.hh"
    
    namespace ost { namespace mol {
    
    void ResidueHandleIter::SkipEmpty()
    {
      if (cur_res_==impl::end((*cur_chain_)->GetResidueList())) {
        // we have to skip over empty chains otherwise we end up pointing to an 
        // invalid residue.
        do {
          ++cur_chain_;
          if (impl::end(ent_->GetChainList())==cur_chain_) {
            break;        
          }
          cur_res_=impl::begin((*cur_chain_)->GetResidueList());
        } while ((*cur_chain_)->GetResidueList().empty());
      }
    }
    
    ResidueHandleIter& ResidueHandleIter::operator++() 
    {
      ++cur_res_;
      this->SkipEmpty();
      return *this;
    }
    
    ResidueHandleIter::ResidueHandleIter(impl::pointer_it<impl::ChainImplPtr> chain_it, 
                                         impl::pointer_it<impl::ResidueImplPtr> res_it,
                                         impl::EntityImplPtr ent, bool skip_empty) 
     : cur_chain_(chain_it), cur_res_(res_it),
       ent_(ent) {
      if (skip_empty) {
        this->SkipEmpty();
      }
    }
    
    ResidueHandle ResidueHandleIter::operator*() {
      return ResidueHandle(*cur_res_);
    }
    
    
    
    ResidueView ResidueViewIter::operator*() {
      return ResidueView(*cur_res_);
    }
    
    void ResidueViewIter::SkipEmpty()
    {
      if (cur_res_==impl::end(cur_chain_->GetResidueList())) {
        // we have to skip over empty chains otherwise we end up pointing to an 
        // invalid residue.
        do {
          ++cur_chain_;
          if (impl::end(ent_.GetChainList())==cur_chain_) {
            break;        
          }
          cur_res_=impl::begin(cur_chain_->GetResidueList());
        } while (cur_chain_->GetResidueList().empty());
      }  
    }
    ResidueViewIter& ResidueViewIter::operator++() {
      ++cur_res_;
      this->SkipEmpty();
      return *this;
    }
    
    ResidueViewIter::ResidueViewIter(impl::pointer_it<ChainView>   chain_it,
                                     impl::pointer_it<ResidueView> res_it,
                                     EntityView ent, bool skip_empty) 
     : cur_chain_(chain_it), cur_res_(res_it),
       ent_(ent) {
      if (skip_empty) {
        this->SkipEmpty();
      }
    }
    
    AtomHandleIter::AtomHandleIter(impl::pointer_it<impl::ChainImplPtr> chain_it,
                                   impl::pointer_it<impl::ResidueImplPtr> res_it,
                                   impl::pointer_it<impl::AtomImplPtr> atom_it,
                                   impl::EntityImplPtr ent, bool skip_empty)
     : cur_chain_(chain_it), cur_res_(res_it), cur_atom_(atom_it),
       ent_(ent) 
    {
      if (skip_empty) {
        this->SkipEmpty();
      }
    }
    
    AtomHandle AtomHandleIter::operator*() {
      return AtomHandle(*cur_atom_);
    }
    
    void AtomHandleIter::SkipEmpty()
    {
      if (impl::end((*cur_res_)->GetAtomList())==cur_atom_) {
        // we have to skip over empty chains and residues otherwise we end up 
        // pointing to an invalid atom.
        do {
          ++cur_res_;
          if (impl::end((*cur_chain_)->GetResidueList())==cur_res_) {
            do {
              ++cur_chain_;
              if (impl::end(ent_->GetChainList())==cur_chain_) {
                return;
              }
    
              cur_res_=impl::begin((*cur_chain_)->GetResidueList());
              if (!(*cur_chain_)->GetResidueList().empty())          
                cur_atom_=impl::begin((*cur_res_)->GetAtomList());
              else
                cur_atom_=impl::pointer_it<impl::AtomImplPtr>(NULL);
            } while ((*cur_chain_)->GetResidueList().empty());
          } else {
            cur_atom_=impl::begin((*cur_res_)->GetAtomList());
          }
        } while ((*cur_res_)->GetAtomList().empty());
      }
    }
    
    AtomHandleIter& AtomHandleIter::operator++() 
    {
      ++cur_atom_;
      this->SkipEmpty();
      return *this;
    }
    
    AtomViewIter::AtomViewIter(impl::pointer_it<ChainView> chain_it,
                               impl::pointer_it<ResidueView> res_it,
                               impl::pointer_it<AtomView> atom_it,
                               EntityView ent, bool skip_empty)
      : cur_chain_(chain_it), cur_res_(res_it), cur_atom_(atom_it),
        ent_(ent) {
      if (skip_empty) {
        this->SkipEmpty();    
      }
    }
    
    void AtomViewIter::SkipEmpty()
    {
      if (impl::end(cur_res_->GetAtomList())==cur_atom_) {
        do {
          ++cur_res_;      
          if (impl::end(cur_chain_->GetResidueList())==cur_res_) {
            do {
              ++cur_chain_;
              if (impl::end(ent_.GetChainList())==cur_chain_) {
                return;
              }          
              cur_res_=impl::begin(cur_chain_->GetResidueList());
              if (!cur_chain_->GetResidueList().empty()) {
                cur_atom_=impl::begin(cur_res_->GetAtomList());
              } else {
                cur_atom_=impl::pointer_it<AtomView>(NULL);
              }
            } while (cur_chain_->GetResidueList().empty());
          } else {
            cur_atom_=impl::begin(cur_res_->GetAtomList());
          }
        } while (cur_res_->GetAtomList().empty());
      }
    }
    
    AtomView AtomViewIter::operator*() 
    {
      return AtomView(*cur_atom_);
    }
    
    AtomViewIter& AtomViewIter::operator++() 
    {
      ++cur_atom_;
      this->SkipEmpty();
      return *this;
    }
    
    }} // ns