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

teach stream operators to deal with invalid handles

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1963 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 1d33c323
No related branches found
No related tags found
No related merge requests found
......@@ -126,10 +126,13 @@ long AtomBase::GetHashCode() const
return reinterpret_cast<long>(Impl().get());
}
std::ostream& operator<<(std::ostream& os,
const AtomBase& atom)
std::ostream& operator<<(std::ostream& os, const AtomBase& atom)
{
os << atom.GetQualifiedName();
if (atom.IsValid()) {
os << atom.GetQualifiedName();
} else {
os << "invalid atom";
}
return os;
}
......
......@@ -49,7 +49,7 @@ ChainBase::operator bool() const {
}
bool ChainBase::IsValid() const {
return impl_;
return impl_.get()!=0;
}
void ChainBase::CheckValidity() const {
......@@ -57,9 +57,13 @@ void ChainBase::CheckValidity() const {
throw InvalidHandle();
}
DLLEXPORT_OST_MOL std::ostream& operator<<(std::ostream& os,
const ChainBase& chain) {
os << chain.GetName();
std::ostream& operator<<(std::ostream& os, const ChainBase& chain)
{
if (chain.IsValid()) {
os << chain.GetName();
} else {
os << "invalid chain";
}
return os;
}
......
......@@ -47,11 +47,11 @@ const GenericPropertyContainerImpl* EntityBase::GpImpl() const
}
bool EntityBase::IsValid() const {
return Impl();
return impl_.get()!=0;
}
EntityBase::operator bool() const {
return impl_;
return impl_.get()!=0;
}
void EntityBase::CheckValidity() const {
......@@ -69,9 +69,14 @@ void EntityBase::SetName(const String& ent_name) {
impl_->SetName(ent_name);
}
DLLEXPORT_OST_MOL std::ostream& operator<<(std::ostream& os,
const EntityBase& ent) {
DLLEXPORT_OST_MOL std::ostream& operator<<(std::ostream& os,
const EntityBase& ent) {
if (ent.IsValid()) {
os << "entity";
} else {
os << "invalid";
}
return os;
}
}} //ns
......
......@@ -70,7 +70,7 @@ ResidueBase::operator bool() const {
}
bool ResidueBase::IsValid() const {
return impl_;
return impl_.get()!=0;
}
bool ResidueBase::IsPeptideLinking() const
......@@ -141,9 +141,12 @@ void ResidueBase::CheckValidity() const
throw InvalidHandle();
}
DLLEXPORT_OST_MOL std::ostream& operator<<(std::ostream& os,
const ResidueBase& residue) {
os << residue.GetQualifiedName();
std::ostream& operator<<(std::ostream& os, const ResidueBase& residue) {
if (residue.IsValid()) {
os << residue.GetQualifiedName();
} else {
os << "invalid residue";
}
return os;
}
......
......@@ -219,7 +219,12 @@ SequenceHandle SequenceFromInfo(info::InfoGroup& group)
std::ostream& operator<<(std::ostream& os, const ConstSequenceHandle& sequence)
{
os << sequence.GetName() << ": " << sequence.GetString();
if (sequence.IsValid()) {
os << sequence.GetName() << ": " << sequence.GetString();
} else {
os << "invalid";
}
return os;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment