Skip to content

Commit

Permalink
Separate creation and initialization of colvar components
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomofiorin committed Dec 1, 2023
1 parent 14281bc commit 7f27732
Show file tree
Hide file tree
Showing 15 changed files with 703 additions and 816 deletions.
18 changes: 8 additions & 10 deletions src/colvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
#include "colvars_memstream.h"



std::map<std::string, std::function<colvar::cvc *(const std::string &conf)>>
colvar::global_cvc_map =
std::map<std::string, std::function<colvar::cvc *(const std::string &conf)>>();
std::map<std::string, std::function<colvar::cvc *()>> colvar::global_cvc_map =
std::map<std::string, std::function<colvar::cvc *()>>();

std::map<std::string, std::string> colvar::global_cvc_desc_map =
std::map<std::string, std::string>();
Expand Down Expand Up @@ -755,8 +753,8 @@ template <typename def_class_name>
void colvar::add_component_type(char const *def_description, char const *def_config_key)
{
if (global_cvc_map.count(def_config_key) == 0) {
global_cvc_map[def_config_key] = [](const std::string &cvc_conf) {
return new def_class_name(cvc_conf);
global_cvc_map[def_config_key] = []() {
return new def_class_name();
};
global_cvc_desc_map[def_config_key] = std::string(def_description);
}
Expand All @@ -776,11 +774,10 @@ int colvar::init_components_type(const std::string& conf, const char* def_config
"a new \""+std::string(def_config_key)+"\" component"+
(cvm::debug() ? ", with configuration:\n"+def_conf
: ".\n"));
cvc *cvcp = global_cvc_map[def_config_key](def_conf);
cvm::increase_depth();
cvc *cvcp = global_cvc_map[def_config_key]();
if (cvcp) {
int error_code = cvcp->init_code;
cvcs.push_back(cvcp);
cvm::increase_depth();
int error_code = cvcp->init(def_conf);
error_code |= cvcp->set_function_type(def_config_key);
if (error_code == COLVARS_OK) {
error_code |= cvcp->check_keywords(def_conf, def_config_key);
Expand All @@ -796,6 +793,7 @@ int colvar::init_components_type(const std::string& conf, const char* def_config
return cvm::error("Error: in allocating component \"" + std::string(def_config_key) + "\".\n",
COLVARS_MEMORY_ERROR);
}
cvcs.push_back(cvcp);

if ((cvcp->period != 0.0) || (cvcp->wrap_center != 0.0)) {
if (!cvcp->is_enabled(f_cvc_periodic)) {
Expand Down
7 changes: 2 additions & 5 deletions src/colvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ class colvar : public colvarparse, public colvardeps {
class dihedPC;
class alch_lambda;
class alch_Flambda;
class componentDisabled;
class CartesianBasedPath;
class aspath;
class azpath;
Expand Down Expand Up @@ -644,8 +643,7 @@ class colvar : public colvarparse, public colvardeps {
class map_total;

/// A global mapping of cvc names to the cvc constructors
static const std::map<std::string, std::function<colvar::cvc *(const std::string &subcv_conf)>> &
get_global_cvc_map()
static const std::map<std::string, std::function<colvar::cvc *()>> &get_global_cvc_map()
{
return global_cvc_map;
}
Expand Down Expand Up @@ -688,8 +686,7 @@ class colvar : public colvarparse, public colvardeps {
#endif

/// A global mapping of cvc names to the cvc constructors
static std::map<std::string, std::function<colvar::cvc *(const std::string &conf)>>
global_cvc_map;
static std::map<std::string, std::function<colvar::cvc *()>> global_cvc_map;

/// A global mapping of cvc names to the corresponding descriptions
static std::map<std::string, std::string> global_cvc_desc_map;
Expand Down
14 changes: 0 additions & 14 deletions src/colvarcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ colvar::cvc::cvc()
}


colvar::cvc::cvc(std::string const &conf)
{
description = "uninitialized colvar component";
b_try_scalable = true;
sup_coeff = 1.0;
sup_np = 1;
period = 0.0;
wrap_center = 0.0;
width = 0.0;
init_dependencies();
colvar::cvc::init(conf);
}


int colvar::cvc::update_description()
{
if (name.size() > 0) {
Expand Down
Loading

0 comments on commit 7f27732

Please sign in to comment.