diff --git a/modules/base/src/CMakeLists.txt b/modules/base/src/CMakeLists.txt index 5dbc9b808944558b318d3ce352d772934411aeb9..b30a8312b937c84425ce039f0332faed98e73c98 100644 --- a/modules/base/src/CMakeLists.txt +++ b/modules/base/src/CMakeLists.txt @@ -31,7 +31,7 @@ fixed_string.hh ) module(NAME base SOURCES ${OST_BASE_SOURCES} - HEADERS ${OST_BASE_HEADERS} + HEADERS generic_property_def.hh IN_DIR export_helper ${OST_BASE_HEADERS} DEPENDS_ON geom HEADER_OUTPUT_DIR ost) diff --git a/modules/mol/base/pymod/generic_property_def.hh b/modules/base/src/export_helper/generic_property_def.hh similarity index 89% rename from modules/mol/base/pymod/generic_property_def.hh rename to modules/base/src/export_helper/generic_property_def.hh index fbed012fbb98ee8a34fa1a97bb77aa82ed8ba7d7..4b8241be7ee0804eb107c941248dd91f38651040 100644 --- a/modules/mol/base/pymod/generic_property_def.hh +++ b/modules/base/src/export_helper/generic_property_def.hh @@ -24,8 +24,8 @@ Author: Marco Biasini */ -template <typename C> -void generic_prop_def(class_<C>& bp_class) +template <typename C, typename O> +void const_generic_prop_def(O& bp_class) { bool (C::*get_bool1)(const String&, bool) const=&C::GetGenericBoolProperty; bool (C::*get_bool2)(const String&) const=&C::GetGenericBoolProperty; @@ -40,6 +40,24 @@ void generic_prop_def(class_<C>& bp_class) String (C::*get_str2)(const String&) const=&C::GetGenericStringProperty; bp_class .def("HasGenericProperty", &C::HasGenericProperty) + .def("GetGenericPropertyStringRepresentation", + &C::GetGenericPropertyStringRepresentation) + .def("GetGenericBoolProperty", get_bool1) + .def("GetGenericBoolProperty", get_bool2) + .def("GetGenericFloatProperty", get_float1) + .def("GetGenericFloatProperty", get_float2) + .def("GetGenericIntProperty", get_int1) + .def("GetGenericIntProperty", get_int2) + .def("GetGenericStringProperty", get_str1) + .def("GetGenericStringProperty", get_str2) + ; +} + +template <typename C, typename O> +void generic_prop_def(O& bp_class) +{ + const_generic_prop_def<C, O>(bp_class); + bp_class .def("SetGenericBoolProperty", &C::SetGenericBoolProperty) .def("ClearGenericProperties", @@ -52,14 +70,6 @@ void generic_prop_def(class_<C>& bp_class) &C::SetGenericIntProperty) .def("SetGenericStringProperty", &C::SetGenericStringProperty) - .def("GetGenericBoolProperty", get_bool1) - .def("GetGenericBoolProperty", get_bool2) - .def("GetGenericFloatProperty", get_float1) - .def("GetGenericFloatProperty", get_float2) - .def("GetGenericIntProperty", get_int1) - .def("GetGenericIntProperty", get_int2) - .def("GetGenericStringProperty", get_str1) - .def("GetGenericStringProperty", get_str2) ; } diff --git a/modules/base/src/generic_property.hh b/modules/base/src/generic_property.hh index 66c9212ad5ef403a79eb39ee7a68f9974c7d6a3d..3fe6f037a70ee16c7b318a013579dd67a9359ad7 100644 --- a/modules/base/src/generic_property.hh +++ b/modules/base/src/generic_property.hh @@ -127,11 +127,11 @@ public: private: mutable PropertyMap* map_; }; - -/// \brief base class for the handler classes + template <typename H> -class TEMPLATE_EXPORT GenericPropertyContainer -{ +class TEMPLATE_EXPORT ConstGenericPropertyContainer { +protected: + template<typename T> T gp_get(const String& key) const { if(HasGenericProperty(key)) { @@ -150,19 +150,21 @@ class TEMPLATE_EXPORT GenericPropertyContainer } return def; } + GenericPropertyContainerImpl* GetImpl() + { + return static_cast<H*>(this)->GpImpl(); + } - + const GenericPropertyContainerImpl* GetImpl() const + { + return static_cast<const H*>(this)->GpImpl(); + } public: /// \brief checks existence of property bool HasGenericProperty(const String& key) const { - return GetImpl()->HasGenericProperty(key); + return this->GetImpl()->HasGenericProperty(key); } - - void ClearGenericProperties() - { - GetImpl()->ClearGenericProperties(); - } - + /// \brief returns a String representation of stored value /// /// returns the String representation of this property, or the empty String if @@ -174,50 +176,25 @@ public: { if(!HasGenericProperty(key)) return ""; std::ostringstream rep(""); - rep << GetImpl()->GenericProperty(key); + rep << this->GetImpl()->GenericProperty(key); return rep.str(); - } - - /// \brief sets String property - void SetGenericStringProperty(const String& key, const String& value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \brief sets floating point property - void SetGenericFloatProperty(const String& key, Real value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \brief sets integer property - void SetGenericIntProperty(const String& key, int value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \ brief sets boolean property - void SetGenericBoolProperty(const String& key, bool value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \brief returns String property, raises an exception if it does not exist - String GetGenericStringProperty(const String& key) const - { - return gp_get<String>(key); - } + } + /// \brief returns String property, raises an exception if it does not exist + String GetGenericStringProperty(const String& key) const + { + return this->gp_get<String>(key); + } /// \brief returns floating point property, raises an exception if it does /// not exist Real GetGenericFloatProperty(const String& key) const { if(HasGenericProperty(key)) { - GenericPropertyValue value=GetImpl()->GenericProperty(key); + GenericPropertyValue value=this->GetImpl()->GenericProperty(key); if (value.which()==1) { - return boost::get<Real>(GetImpl()->GenericProperty(key)); + return boost::get<Real>(this->GetImpl()->GenericProperty(key)); } else if (value.which()==2) { - return boost::get<int>(GetImpl()->GenericProperty(key)); + return boost::get<int>(this->GetImpl()->GenericProperty(key)); } std::ostringstream m(""); m << "property '" << key << "' is not numeric"; @@ -229,29 +206,30 @@ public: } } + /// \brief returns integer property, raises an exception if it does not exist int GetGenericIntProperty(const String& key) const { - return gp_get<int>(key); + return this->gp_get<int>(key); } /// \brief returns boolean property, raises an exception if it does not exist bool GetGenericBoolProperty(const String& key) const { - return gp_get<bool>(key); + return this->gp_get<bool>(key); } /// \brief returns String property, or the given default if it does not exist String GetGenericStringProperty(const String& key, const String& def) const { - return gp_get<String>(key,def); + return this->gp_get<String>(key,def); } /// \brief returns floating point property, or the given default if it does /// not exist Real GetGenericFloatProperty(const String& key, Real def) const { - if(HasGenericProperty(key)) { + if(this->HasGenericProperty(key)) { GenericPropertyValue value=GetImpl()->GenericProperty(key); if (value.which()==1) { return boost::get<Real>(GetImpl()->GenericProperty(key)); @@ -269,29 +247,55 @@ public: /// \brief returns integer property, or the given default if it does not exist int GetGenericIntProperty(const String& key, int def) const { - return gp_get<int>(key, def); + return this->gp_get<int>(key, def); } /// \brief returns boolean property, or the given default if it does not exist bool GetGenericBoolProperty(const String& key, bool def) const { - return gp_get<bool>(key, def); + return this->gp_get<bool>(key, def); } - + std::map<String,GenericPropertyValue> GetGenericPropertyMap() const { - return GetImpl()->GetGenericPropertyMap(); - } -protected: - GenericPropertyContainerImpl* GetImpl() + return this->GetImpl()->GetGenericPropertyMap(); + } +}; + +/// \brief base class for the handler classes +template <typename H> +class TEMPLATE_EXPORT GenericPropertyContainer : + public ConstGenericPropertyContainer<H> +{ +public: + void ClearGenericProperties() { - return static_cast<H*>(this)->GpImpl(); + this->GetImpl()->ClearGenericProperties(); } - const GenericPropertyContainerImpl* GetImpl() const + /// \brief sets String property + void SetGenericStringProperty(const String& key, const String& value) { - return static_cast<const H*>(this)->GpImpl(); - } + this->GetImpl()->GenericProperty(key)=value; + } + + /// \brief sets floating point property + void SetGenericFloatProperty(const String& key, Real value) + { + this->GetImpl()->GenericProperty(key)=value; + } + + /// \brief sets integer property + void SetGenericIntProperty(const String& key, int value) + { + this->GetImpl()->GenericProperty(key)=value; + } + + /// \ brief sets boolean property + void SetGenericBoolProperty(const String& key, bool value) + { + this->GetImpl()->GenericProperty(key)=value; + } }; diff --git a/modules/mol/base/pymod/export_atom.cc b/modules/mol/base/pymod/export_atom.cc index ccebbfb0adf0f9b7eb3aba0f10ba914ef68e987c..bb8c9fe31afea70a0ff111b82de719df2c186ab0 100644 --- a/modules/mol/base/pymod/export_atom.cc +++ b/modules/mol/base/pymod/export_atom.cc @@ -26,7 +26,8 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> + void export_Atom() { class_<AtomBase> atom_base("AtomBase", no_init); diff --git a/modules/mol/base/pymod/export_bond.cc b/modules/mol/base/pymod/export_bond.cc index e22adf98e8e26d4abfcf0ecdf1a63bce746f0107..ddfde472156fe0bdaaed309d93182cf42ff9963d 100644 --- a/modules/mol/base/pymod/export_bond.cc +++ b/modules/mol/base/pymod/export_bond.cc @@ -26,8 +26,8 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> + void export_Bond() { void (BondHandle::* apply1)(EntityVisitor&) = &BondHandle::Apply; diff --git a/modules/mol/base/pymod/export_chain.cc b/modules/mol/base/pymod/export_chain.cc index 71896935b6b8855c899df06d1638c38da540ab93..57e717ebac7e5a63c108eb0568c9815d09a7994e 100644 --- a/modules/mol/base/pymod/export_chain.cc +++ b/modules/mol/base/pymod/export_chain.cc @@ -24,9 +24,7 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" - -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> namespace { typedef void (ChainHandle::*RnumMethod)(const ResNum&); diff --git a/modules/mol/base/pymod/export_entity.cc b/modules/mol/base/pymod/export_entity.cc index a3624877abe4bc0c9636d3e312278170c5506bba..733c867d66e3e3231bda88d8ce9a542596ab2aae 100644 --- a/modules/mol/base/pymod/export_entity.cc +++ b/modules/mol/base/pymod/export_entity.cc @@ -28,7 +28,7 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> namespace { EntityHandle create1() { return CreateEntity(); } diff --git a/modules/mol/base/pymod/export_residue.cc b/modules/mol/base/pymod/export_residue.cc index 1ff735cf642d3ca604a54d3dd5c45dca7517b3da..66214c7d4b5050d7ba0ce4697a56a1ffad4fb6b1 100644 --- a/modules/mol/base/pymod/export_residue.cc +++ b/modules/mol/base/pymod/export_residue.cc @@ -25,9 +25,8 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> namespace { typedef EntityView (ResidueHandle::*QueryMethod)(const Query&, uint) const; @@ -118,9 +117,7 @@ void export_Residue() return_value_policy<copy_const_reference>())) .add_property("qualified_name", &ResidueBase::GetQualifiedName) ; - generic_prop_def(residue_base); - - generic_prop_def(residue_base); + generic_prop_def<ResidueBase>(residue_base); class_<ResidueHandle, bases<ResidueBase> >("ResidueHandle", init<>()) .def("GetChain",&ResidueHandle::GetChain) diff --git a/modules/mol/base/src/atom_base.hh b/modules/mol/base/src/atom_base.hh index 3b10fb8ca241ff4aa5c452d0b86a63c2bb848127..71ec8dbe88fe3b46e0f9c65570071c9c16d3b5c8 100644 --- a/modules/mol/base/src/atom_base.hh +++ b/modules/mol/base/src/atom_base.hh @@ -49,7 +49,7 @@ public: AtomBase(); AtomBase(const impl::AtomImplPtr& impl); public: - friend class GenericPropertyContainer<AtomBase>; + friend class ConstGenericPropertyContainer<AtomBase>; ///\brief Get atom name. /// /// In Python the atom name may also be accesssed over the property \c Name diff --git a/modules/mol/base/src/bond_handle.hh b/modules/mol/base/src/bond_handle.hh index b23ca06792604dc2af606e5fecc183edc72c729f..114e033a65ba16436c2c2f601a25aab053506393 100644 --- a/modules/mol/base/src/bond_handle.hh +++ b/modules/mol/base/src/bond_handle.hh @@ -34,7 +34,7 @@ namespace ost { namespace mol { class DLLEXPORT_OST_MOL BondHandle: public GenericPropertyContainer<BondHandle> { public: - friend class GenericPropertyContainer<BondHandle>; + friend class ConstGenericPropertyContainer<BondHandle>; /// necessary dummy ctor, creates invalid handle BondHandle(); /// ctor for internal use, in public interface for convenience purposes diff --git a/modules/mol/base/src/chain_base.hh b/modules/mol/base/src/chain_base.hh index 4e27e79edb2cfae2824e7dd0a65cc5595d04a59d..c8de6551ba637115f10816ff0aa45fb136c994e3 100644 --- a/modules/mol/base/src/chain_base.hh +++ b/modules/mol/base/src/chain_base.hh @@ -42,7 +42,7 @@ public: // constructors ChainBase(); ChainBase(const impl::ChainImplPtr& impl); public: - friend class GenericPropertyContainer<ChainBase>; + friend class ConstGenericPropertyContainer<ChainBase>; String GetName() const; /// \name Handle validity //@{ diff --git a/modules/mol/base/src/entity_base.hh b/modules/mol/base/src/entity_base.hh index 9cb68a0c8f6d4dd01bdc34702bf9e6419ae786b5..05228c56febf0ed3a3b94490553d6288948e0361 100644 --- a/modules/mol/base/src/entity_base.hh +++ b/modules/mol/base/src/entity_base.hh @@ -30,7 +30,7 @@ namespace ost { namespace mol { class DLLEXPORT_OST_MOL EntityBase: public GenericPropertyContainer<EntityBase> { public: - friend class GenericPropertyContainer<EntityBase>; + friend class ConstGenericPropertyContainer<EntityBase>; EntityBase(const impl::EntityImplPtr& impl); EntityBase(); diff --git a/modules/mol/base/src/residue_base.hh b/modules/mol/base/src/residue_base.hh index da5cd052588bfe3ea5c639e6276071cda0a0eb0b..0aabe77a38e08bb0c8c17144148102223e68b50d 100644 --- a/modules/mol/base/src/residue_base.hh +++ b/modules/mol/base/src/residue_base.hh @@ -63,7 +63,7 @@ public: ResidueBase(const impl::ResidueImplPtr& impl); ResidueBase(const ResidueBase& rhs); public: - friend class GenericPropertyContainer<ResidueBase>; + friend class ConstGenericPropertyContainer<ResidueBase>; /// \brief return residue number const ResNum& GetNumber() const; diff --git a/modules/seq/base/pymod/export_sequence.cc b/modules/seq/base/pymod/export_sequence.cc index ce05be244be8609cf8e58f3e087a2f38085b659d..60947f4cbdc9201118c7cf1cb56e84e321d4d735 100644 --- a/modules/seq/base/pymod/export_sequence.cc +++ b/modules/seq/base/pymod/export_sequence.cc @@ -22,6 +22,8 @@ #include <boost/python/suite/indexing/vector_indexing_suite.hpp> using namespace boost::python; +#include <ost/generic_property.hh> +#include <ost/export_helper/generic_property_def.hh> #include <ost/info/info.hh> #include <ost/mol/mol.hh> #include <ost/seq/sequence_handle.hh> @@ -145,46 +147,54 @@ RevRegionRangeIter iter_range3(AlignedRegion& aln_region) return RevRegionRangeIter(aln_region.begin(), aln_region.end()); } -} - -void export_sequence() +template <typename C, typename O> +void const_seq_handle_def(O& bp_class) { - class_<ConstSequenceHandle>("ConstSequenceHandle", init<>()) - .def("GetResidueIndex", &ConstSequenceHandle::GetResidueIndex) - .def("GetPos", &ConstSequenceHandle::GetPos) - .def("GetLength", &ConstSequenceHandle::GetLength) - .def("GetResidue", &ConstSequenceHandle::GetResidue) - .def("GetOneLetterCode", &ConstSequenceHandle::GetOneLetterCode) - .def("__getitem__", &ConstSequenceHandle::GetOneLetterCode) - .def("GetSequenceOffset", &ConstSequenceHandle::GetSequenceOffset) - .def("Copy", &ConstSequenceHandle::Copy) - .def("GetFirstNonGap", &ConstSequenceHandle::GetFirstNonGap) - .def("GetLastNonGap", &ConstSequenceHandle::GetLastNonGap) - .add_property("first_non_gap", &SequenceHandle::GetFirstNonGap) - .add_property("last_non_gap", &SequenceHandle::GetLastNonGap) - .def("GetAttachedView", &ConstSequenceHandle::GetAttachedView) - .def("GetGaplessString", &ConstSequenceHandle::GetGaplessString) - .def("GetString", &ConstSequenceHandle::GetString, + bp_class + .def("GetResidueIndex", &C::GetResidueIndex) + .def("GetPos", &C::GetPos) + .def("GetLength", &C::GetLength) + .def("GetResidue", &C::GetResidue) + .def("GetOneLetterCode", &C::GetOneLetterCode) + .def("__getitem__", &C::GetOneLetterCode) + .def("GetSequenceOffset", &C::GetSequenceOffset) + .def("Copy", &C::Copy) + .def("GetFirstNonGap", &C::GetFirstNonGap) + .def("GetLastNonGap", &C::GetLastNonGap) + .add_property("first_non_gap", &C::GetFirstNonGap) + .add_property("last_non_gap", &C::GetLastNonGap) + .def("GetAttachedView", &C::GetAttachedView) + .def("GetGaplessString", &C::GetGaplessString) + .def("GetString", &C::GetString, return_value_policy<copy_const_reference>()) - .def("GetName", &ConstSequenceHandle::GetName, + .def("GetName", &C::GetName, return_value_policy<copy_const_reference>()) - .def("HasAttachedView", &ConstSequenceHandle::HasAttachedView) - .def("__len__", &SequenceHandle::GetLength) - .add_property("length", &SequenceHandle::GetLength) - .add_property("attached_view", &ConstSequenceHandle::GetAttachedView) + .def("HasAttachedView", &C::HasAttachedView) + .def("__len__", &C::GetLength) + .add_property("length", &C::GetLength) + .add_property("attached_view", &C::GetAttachedView) .add_property("name", - make_function(&ConstSequenceHandle::GetName, + make_function(&C::GetName, return_value_policy<copy_const_reference>())) - .add_property("sequence_offset", &ConstSequenceHandle::GetSequenceOffset) - .add_property("gapless_string", &ConstSequenceHandle::GetGaplessString) + .add_property("sequence_offset", &C::GetSequenceOffset) + .add_property("gapless_string", &C::GetGaplessString) .add_property("string", - make_function(&ConstSequenceHandle::GetString, + make_function(&C::GetString, return_value_policy<copy_const_reference>())) - .def("__str__", &ConstSequenceHandle::GetString, + .def("__str__", &C::GetString, return_value_policy<copy_const_reference>()) ; +} - class_<SequenceHandle, bases<ConstSequenceHandle> >("SequenceHandle", init<>()) +} + +void export_sequence() +{ + class_<ConstSequenceHandle> const_seq("ConstSequenceHandle", init<>()); + const_seq_handle_def<ConstSequenceHandle>(const_seq); + const_generic_prop_def<ConstSequenceHandle>(const_seq); + class_<SequenceHandle> seq_handle("SequenceHandle", init<>()); + seq_handle .def("SetSequenceOffset", &SequenceHandle::SetSequenceOffset) .def("AttachView", attach_one) .def("AttachView", attach_two) @@ -201,6 +211,10 @@ void export_sequence() .add_property("sequence_offset", &SequenceHandle::GetSequenceOffset, &SequenceHandle::SetSequenceOffset) ; + const_seq_handle_def<SequenceHandle>(seq_handle); + generic_prop_def<SequenceHandle>(seq_handle); + implicitly_convertible<SequenceHandle, ConstSequenceHandle>(); + def("CreateSequence", &CreateSequence); /*class_<SequenceHandleList>("SequenceHandleList", init<>()) .def(vector_indexing_suite<SequenceHandleList>()) diff --git a/modules/seq/base/src/impl/sequence_impl.hh b/modules/seq/base/src/impl/sequence_impl.hh index 033bf50bf5f331a419b23068b6997d6cdc53c3eb..6ac241970d7836f6de76ac61ac90602761b3d12d 100644 --- a/modules/seq/base/src/impl/sequence_impl.hh +++ b/modules/seq/base/src/impl/sequence_impl.hh @@ -26,7 +26,7 @@ #include <list> #include <boost/shared_ptr.hpp> - +#include <ost/generic_property.hh> #include <ost/info/info_fw.hh> #include <ost/mol/residue_prop.hh> #include <ost/mol/entity_view.hh> @@ -43,7 +43,7 @@ class SequenceImpl; typedef boost::shared_ptr<SequenceImpl> SequenceImplPtr; /// \internal -class DLLEXPORT_OST_SEQ SequenceImpl { +class DLLEXPORT_OST_SEQ SequenceImpl : public GenericPropertyContainerImpl { public: /// \brief Construct new sequence object from sequence_string. static SequenceImplPtr FromString(const String& seq_name, diff --git a/modules/seq/base/src/sequence_handle.cc b/modules/seq/base/src/sequence_handle.cc index d24fff1ae4cf4543f7b5bbe81e1e1505e833f4c9..60216f9ae1cd72ba584a8d036613e219d9f33326 100644 --- a/modules/seq/base/src/sequence_handle.cc +++ b/modules/seq/base/src/sequence_handle.cc @@ -32,7 +32,7 @@ ConstSequenceHandle::ConstSequenceHandle() { } SequenceHandle::SequenceHandle(const impl::SequenceImplPtr& impl): - ConstSequenceHandle(impl) + impl_(impl) { } ConstSequenceHandle::ConstSequenceHandle(const impl::SequenceImplPtr& impl): @@ -75,10 +75,6 @@ SequenceHandle CreateSequence(const String& name, const String& seq) return SequenceHandle(impl::SequenceImpl::FromString(name, seq)); } -SequenceHandle::SequenceHandle(): - ConstSequenceHandle() -{ } - String ConstSequenceHandle::GetGaplessString() const { @@ -175,8 +171,6 @@ void SequenceHandle::SetName(const String& name) return Impl()->SetName(name); } - - void SequenceHandle::SetString(const String& seq) { this->CheckValidity(); @@ -228,4 +222,150 @@ std::ostream& operator<<(std::ostream& os, const ConstSequenceHandle& sequence) return os; } +bool SequenceHandle::operator==(const SequenceHandle& rhs) const +{ + return impl_==rhs.impl_; +} + +bool SequenceHandle::operator!=(const SequenceHandle& rhs) const +{ + return impl_!=rhs.impl_; +} + + +void SequenceHandle::CheckValidity() const +{ + if (!impl_) { + throw InvalidHandle(); + } +} + +bool SequenceHandle::IsValid() const +{ + return impl_.get()!=0; +} + +impl::SequenceImplPtr& SequenceHandle::Impl() const +{ + return impl_; +} + + +SequenceHandle::SequenceHandle(): + impl_() +{ } + + +String SequenceHandle::GetGaplessString() const +{ + this->CheckValidity(); + return Impl()->GetGaplessString(); +} + +int SequenceHandle::GetSequenceOffset() const +{ + this->CheckValidity(); + return Impl()->GetSequenceOffset(); +} + +SequenceHandle::operator ConstSequenceHandle() const +{ + return ConstSequenceHandle(impl_); +} + +int SequenceHandle::GetLength() const +{ + this->CheckValidity(); + return Impl()->GetLength(); +} + + +char SequenceHandle::GetOneLetterCode(int position) const +{ + this->CheckValidity(); + return Impl()->GetOneLetterCode(position); +} + +mol::ResidueView SequenceHandle::GetResidue(int position) const +{ + this->CheckValidity(); + return Impl()->GetResidue(position); +} + +mol::EntityView SequenceHandle::GetAttachedView() const +{ + this->CheckValidity(); + return Impl()->GetAttachedView(); +} + +SequenceHandle SequenceHandle::Copy() const +{ + this->CheckValidity(); + return Impl()->Copy(); +} + +bool SequenceHandle::HasAttachedView() const +{ + this->CheckValidity(); + return Impl()->HasAttachedView(); +} + + +int SequenceHandle::GetResidueIndex(int pos) const +{ + this->CheckValidity(); + return Impl()->GetResidueIndex(pos); +} + +int SequenceHandle::GetPos(int residue_index) const +{ + this->CheckValidity(); + return Impl()->GetPos(residue_index); +} + + +int SequenceHandle::GetFirstNonGap() const +{ + this->CheckValidity(); + return Impl()->GetFirstNonGap(); +} + + +int SequenceHandle::GetLastNonGap() const +{ + this->CheckValidity(); + return Impl()->GetLastNonGap(); +} + +const String& SequenceHandle::GetName() const +{ + this->CheckValidity(); + return Impl()->GetName(); +} + +const String& SequenceHandle::GetString() const +{ + this->CheckValidity(); + return Impl()->GetString(); +} + +GenericPropertyContainerImpl* ConstSequenceHandle::GpImpl() +{ + return Impl().get(); +} + +const GenericPropertyContainerImpl* ConstSequenceHandle::GpImpl() const +{ + return Impl().get(); +} + +GenericPropertyContainerImpl* SequenceHandle::GpImpl() +{ + return Impl().get(); +} + +const GenericPropertyContainerImpl* SequenceHandle::GpImpl() const +{ + return Impl().get(); +} }} diff --git a/modules/seq/base/src/sequence_handle.hh b/modules/seq/base/src/sequence_handle.hh index ba9b2eabe5308a06c0e24f6cf35a58f141d7e9e9..c76c3298c7420734e70713320ec3fde480fb037d 100644 --- a/modules/seq/base/src/sequence_handle.hh +++ b/modules/seq/base/src/sequence_handle.hh @@ -24,6 +24,7 @@ */ #include <ost/base.hh> +#include <ost/generic_property.hh> #include <ost/info/info_fw.hh> #include <ost/seq/module_config.hh> @@ -41,8 +42,10 @@ class AlignmentHandle; /// /// The ConstSequenceHandle provides all read-only methods of the /// \ref SequenceHandle "sequence handle". -class DLLEXPORT_OST_SEQ ConstSequenceHandle { +class DLLEXPORT_OST_SEQ ConstSequenceHandle : + public ConstGenericPropertyContainer<ConstSequenceHandle> { public: + friend class ConstGenericPropertyContainer<ConstSequenceHandle>; friend class AlignmentHandle; friend class ConstSequenceList; friend class SequenceList; @@ -116,14 +119,15 @@ public: /// \brief whether the sequence is valid bool IsValid() const; /// \internal +protected: + GenericPropertyContainerImpl* GpImpl(); + + const GenericPropertyContainerImpl* GpImpl() const; public: ConstSequenceHandle(const impl::SequenceImplPtr& impl); impl::SequenceImplPtr& Impl() const; -protected: - void CheckValidity() const; - - private: + void CheckValidity() const; mutable impl::SequenceImplPtr impl_; }; @@ -149,12 +153,80 @@ private: /// /// Sequences IO is dealt with in the sequence module. For more information, /// consult \ref module_seq "this page". -class DLLEXPORT_OST_SEQ SequenceHandle : public ConstSequenceHandle { +class DLLEXPORT_OST_SEQ SequenceHandle : + public GenericPropertyContainer<SequenceHandle> { public: - friend class ConstSequenceHandle; + friend class GenericPropertyContainer<SequenceHandle>; friend class SequenceList; + friend class AlignmentHandle; + friend class ConstSequenceList; + /// \brief Get residue index corresponding to given sequence position + /// \param pos zero-based index + /// \throws out_of_range if pos is not in [0, length-1]. + int GetResidueIndex(int pos) const; + + /// \brief Get zero-based index for given residue number. + /// \throws out_of_range, if number is not included in sequence. + int GetPos(int residue_index) const; + + /// \brief Get position of first non-gap character in sequence + int GetFirstNonGap() const; + + /// \brief Get position of last non-gap character in sequence + int GetLastNonGap() const; + + /// \brief Get name of sequence + /// + /// \sa SequenceHandle::GetName() + const String& GetName() const; + + /// \brief get sequence as a string, including all the gaps + /// + /// \sa GetGaplessString() + const String& GetString() const; + + /// \brief Get sequence as string ignoring gaps + String GetGaplessString() const; + + /// \brief Get sequence offset from N-terminus + /// + /// \sa SequenceHandle::SetSequenceOffset + int GetSequenceOffset() const; + + /// \brief Get lenght of sequence, including gaps. + int GetLength() const; + + /// \brief get one letter code of residue at position + char GetOneLetterCode(int position) const; + + /// \brief get residue at position + /// + /// will return the residue view at the given sequence position or an invalid + /// residue view when no view is attached, the index is out of bounds or the + /// position contains a gap. + mol::ResidueView GetResidue(int position) const; + + /// \brief get attached view. may be an invalid entity view + /// \sa SequenceHandle::AttachView(const mol::EntityView&, const String&) + mol::EntityView GetAttachedView() const; + + /// \brief create copy sequence + /// The newly created sequence has the same attached view. + SequenceHandle Copy() const; + + /// \brief whether the sequence has an attached view + /// + /// \sa SequenceHandle::AttachView(const mol::EntityView&, const String&) + bool HasAttachedView() const; + + bool operator==(const SequenceHandle& rhs) const; + bool operator!=(const SequenceHandle& rhs) const; + + /// \brief whether the sequence is valid + bool IsValid() const; + /// \brief create invalid sequence handle /// /// \sa IsValid() @@ -178,7 +250,7 @@ public: /// \throw IntegrityError when the view contains more than one chain void AttachView(const mol::EntityView& view); - + operator ConstSequenceHandle() const; /// \brief attach entity view to sequence /// /// The sequence is mapped onto the chain with given name @@ -186,6 +258,15 @@ public: /// \internal SequenceHandle(const impl::SequenceImplPtr& impl); + + impl::SequenceImplPtr& Impl() const; + + GenericPropertyContainerImpl* GpImpl(); + + const GenericPropertyContainerImpl* GpImpl() const; +private: + void CheckValidity() const; + mutable impl::SequenceImplPtr impl_; }; SequenceHandle DLLEXPORT_OST_SEQ CreateSequence(const String& name,