22#ifndef mia_core_parameters_hh
23#define mia_core_parameters_hh
71 void descr(std::ostream& os)
const;
84 void value(std::ostream& os)
const;
94 bool set(
const std::string& str_value);
137 const std::string
errmsg(
const std::string& err_value)
const;
147 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
148 virtual bool do_set(
const std::string& str_value) = 0;
149 virtual void do_reset() = 0;
150 virtual std::string do_get_default_value()
const = 0;
151 virtual std::string do_get_value_as_string()
const = 0;
152 virtual void do_get_help_xml(
CXMLElement& self)
const;
156 const std::string m_type;
187 virtual bool do_set(
const std::string& str_value);
188 virtual void do_reset();
189 virtual void adjust(T& value);
190 virtual std::string do_get_default_value()
const;
191 virtual std::string do_get_value_as_string()
const;
193 const T m_default_value;
240 template <
typename S>
245 template <
typename S>
272 virtual void adjust(T& value);
273 virtual void do_get_help_xml(
CXMLElement& self)
const;
286template <
typename T,
typename S>
290 {
static_cast<T
>(lower_bound)},
required, descr);
299template <
typename T,
typename S>
303 {
static_cast<T
>(lower_bound)},
required, descr);
314template <
typename T,
typename S>
318 {
static_cast<T
>(upper_bound)},
required, descr);
321template <
typename T,
typename S>
325 {
static_cast<T
>(upper_bound)},
required, descr);
328template <
typename T,
typename S1,
typename S2>
332 {
static_cast<T
>(lower_bound),
static_cast<T
>(upper_bound)},
required, descr);
335template <
typename T,
typename S1,
typename S2>
339 {
static_cast<T
>(lower_bound),
static_cast<T
>(upper_bound)},
required, descr);
342template <
typename T,
typename S1,
typename S2>
346 {
static_cast<T
>(lower_bound),
static_cast<T
>(upper_bound)},
required, descr);
349template <
typename T,
typename S1,
typename S2>
353 {
static_cast<T
>(lower_bound),
static_cast<T
>(upper_bound)},
required, descr);
382 virtual void do_descr(std::ostream& os)
const;
384 virtual bool do_set(
const std::string& str_value);
385 virtual void do_reset();
386 virtual std::string do_get_default_value()
const;
387 virtual std::string do_get_value_as_string()
const;
388 virtual void do_get_help_xml(
CXMLElement& self)
const;
435 virtual void do_descr(std::ostream& os)
const;
436 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
437 virtual bool do_set(
const std::string& str_value);
438 virtual void do_reset();
439 virtual std::string do_get_default_value()
const;
440 virtual std::string do_get_value_as_string()
const;
441 virtual void do_get_help_xml(
CXMLElement& self)
const;
443 typename F::ProductPtr dummy_shared_value;
444 typename F::UniqueProduct dummy_unique_value;
446 typename F::ProductPtr& m_shared_value;
447 typename F::UniqueProduct& m_unique_value;
449 virtual void post_set();
451 std::string m_string_value;
452 std::string m_default_value;
486 virtual void do_descr(std::ostream& os)
const;
488 virtual bool do_set(
const std::string& str_value);
489 virtual void do_reset();
490 virtual std::string do_get_default_value()
const;
491 virtual std::string do_get_value_as_string()
const;
495 const std::set<T> m_valid_set;
523 virtual void do_descr(std::ostream& os)
const;
525 virtual void do_reset();
526 virtual bool do_set(
const std::string& str_value);
527 virtual std::string do_get_default_value()
const;
528 virtual std::string do_get_value_as_string()
const;
543 virtual void do_reset();
544 virtual bool do_set(
const std::string& str_value);
545 virtual std::string do_get_default_value()
const;
546 virtual std::string do_get_value_as_string()
const;
548 virtual void do_descr(std::ostream& os)
const;
549 virtual void do_get_help_xml(
CXMLElement& self)
const;
550 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
553 std::string& m_value;
554 std::string m_default_value;
621 typedef typename FactoryTrait<T>::type F;
642 typedef typename FactoryTrait<T>::type F;
655struct __dispatch_param_translate {
656 static std::string apply(T x)
658 std::ostringstream s;
665struct __dispatch_param_translate<
std::string> {
666 static std::string apply(
const std::string& x)
673struct __dispatch_param_translate<const char *> {
674 static std::string apply(
const char *x)
676 return std::string(x);
686 m_default_value(value),
694 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
695 os <<
"\n " << i->second.first <<
": " << i->second.second;
703 auto& dict = this->add_xmlhelp_childnode(self,
"dict");
705 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
706 auto& v = this->add_xmlhelp_childnode(dict,
"value");
707 this->add_xmlhelp_attribute(v,
"name", i->second.first);
708 this->add_xmlhelp_text(v, i->second.second);
715 m_value = m_dict.get_value(str_value.c_str());
722 m_value = m_default_value;
728 return m_dict.get_name(m_default_value);
734 return m_dict.get_name(m_value);
739 const std::string& init,
bool required,
const char *descr):
741 m_shared_value(value),
742 m_unique_value(dummy_unique_value),
743 m_string_value(init),
744 m_default_value(init),
752 m_shared_value(dummy_shared_value),
753 m_unique_value(value),
754 m_string_value(init),
755 m_default_value(init),
765 os <<
"For a list of available plug-ins see run 'mia-plugin-help "
766 << T::instance().get_descriptor() <<
"'";
772 auto& node = this->add_xmlhelp_childnode(self,
"factory");
773 this->add_xmlhelp_attribute(node,
"name", T::instance().get_descriptor());
779 m_string_value = str_value;
786 if (!m_string_value.empty()) {
788 m_unique_value = T::instance().produce_unique(m_string_value);
790 m_shared_value = T::instance().produce(m_string_value);
797 m_string_value = m_default_value;
804 if (handler_map.find(T::instance().get_descriptor()) == handler_map.end()) {
805 handler_map[T::instance().get_descriptor()] = &T::instance();
807 for (
auto i = T::instance().begin(); i != T::instance().end(); ++i)
808 i->second->add_dependend_handlers(handler_map);
815 return m_default_value;
821 if (m_unique && m_unique_value)
822 return m_unique_value->get_init_string();
824 if (!m_unique && m_shared_value)
825 return m_shared_value->get_init_string();
827 return m_string_value;
834 m_default_value(value),
835 m_valid_set(valid_set)
837 if (m_valid_set.empty())
838 throw std::invalid_argument(
"CSetParameter initialized with empty set");
845 return __dispatch_param_translate<T>::apply(m_default_value);
851 return __dispatch_param_translate<T>::apply(m_value);
857 auto i = m_valid_set.begin();
858 auto e = m_valid_set.end();
860 os <<
" Supported values are (" << *i;
872 auto& node = this->add_xmlhelp_childnode(self,
"set");
874 for (
auto i = m_valid_set.begin(); i != m_valid_set.end(); ++i) {
875 auto& v = this->add_xmlhelp_childnode(node,
"value");
876 this->add_xmlhelp_attribute(v,
"name", __dispatch_param_translate<T>::apply(*i));
883 m_value = m_default_value;
889 std::stringstream s(str_value);
893 if (s.fail() || m_valid_set.find(val) == m_valid_set.end()) {
894 throw std::invalid_argument(errmsg(str_value));
907 m_default_value(value)
922 std::stringstream s(str_value);
926 throw std::invalid_argument(errmsg(str_value));
934 m_value = m_default_value;
940 std::ostringstream s;
941 s << m_default_value;
944 if (str.find(
',') != std::string::npos) {
945 std::ostringstream s2;
946 s2 <<
'[' << str <<
']';
956 return __dispatch_param_translate<T>::apply(m_value);
CDictParameter(T &value, const TDictMap< T > &dict, const char *descr, bool required=false)
virtual void do_descr(std::ostream &os) const
The base class for parameters used in complex options.
bool set(const std::string &str_value)
const char * type() const
void descr(std::ostream &os) const
const char * get_descr() const
std::string get_default_value() const
void get_help_xml(CXMLElement &root) const
CParameter(const char type[], bool required, const char *descr)
std::string get_value_as_string() const
void add_dependend_handler(HandlerHelpMap &handler_map) const
const std::string errmsg(const std::string &err_value) const
create an error message by using the given value that raises the error
void add_xmlhelp_attribute(CXMLElement &node, const std::string &tag, const std::string &value) const
void add_xmlhelp_text(CXMLElement &node, const std::string &value) const
CXMLElement & add_xmlhelp_childnode(CXMLElement &parent, const std::string &tag) const
void value(std::ostream &os) const
bool required_set() const
virtual void do_descr(std::ostream &os) const =0
The base class for all plugin handlers.
A parameter that can only assume values out of a limited set.
CSetParameter(T &value, const std::set< T > &valid_set, const char *descr, bool required=false)
virtual void do_descr(std::ostream &os) const
CStringParameter(std::string &value, CCmdOptionFlags flags, const char *descr, const CPluginHandlerBase *plugin_hint=nullptr)
Generic type of a complex paramter.
CTParameter(T &value, bool required, const char *descr)
virtual void do_descr(std::ostream &os) const
This class implements a facade for the xml Element.
void do_descr(std::ostream &os) const
TBoundedParameter(T &value, EParameterBounds flags, const std::vector< boundary_type > &boundaries, bool required, const char *descr)
boundary< T >::value_type boundary_type
A mapper from emums to string values. - usefull for names flags.
A parameter that get's initialized by a factory to a shared or unique pointer.
TFactoryParameter(typename F::ProductPtr &value, const std::string &init, bool required, const char *descr)
A parameter that can assume any value of the given value type.
virtual void do_descr(std::ostream &os) const
TParameter(T &value, bool required, const char *descr)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
#define NS_MIA_END
conveniance define to end the mia namespace
EParameterBounds
Scalar parameter with an expected value range.
std::map< std::string, const CPluginHandlerBase * > HandlerHelpMap
A map that is used to collect the plug-in handlers used in a program.
TBoundedParameter< uint16_t > CUSBoundedParameter
an unsigned short parameter (with possible boundaries)
TBoundedParameter< uint32_t > CUIBoundedParameter
an unsigned int parameter (with possible boundaries)
TBoundedParameter< int32_t > CSIBoundedParameter
an signed int parameter (with possible boundaries)
CParameter * make_positive_param(T &value, bool required, const char *descr)
TBoundedParameter< std::vector< double > > CVDBoundedParameter
an float parameter, double accuracy (with possible boundaries)
CParameter * make_uc_param(T &value, S upper_bound, bool required, const char *descr)
CParameter * make_oci_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)
EXPORT_CORE std::ostream & operator<<(std::ostream &os, EParameterBounds flags)
TBoundedParameter< uint64_t > CULBoundedParameter
an unsigned long parameter (with possible boundaries)
TBoundedParameter< int16_t > CSSBoundedParameter
an signed short parameter (with possible boundaries)
TBoundedParameter< std::vector< uint16_t > > CVUSBoundedParameter
an unsigned short parameter (with possible boundaries)
TBoundedParameter< std::vector< int64_t > > CVSLBoundedParameter
an signed long parameter (with possible boundaries)
CParameter * make_ci_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)
TBoundedParameter< double > CDBoundedParameter
an float parameter, double accuracy (with possible boundaries)
CParameter * make_nonnegative_param(T &value, bool required, const char *descr)
CParameter * make_coi_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)
CParameter * make_uo_param(T &value, S upper_bound, bool required, const char *descr)
TBoundedParameter< std::vector< uint32_t > > CVUIBoundedParameter
an unsigned int parameter (with possible boundaries)
TBoundedParameter< std::vector< float > > CVFBoundedParameter
an float parameter, single accuracy (with possible boundaries)
CTParameter< bool > CBoolParameter
boolean parameter
TBoundedParameter< std::vector< uint64_t > > CVULBoundedParameter
an unsigned long parameter (with possible boundaries)
CParameter * make_param(T &value, bool required, const char *descr)
TBoundedParameter< std::vector< int16_t > > CVSSBoundedParameter
an signed short parameter (with possible boundaries)
IMPLEMENT_FLAG_OPERATIONS(EParameterBounds)
TBoundedParameter< float > CFBoundedParameter
an float parameter, single accuracy (with possible boundaries)
TBoundedParameter< std::vector< int32_t > > CVSIBoundedParameter
an signed int parameter (with possible boundaries)
CParameter * make_lo_param(T &value, S lower_bound, bool required, const char *descr)
TBoundedParameter< int64_t > CSLBoundedParameter
an signed long parameter (with possible boundaries)
CParameter * make_lc_param(T &value, S lower_bound, bool required, const char *descr)
CParameter * make_oi_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)