Skip to content

Commit

Permalink
Add default constructors for Fst and Diversity Processors
Browse files Browse the repository at this point in the history
  • Loading branch information
lczech committed May 28, 2024
1 parent 2075e91 commit 0e45974
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/genesis/population/function/diversity_pool_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ class DiversityPoolProcessor
// Constructors and Rule of Five
// -------------------------------------------------------------------------

/**
* @brief Default constructor.
*
* We always want to make sure that the user provides a WindowAveragePolicy, so using this
* default constructor leads to an unusable instance. We provide it so that dummy processors
* can be constructed, but they have to be replaced by non-default-constructed instances
* befor usage.
*/
FstPoolProcessor() = default;

/**
* @brief Construct a processor.
*
Expand All @@ -86,6 +96,7 @@ class DiversityPoolProcessor
: avg_policy_( window_average_policy )
, thread_pool_( thread_pool )
, threading_threshold_( threading_threshold )
, is_default_constructed_( false )
{
thread_pool_ = thread_pool ? thread_pool : utils::Options::get().global_thread_pool();
}
Expand Down Expand Up @@ -185,6 +196,11 @@ class DiversityPoolProcessor

void process( Variant const& variant )
{
// Check correct usage
if( is_default_constructed_ ) {
throw std::domain_error( "Cannot use a default constructed FstPoolProcessor" );
}

// Boundary error check. We do this before any other processing of the Variant,
// as this indicates a serious error or issue with the data somewhere,
// which we want to catch in any case.
Expand Down Expand Up @@ -281,6 +297,10 @@ class DiversityPoolProcessor
// at which we start using the thread pool.
std::shared_ptr<utils::ThreadPool> thread_pool_;
size_t threading_threshold_ = 0;

// We want to make sure to disallow default constructed instances.
// Bit ugly to do it this way, but works for now.
bool is_default_constructed_ = true;
};

// =================================================================================================
Expand Down
19 changes: 19 additions & 0 deletions lib/genesis/population/function/fst_pool_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ class FstPoolProcessor
// Constructors and Rule of Five
// -------------------------------------------------------------------------

/**
* @brief Default constructor.
*
* We always want to make sure that the user provides a WindowAveragePolicy, so using this
* default constructor leads to an unusable instance. We provide it so that dummy processors
* can be constructed, but they have to be replaced by non-default-constructed instances
* befor usage.
*/
FstPoolProcessor() = default;

/**
* @brief Construct a processor.
*
Expand All @@ -82,6 +92,7 @@ class FstPoolProcessor
: avg_policy_( window_average_policy )
, thread_pool_( thread_pool )
, threading_threshold_( threading_threshold )
, is_default_constructed_( false )
{
thread_pool_ = thread_pool ? thread_pool : utils::Options::get().global_thread_pool();
}
Expand Down Expand Up @@ -179,7 +190,11 @@ class FstPoolProcessor

void process( Variant const& variant )
{
// Check correct usage
assert( sample_pairs_.size() == calculators_.size() );
if( is_default_constructed_ ) {
throw std::domain_error( "Cannot use a default constructed FstPoolProcessor" );
}

// Only process Variants that are passing, but keep track of the ones that did not.
++filter_stats_[variant.status.get()];
Expand Down Expand Up @@ -287,6 +302,10 @@ class FstPoolProcessor
// (number of sample pairs) at which we start using the thread pool.
std::shared_ptr<utils::ThreadPool> thread_pool_;
size_t threading_threshold_ = 0;

// We want to make sure to disallow default constructed instances.
// Bit ugly to do it this way, but works for now.
bool is_default_constructed_ = true;
};

// =================================================================================================
Expand Down

0 comments on commit 0e45974

Please sign in to comment.