Skip to content
Snippets Groups Projects
Commit b643d81c authored by stefan's avatar stefan
Browse files

Fix, Bounds check for AlignedRegion and AlignedColumn

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2229 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 95ddda14
Branches
Tags
No related merge requests found
......@@ -38,16 +38,19 @@ int AlignedColumn::GetIndex() const
char AlignedColumn::operator[](int row) const
{
this->CheckRowValidity(row);
return aln_.GetOneLetterCode(row, index_);
}
int AlignedColumn::GetResidueIndex(int row) const
{
this->CheckRowValidity(row);
return aln_.GetResidueIndex(row, index_);
}
mol::ResidueView AlignedColumn::GetResidue(int row) const
{
this->CheckRowValidity(row);
return aln_.GetResidue(row, index_);
}
......@@ -64,4 +67,12 @@ int AlignedColumn::GetRowCount() const
return aln_.GetCount();
}
void AlignedColumn::CheckRowValidity(int row) const
{
if(row<0 || row>=this->GetRowCount()){
throw std::out_of_range("Row out of bounds");
}
}
}}
......@@ -55,6 +55,8 @@ public:
/// \sa AlignmentHandle::GetResidue()
mol::ResidueView GetResidue(int row) const;
private:
void CheckRowValidity(int row) const;
AlignmentHandle aln_;
int index_;
};
......
......@@ -94,7 +94,11 @@ AlignedColumnIterator AlignedRegion::end()
AlignedColumn AlignedRegion::operator[](int index) const
{
return AlignedColumn(aln_, start_+index);
int col_index = start_+index;
if(col_index<start_ || col_index>=end_){
throw std::out_of_range("Index out of region");
}
return AlignedColumn(aln_, col_index);
}
bool AlignedRegion::operator==(const AlignedRegion& rhs) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment