version 1.3 | version 1.4 |
---|
| |
#include "colvarmodule.h" | #include "colvarmodule.h" |
#include "colvarparse.h" | #include "colvarparse.h" |
| |
/// Parent class for a member object of a bias, cv or cvc etc. containing dependencies | /// \brief Parent class for a member object of a bias, cv or cvc etc. containing features and |
/// (features) and handling dependency resolution | /// their dependencies, and handling dependency resolution |
| /// |
// Some features like colvar::f_linear have no dependencies, require() doesn't enable anything but fails if unavailable | /// There are 3 kinds of features: |
// Policy: those features are unavailable at all times | /// 1. Dynamic features are under the control of the dependency resolution |
// Other features are under user control | /// system. They may be enabled or disabled depending on dependencies. |
// They are unavailable unless requested by the user, then they may be enabled subject to | /// 2. User features may be enabled based on user input (they may trigger a failure upon dependency resolution, though) |
// satisfied dependencies | /// 3. Static features are static properties of the object, determined |
| /// programatically at initialization time. |
// It seems important to have available default to false (for safety) and enabled to false (for efficiency) | /// |
| |
class colvardeps { | class colvardeps { |
public: | public: |
| |
| |
feature_state(bool a, bool e) | feature_state(bool a, bool e) |
: available(a), enabled(e) {} | : available(a), enabled(e) {} |
| |
/// Available means: supported, subject to dependencies as listed, | /// Feature may be enabled, subject to possible dependencies |
/// MAY BE ENABLED AS A RESULT OF DEPENDENCY SOLVING | |
/// Remains false for passive flags that are set based on other object properties, | |
/// eg. f_cv_linear | |
/// Is set to true upon user request for features that are implemented by the user | |
/// or under his/her direct control, e.g. f_cv_scripted or f_cv_extended_Lagrangian | |
bool available; | bool available; |
/// Currently enabled - this flag is subject to change dynamically | /// Currently enabled - this flag is subject to change dynamically |
/// TODO consider implications for dependency solving: anyone who disables | /// TODO consider implications for dependency solving: anyone who disables |
| |
| |
| |
private: | private: |
/// List of the state of all features | /// List of the states of all features |
std::vector<feature_state> feature_states; | std::vector<feature_state> feature_states; |
| |
| /// Enum of possible feature types |
| enum feature_type { |
| f_type_not_set, |
| f_type_dynamic, |
| f_type_user, |
| f_type_static |
| }; |
| |
public: | public: |
| /// Pair a numerical feature ID with a description and type |
| void init_feature(int feature_id, const char *description, feature_type type = f_type_not_set); |
| |
/// Describes a feature and its dependecies | /// Describes a feature and its dependecies |
/// used in a static array within each subclass | /// used in a static array within each subclass |
class feature { | class feature { |
| |
| |
// features that this feature requires in children | // features that this feature requires in children |
std::vector<int> requires_children; | std::vector<int> requires_children; |
| |
| inline bool is_dynamic() { return type == f_type_dynamic; } |
| inline bool is_static() { return type == f_type_static; } |
| inline bool is_user() { return type == f_type_user; } |
| /// Type of this feature, from the enum feature_type |
| feature_type type; |
}; | }; |
| |
| inline bool is_dynamic(int id) { return features()[id]->type == f_type_dynamic; } |
| inline bool is_static(int id) { return features()[id]->type == f_type_static; } |
| inline bool is_user(int id) { return features()[id]->type == f_type_user; } |
| |
// Accessor to array of all features with deps, static in most derived classes | // Accessor to array of all features with deps, static in most derived classes |
// Subclasses with dynamic dependency trees may override this | // Subclasses with dynamic dependency trees may override this |
// with a non-static array | // with a non-static array |
| |
/// (useful for cvcs because their children are member objects) | /// (useful for cvcs because their children are member objects) |
void remove_all_children(); | void remove_all_children(); |
| |
| |
| |
private: | private: |
| |
// pointers to objects this object depends on | // pointers to objects this object depends on |
// list should be maintained by any code that modifies the object | // list should be maintained by any code that modifies the object |
// this could be secured by making lists of colvars / cvcs / atom groups private and modified through accessor functions | // this could be secured by making lists of colvars / cvcs / atom groups private and modified through accessor functions |
| |
return feature_states[f].available; | return feature_states[f].available; |
} | } |
| |
void provide(int feature_id); // set the feature's flag to available in local object | /// Set the feature's available flag, without checking |
| /// To be used for dynamic properties |
| /// dependencies will be checked by enable() |
| void provide(int feature_id, bool truefalse = true); |
| |
/// Set the feature's enabled flag, without dependency check or resolution | /// Set the feature's enabled flag, without dependency check or resolution |
/// To be used for static and user properties | /// To be used for static properties only |
/// Checking for availability is up to the caller | /// Checking for availability is up to the caller |
void set_enabled(int feature_id, bool truefalse); | void set_enabled(int feature_id, bool truefalse = true); |
| |
protected: | protected: |
| |
void set_available(int feature_id, bool truefalse); // set the feature's available flag, without checking | |
| |
| |
/// Parse a keyword and enable a feature accordingly | /// Parse a keyword and enable a feature accordingly |