Skip to content

Commit

Permalink
Embrace std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed May 13, 2021
1 parent 7b8e358 commit d786abb
Show file tree
Hide file tree
Showing 294 changed files with 1,422 additions and 1,442 deletions.
2 changes: 1 addition & 1 deletion source/auto_generated_file_list.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,7 @@ set(
set(
TESTSOURCES_CT_COMMON_CATH_COMMON_STRING
ct_common/cath/common/string/booled_to_string_test.cpp
ct_common/cath/common/string/cath_to_string_test.cpp
ct_common/cath/common/string/string_parse_tools_test.cpp
ct_common/cath/common/string/sub_string_parser_test.cpp
)
Expand Down Expand Up @@ -1924,7 +1925,6 @@ set(
${TESTSOURCES_CT_COMMON_CATH_COMMON_STRING}
ct_common/cath/common/temp_check_offset_1_test.cpp
${TESTSOURCES_CT_COMMON_CATH_COMMON_TUPLE}
ct_common/cath/common/tuple_insertion_operator_test.cpp
ct_common/cath/common/type_to_string_test.cpp
${TESTSOURCES_CT_COMMON_CATH_COMMON_TYPE_TRAITS}
)
Expand Down
7 changes: 3 additions & 4 deletions source/ct_biocore/cath/biocore/biocore_type_aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
#define _CATH_TOOLS_SOURCE_CT_BIOCORE_CATH_BIOCORE_BIOCORE_TYPE_ALIASES_HPP

#include <map>
#include <optional>
#include <set>
#include <vector>

#include <boost/optional/optional_fwd.hpp>

// clang-format off
namespace cath { class chain_label; }
namespace cath { class residue_id; }
Expand All @@ -42,10 +41,10 @@ namespace cath {
using chain_label_set = ::std::set<chain_label>;

/// \brief TODOCUMENT
using chain_label_opt = ::boost::optional<chain_label>;
using chain_label_opt = ::std::optional<chain_label>;

/// \brief TODOCUMENT
using residue_name_opt = ::boost::optional<residue_name>;
using residue_name_opt = ::std::optional<residue_name>;

/// \brief TODOCUMENT
using residue_name_set = ::std::set<residue_name>;
Expand Down
19 changes: 10 additions & 9 deletions source/ct_biocore/cath/biocore/residue_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@

#include "residue_id.hpp"

#include <iostream>
#include <optional>
#include <string>

#include <boost/algorithm/cxx11/any_of.hpp>

#include "cath/common/cpp14/cbegin_cend.hpp"
#include "cath/common/exception/invalid_argument_exception.hpp"

#include <iostream>
#include <string>
#include "cath/common/optional/make_optional_if.hpp"

using namespace ::cath;
using namespace ::cath::common;

using ::boost::algorithm::any_of;
using ::boost::make_optional;
using ::boost::none;
using ::std::istream;
using ::std::nullopt;
using ::std::ostream;
using ::std::string;

Expand Down Expand Up @@ -114,18 +115,18 @@ chain_label_residue_id_vec_map cath::get_residue_id_by_chain_label(const residue
}

/// \brief Return a chain label that is used consistently in all of the specified residue_ids
/// or none otherwise
/// or nullopt otherwise
///
/// Returns none if `prm_residue_ids.empty()`
/// Returns nullopt if `prm_residue_ids.empty()`
///
/// \relates residue_id
chain_label_opt cath::consistent_chain_label(const residue_id_vec &prm_residue_ids ///< The vector of residue_ids to query
) {
if ( prm_residue_ids.empty() ) {
return none;
return nullopt;
}
const auto &front_chain_label = prm_residue_ids.front().get_chain_label();
return make_optional(
return make_optional_if(
all_of(
next( common::cbegin( prm_residue_ids ) ),
common::cend( prm_residue_ids ),
Expand Down
4 changes: 3 additions & 1 deletion source/ct_biocore/cath/biocore/residue_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "residue_name.hpp"

#include <optional>

#include <boost/algorithm/string/classification.hpp>
#include <boost/lexical_cast.hpp>

Expand All @@ -31,8 +33,8 @@ using namespace ::cath::common;
using ::boost::algorithm::is_alnum;
using ::boost::algorithm::is_digit;
using ::boost::lexical_cast;
using ::boost::optional;
using ::std::istream;
using ::std::optional;
using ::std::ostream;
using ::std::string;

Expand Down
11 changes: 6 additions & 5 deletions source/ct_biocore/cath/biocore/residue_name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#ifndef _CATH_TOOLS_SOURCE_CT_BIOCORE_CATH_BIOCORE_RESIDUE_NAME_HPP
#define _CATH_TOOLS_SOURCE_CT_BIOCORE_CATH_BIOCORE_RESIDUE_NAME_HPP

#include <optional>

#include <boost/operators.hpp>
#include <boost/optional.hpp>

namespace cath {

Expand All @@ -35,7 +36,7 @@ namespace cath {
int res_num = 0;

/// \brief The (optional insert code)
boost::optional<char> insert;
::std::optional<char> insert;

/// \brief Whether this is a null residue
bool is_null_residue_name = true;
Expand All @@ -51,7 +52,7 @@ namespace cath {

const bool & is_null() const;
const int & residue_number() const;
const boost::optional<char> & opt_insert() const;
const ::std::optional<char> & opt_insert() const;
};


Expand All @@ -72,8 +73,8 @@ namespace cath {

int residue_number_or_value_if_null(const residue_name &,
const int &);
boost::optional<char> opt_insert_or_value_if_null(const residue_name &,
const boost::optional<char> &);
::std::optional<char> opt_insert_or_value_if_null(const residue_name &,
const ::std::optional<char> &);
bool has_insert(const residue_name &);
bool has_insert_or_value_if_null(const residue_name &,
const bool &);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ using namespace ::cath::file;
using namespace ::cath::opts;
using namespace ::cath::sup;

using ::boost::none;
using ::std::filesystem::path;
using ::std::nullopt;
using ::std::string;

/// \brief The name of the program that uses this executable_options
Expand Down Expand Up @@ -89,7 +89,7 @@ str_opt cath_assign_domains_options::do_get_error_or_help_string() const {
return "Please specify a superfamily of domain file"s;
}

return none;
return nullopt;
}

/// \brief Get a string to prepend to the standard help
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <boost/algorithm/cxx11/all_of.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/optional.hpp>

#include "cath/acquirer/pdbs_acquirer/file_list_pdbs_acquirer.hpp"
#include "cath/acquirer/pdbs_acquirer/istream_pdbs_acquirer.hpp"
Expand All @@ -39,11 +38,11 @@ using namespace ::std;

using ::boost::algorithm::all_of;
using ::boost::algorithm::join;
using ::boost::none;
using ::boost::program_options::options_description;
using ::boost::program_options::value;
using ::boost::program_options::variables_map;
using ::std::filesystem::path;
using ::std::nullopt;

/// \brief The long option specifying the SVM-light RBF model file
const string cath_assign_domains_options_block::PO_SVMLIGHT_RBF_FILE( "svmlight-rbf-file" );
Expand Down Expand Up @@ -104,7 +103,7 @@ str_opt cath_assign_domains_options_block::do_invalid_string(const variables_map
if ( ! all_of( forbidden_nodes, is_valid_cath_node_id{} ) ) {
return "Forbidden nodes list " + join( forbidden_nodes, ", ") + " is not a list of valid CATH nodes";
}
return none;
return nullopt;
}

/// \brief Return all options names for this block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ using namespace ::cath::clust;
using namespace ::cath::common;
using namespace ::cath::opts;

using ::boost::make_optional;
using ::std::ifstream;
using ::std::istream;
using ::std::make_optional;
using ::std::ostream;

/// \brief Perform clustering according to the specified arguments strings with the specified i/o streams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
using namespace ::cath;
using namespace ::cath::clust;

using ::boost::none;
using ::boost::program_options::positional_options_description;
using ::std::nullopt;
using ::std::string;

/// The name of the program that uses this executable_options
Expand Down Expand Up @@ -62,7 +62,7 @@ str_opt cath_cluster_options::do_get_error_or_help_string() const {
+ " output when generating more than one level of clustering";
}

return none;
return nullopt;
}

/// \brief Get a string to prepend to the standard help
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ using namespace ::cath::clust;
using namespace ::cath::common;
using namespace ::cath::opts;

using ::boost::none;
using ::boost::program_options::options_description;
using ::boost::program_options::value;
using ::boost::program_options::variables_map;
using ::std::nullopt;
using ::std::string;
using ::std::unique_ptr;

Expand Down Expand Up @@ -70,10 +70,10 @@ void cath_cluster_clustering_options_block::do_add_visible_options_to_descriptio
}

/// \brief Generate a description of any problem that makes the specified cath_cluster_clustering_options_block invalid
/// or none otherwise
/// or nullopt otherwise
str_opt cath_cluster_clustering_options_block::do_invalid_string(const variables_map &/*prm_variables_map*/ ///< The variables map, which options_blocks can use to determine which options were specified, defaulted etc
) const {
return none;
return nullopt;
}

/// \brief Return all options names for this block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ using namespace ::cath::clust;
using namespace ::cath::common;
using namespace ::cath::opts;

using ::boost::none;
using ::boost::program_options::options_description;
using ::boost::program_options::value;
using ::boost::program_options::variables_map;
using ::std::filesystem::path;
using ::std::nullopt;
using ::std::string;
using ::std::unique_ptr;

Expand Down Expand Up @@ -131,10 +131,10 @@ void cath_cluster_output_options_block::do_add_hidden_options_to_description(opt
}

/// \brief Generate a description of any problem that makes the specified cath_cluster_output_options_block invalid
/// or none otherwise
/// or nullopt otherwise
str_opt cath_cluster_output_options_block::do_invalid_string(const variables_map &/*prm_variables_map*/ ///< The variables map, which options_blocks can use to determine which options were specified, defaulted etc
) const {
return none;
return nullopt;
}

/// \brief Return all options names for this block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "cath/common/boost_addenda/range/max_proj_element.hpp"
#include "cath/common/exception/invalid_argument_exception.hpp"
#include "cath/common/optional/make_optional_if.hpp"

#include <functional>

Expand All @@ -42,11 +43,10 @@ using ::boost::algorithm::is_sorted;
using ::boost::algorithm::join;
using ::boost::algorithm::to_lower_copy;
using ::boost::lexical_cast;
using ::boost::make_optional;
using ::boost::none;
using ::boost::range::sort;
using ::std::greater;
using ::std::less;
using ::std::nullopt;
using ::std::string;

/// \brief Getter for the levels at which the clustering should be performed
Expand All @@ -62,7 +62,7 @@ cath_cluster_clustering_spec & cath_cluster_clustering_spec::set_levels(const st
}

/// \brief Generate a description of any problem that makes the specified cath_cluster_clustering_spec invalid
/// or none otherwise
/// or nullopt otherwise
///
/// \relates cath_cluster_clustering_spec
str_opt cath::clust::get_invalid_description(const cath_cluster_clustering_spec &prm_clustering_spec ///< The cath_cluster_clustering_spec to query
Expand All @@ -71,18 +71,18 @@ str_opt cath::clust::get_invalid_description(const cath_cluster_clustering_spec
return "Most specify at least one clustering level"s;
}

return none;
return nullopt;
}

/// \brief Get a warning string if the specified clustering levels aren't sorted suitable for the specified link_dirn
/// or none otherwise
/// or nullopt otherwise
str_opt cath::clust::get_dissim_sort_warning(const strength_vec &prm_levels, ///< The clustering levels to check
const link_dirn &prm_link_dirn ///< Whether the links in the input file represent strengths or dissimilarities
) {
const bool is_correct = ( prm_link_dirn == link_dirn::STRENGTH )
? is_sorted( prm_levels, less <>{} )
: is_sorted( prm_levels, greater<>{} );
return make_optional(
return make_optional_if(
! is_correct,
"The levels ("
+ join(
Expand Down Expand Up @@ -135,7 +135,7 @@ strength cath::clust::get_max_dissim(const strength_vec &prm_levels, ///< The
}

/// \brief Get a warning string if the specified cath_cluster_clustering_spec's clustering levels aren't
/// sorted suitable for the specified link_dirn or none otherwise
/// sorted suitable for the specified link_dirn or nullopt otherwise
///
/// \relates cath_cluster_clustering_spec
str_opt cath::clust::get_dissim_sort_warning(const cath_cluster_clustering_spec &prm_spec, ///< The cath_cluster_clustering_spec to check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#ifndef _CATH_TOOLS_SOURCE_CT_CATH_CLUSTER_CATH_CATH_CLUSTER_OPTIONS_SPEC_CATH_CLUSTER_CLUSTERING_SPEC_HPP
#define _CATH_TOOLS_SOURCE_CT_CATH_CLUSTER_CATH_CATH_CLUSTER_OPTIONS_SPEC_CATH_CLUSTER_CLUSTERING_SPEC_HPP

#include <boost/optional.hpp>

#include "cath/clustagglom/clustagglom_type_aliases.hpp"
#include "cath/clustagglom/link_dirn.hpp"
#include "cath/common/path_type_aliases.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <boost/optional/optional_io.hpp>
#include <string>

#include <boost/test/unit_test.hpp>

#include "cath/cath_cluster/options/spec/cath_cluster_clustering_spec.hpp"

#include <string>
#include "cath/test/boost_test_print_type.hpp"

namespace cath { namespace test { } }

using namespace ::cath::clust;
using namespace ::cath::test;
using namespace ::std::literals::string_literals;

using ::boost::none;
using ::boost::test_tools::per_element;
using ::std::nullopt;

namespace cath {
namespace test {
Expand Down Expand Up @@ -69,12 +69,12 @@ BOOST_FIXTURE_TEST_SUITE(cath_cluster_clustering_spec_test_suite, cath_cluster_c

BOOST_AUTO_TEST_CASE(levels_processing_is_correct) {
BOOST_TEST( get_dissim_sort_warning ( jumbled_strength_levels, link_dirn::STRENGTH ) == "The levels (35, 95, 60, 100) are not sorted to be increasing as would be expected with a strength link direction"s );
BOOST_TEST( get_dissim_sort_warning ( valid_strength_levels, link_dirn::STRENGTH ) == none );
BOOST_TEST( get_dissim_sort_warning ( valid_strength_levels, link_dirn::STRENGTH ) == nullopt );
BOOST_TEST( make_dissim_and_sort_copy( valid_strength_levels, link_dirn::STRENGTH ) == expected_strength_levels_result, per_element{} );
BOOST_TEST( get_max_dissim ( valid_strength_levels, link_dirn::STRENGTH ) == -35 );

BOOST_TEST( get_dissim_sort_warning ( jumbled_distance_levels, link_dirn::DISSIMILARITY ) == "The levels (4, 2, 3, 1) are not sorted to be decreasing as would be expected with a distance link direction"s );
BOOST_TEST( get_dissim_sort_warning ( valid_distance_levels, link_dirn::DISSIMILARITY ) == none );
BOOST_TEST( get_dissim_sort_warning ( valid_distance_levels, link_dirn::DISSIMILARITY ) == nullopt );
BOOST_TEST( make_dissim_and_sort_copy( valid_distance_levels, link_dirn::DISSIMILARITY ) == expected_distance_levels_result, per_element{} );
BOOST_TEST( get_max_dissim ( valid_distance_levels, link_dirn::DISSIMILARITY ) == 4 );
}
Expand Down

0 comments on commit d786abb

Please sign in to comment.