diff --git a/include/tadah/models/descriptors/d_base.h b/include/tadah/models/descriptors/d_base.h index 256497c0d93071189f9ebf78164681a19cf5a809..183a58bc2d6f0c24860b89bbbfcf400ccfc4043d 100644 --- a/include/tadah/models/descriptors/d_base.h +++ b/include/tadah/models/descriptors/d_base.h @@ -26,6 +26,10 @@ public: int verbose; virtual ~D_Base(); + // return position of an argument given to TYPExB for a given key + // if key is not used, returns -1 + int get_arg_pos(const std::string &key) const; + /** \brief Return dimension of the descriptor. */ virtual size_t size() { return s; }; diff --git a/src/d_base.cpp b/src/d_base.cpp index a998eb36696a19ebd04ffb4ae0a80d6ea3b3d097..3f1ca91c4a5e69e0576d311e2d15ca1ea2f62faa 100644 --- a/src/d_base.cpp +++ b/src/d_base.cpp @@ -91,3 +91,10 @@ void D_Base::set_fcut(Cut_Base* cut, bool manage_memory) { fcut = cut; this->manage_memory = manage_memory; } +int D_Base::get_arg_pos(const std::string &key) const { + auto it = std::find(keys.begin(), keys.end(), key); + + if (it == keys.end()) return -1; + + return std::distance(keys.begin(), it)+(nparams-keys.size()); +}