Skip to content
Snippets Groups Projects
Commit ca48c2ab authored by marco's avatar marco
Browse files

atom views hashcode is no longer based on AtomImpl's address

I've carefully audited all callers of AtomView::GetHashCode()
and changed them to AtomView::GetHandle().GetHashCode() where
required.

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2259 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 750a2091
Branches
Tags
No related merge requests found
......@@ -43,9 +43,9 @@ void GfxView::AddAtom(const AtomView& av)
AtomEntry ae(a,default_radius,
a.GetRadius(),
GfxObj::Ele2Color(a.GetElement()));
atom_map[a.GetHashCode()]=ae;
atom_map[a.GetHandle().GetHashCode()]=ae;
if(av.GetBondCount()==0) {
orphan_atom_list.push_back(a.GetHashCode());
orphan_atom_list.push_back(a.GetHandle().GetHashCode());
}
}
......
......@@ -42,8 +42,6 @@ void export_Atom()
.add_property("qualified_name", &AtomBase::GetQualifiedName)
.def("IsValid", &AtomBase::IsValid)
.def(self_ns::str(self))
.add_property("hash_code", &AtomBase::GetHashCode)
.def("GetHashCode", &AtomBase::GetHashCode)
.def("GetAtomProps", &AtomBase::GetAtomProps,
return_value_policy<copy_const_reference>())
.def("SetAtomProps", &AtomBase::SetAtomProps, args("prop"))
......@@ -86,10 +84,12 @@ void export_Atom()
.add_property("handle", &AtomHandle::GetHandle)
.add_property("entity", &AtomHandle::GetEntity)
.def("GetBondPartners", &AtomHandle::GetBondPartners)
.def("GetHashCode", &AtomHandle::GetHashCode)
.def("FindBondToAtom", &AtomHandle::FindBondToAtom, args("other_atom"))
.def(self==self)
.def(self!=self)
.def("__hash__", &AtomHandle::GetHashCode)
.add_property("hash_code", &AtomHandle::GetHashCode)
;
class_<AtomHandleList>("AtomHandleList", no_init)
......
......@@ -43,6 +43,9 @@ void export_AtomView()
.def("GetHandle", &AtomView::GetHandle)
.def("GetBondCount", &AtomView::GetBondCount)
.def("GetBondList", &AtomView::GetBondList)
.def("GetHashCode", &AtomView::GetHashCode)
.def("__hash__", &AtomView::GetHashCode)
.add_property("hash_code", &AtomView::GetHashCode)
.def("GetBondPartners", &AtomView::GetBondPartners)
;
class_<AtomViewList>("AtomViewList", init<>())
......
......@@ -120,12 +120,6 @@ void AtomBase::CheckValidity() const
throw InvalidHandle();
}
long AtomBase::GetHashCode() const
{
this->CheckValidity();
return reinterpret_cast<long>(Impl().get());
}
std::ostream& operator<<(std::ostream& os, const AtomBase& atom)
{
if (atom.IsValid()) {
......
......@@ -153,11 +153,6 @@ public:
/// \brief get atom implementation
impl::AtomImplPtr& Impl();
/// \brief Get unique identifier for atom
///
/// Get hash code that uniquely identifies every atom. The hash code is
/// identical for all atom views pointing to a given atom.
long GetHashCode() const;
protected:
GenericPropContainerImpl* GpImpl();
......
......@@ -116,6 +116,12 @@ AtomHandle AtomHandle::GetHandle() const
return *this;
}
long AtomHandle::GetHashCode() const
{
this->CheckValidity();
return reinterpret_cast<long>(Impl().get());
}
}} // ns
......@@ -81,6 +81,13 @@ public:
///
/// Useful for duck-typing in Python and templated code.
AtomHandle GetHandle() const;
/// \brief Get unique identifier for atom
///
/// Get hash code that uniquely identifies every atom. The hash code is
/// identical for all atom views pointing to a given atom.
long GetHashCode() const;
bool operator==(const AtomHandle& ref) const;
bool operator!=(const AtomHandle& ref) const;
......
......@@ -115,7 +115,7 @@ mol::AtomViewList AtomView::GetBondPartners() const
mol::AtomViewList avl;
mol::BondHandleList::const_iterator i;
for (i=data_->bonds.begin();i!=data_->bonds.end();++i) {
if (i->GetFirst()!=*this) {
if (i->GetFirst().GetHandle()!=this->GetHandle()) {
avl.push_back(this->GetEntity().FindAtom(i->GetFirst()));
} else {
avl.push_back(this->GetEntity().FindAtom(i->GetSecond()));
......@@ -156,7 +156,13 @@ void AtomView::RemoveBondInternal(const BondHandle& bond)
data_->bonds.erase(i);
}
}
long AtomView::GetHashCode() const
{
this->CheckValidity();
return reinterpret_cast<long>(data_.get());
}
}} // ns
......@@ -69,6 +69,11 @@ public:
void Apply(EntityVisitor& visitor);
void Apply(EntityViewVisitor& visitor);
/// \brief get unique id
///
/// The unique id is the same for all AtomViews pointing to the same atom
/// view data.
long GetHashCode() const;
bool operator==(const AtomView& rhs) const;
bool operator!=(const AtomView& rhs) const;
protected:
......
......@@ -95,7 +95,7 @@ void CoordSource::CaptureInto(int pos)
e=atoms_.end(); i!=e; ++i) {
coords.push_back(i->GetPos());
}
if(pos<0 || pos>=GetFrameCount()) {
if(pos<0 || pos>=static_cast<int>(this->GetFrameCount())) {
this->AddFrame(coords);
} else {
this->InsertFrame(pos,coords);
......
......@@ -77,6 +77,17 @@ BOOST_AUTO_TEST_CASE(gen_full_view)
BOOST_CHECK_EQUAL(avl[1].GetBondCount(),2);
BOOST_CHECK_EQUAL(avl[2].GetBondCount(),2);
BOOST_CHECK_EQUAL(avl[3].GetBondCount(),1);
mol::AtomView av1=avl[0];
mol::AtomView av2=avl[1];
BOOST_CHECK(av1!=av2);
BOOST_CHECK(av1.GetHashCode()!=av2.GetHashCode());
BOOST_CHECK(av1.GetHandle().GetHashCode()!=av1.GetHashCode());
mol::AtomView av3=av1;
BOOST_CHECK(av1==av3);
BOOST_CHECK_EQUAL(av1.GetHashCode(), av3.GetHashCode());
}
BOOST_AUTO_TEST_SUITE_END()
......@@ -38,7 +38,6 @@
using namespace ost;
using namespace ost::seq;
using namespace boost::python;
namespace {
void (SequenceHandle::*attach_one)(const mol::EntityView&)=&SequenceHandle::AttachView;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment