diff --git a/modules/io/doc/mmcif.rst b/modules/io/doc/mmcif.rst index ed3ebb395136b95d00b27d1694de8f2e7d91c358..240c7a6ab52714c8f3f2b5beb1210a88c648e498 100644 --- a/modules/io/doc/mmcif.rst +++ b/modules/io/doc/mmcif.rst @@ -993,6 +993,7 @@ of the annotation available. :type i: :class:`int` :return: Date the PDB revision took place. Expected format 'yyyy-mm-dd'. :rtype: :class:`str` + :raises: Exception if *i* out of bounds. .. method:: GetNum(i) @@ -1000,6 +1001,7 @@ of the annotation available. :type i: :class:`int` :return: Unique identifier of revision (assigned in increasing order) :rtype: :class:`int` + :raises: Exception if *i* out of bounds. .. method:: GetStatus(i) @@ -1007,10 +1009,11 @@ of the annotation available. :type i: :class:`int` :return: The status of this revision. :rtype: :class:`str` + :raises: Exception if *i* out of bounds. .. method:: GetLastDate() - :return: Date of the latest revision. + :return: Date of the latest revision ('?' if no revision set). :rtype: :class:`str` .. method:: SetDateOriginal(date) diff --git a/modules/io/src/mol/mmcif_info.hh b/modules/io/src/mol/mmcif_info.hh index 6f9b3ed317c5bed68c27c0ebc1569420fbbfb987..5fc9d576bb27ab05c8a59b8ec72cc3e1043fdc3f 100644 --- a/modules/io/src/mol/mmcif_info.hh +++ b/modules/io/src/mol/mmcif_info.hh @@ -728,24 +728,27 @@ public: /// /// \param i position in list /// \return date - String GetDate(size_t i) const { return date_[i]; } + String GetDate(size_t i) const { return date_.at(i); } /// \brief Get revision num by index in list. /// /// \param i position in list /// \return num - int GetNum(size_t i) const { return num_[i]; } + int GetNum(size_t i) const { return num_.at(i); } /// \brief Get revision status by index in list. /// /// \param i position in list /// \return status - String GetStatus(size_t i) const { return status_[i]; } + String GetStatus(size_t i) const { return status_.at(i); } /// \brief Get date of last revision. /// /// \return date - String GetLastDate() const { return date_.back(); } + String GetLastDate() const { + if (date_.empty()) return "?"; + else return date_.back(); + } /// \brief Get the index of the full release revision. /// diff --git a/modules/io/tests/test_mmcif_info.cc b/modules/io/tests/test_mmcif_info.cc index 6c49768d2eb0806473cefe958c7b5d9f9482e79b..2eb111336ddca9de0379430b91ba5b9906dfad9d 100644 --- a/modules/io/tests/test_mmcif_info.cc +++ b/modules/io/tests/test_mmcif_info.cc @@ -225,6 +225,12 @@ BOOST_AUTO_TEST_CASE(mmcif_info_revisions) MMCifInfoRevisions rev = MMCifInfoRevisions(); BOOST_CHECK(rev.GetDateOriginal() == "?"); + BOOST_CHECK(rev.GetFirstRelease() == 0); + BOOST_CHECK(rev.GetSize() == 0); + BOOST_CHECK(rev.GetLastDate() == "?"); + BOOST_CHECK_THROW(rev.GetDate(0), std::out_of_range); + BOOST_CHECK_THROW(rev.GetNum(0), std::out_of_range); + BOOST_CHECK_THROW(rev.GetStatus(0), std::out_of_range); rev.SetDateOriginal("2012-05-04"); rev.AddRevision(1, "2012-05-04", "in preparation"); @@ -239,6 +245,9 @@ BOOST_AUTO_TEST_CASE(mmcif_info_revisions) BOOST_CHECK(rev.GetFirstRelease() == 2); BOOST_CHECK(rev.GetNum(1) == 2); BOOST_CHECK(rev.GetStatus(1) == "full release"); + BOOST_CHECK_THROW(rev.GetDate(2), std::out_of_range); + BOOST_CHECK_THROW(rev.GetNum(2), std::out_of_range); + BOOST_CHECK_THROW(rev.GetStatus(2), std::out_of_range); BOOST_TEST_MESSAGE(" done."); }