22 #ifndef mia_core_parameters_hh 23 #define mia_core_parameters_hh 66 const char *type()
const;
70 void descr(std::ostream& os)
const;
77 std::string get_value_as_string()
const;
83 void value(std::ostream& os)
const;
88 bool required_set()
const;
93 bool set(
const std::string& str_value);
96 const char *get_descr()
const;
111 std::string get_default_value()
const;
125 virtual void post_set();
133 virtual void do_descr(std::ostream& os)
const = 0;
136 const std::string errmsg(
const std::string& err_value)
const;
141 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
142 virtual bool do_set(
const std::string& str_value) = 0;
143 virtual void do_reset() = 0;
144 virtual std::string do_get_default_value()
const = 0;
145 virtual std::string do_get_value_as_string()
const = 0;
146 virtual void do_get_help_xml(
CXMLElement&
self)
const;
162 template <
typename T>
177 virtual void do_descr(std::ostream& os)
const;
179 virtual bool do_set(
const std::string& str_value);
180 virtual void do_reset();
181 virtual void adjust(T& value);
182 virtual std::string do_get_default_value()
const;
183 virtual std::string do_get_value_as_string()
const;
185 const T m_default_value;
226 template <
typename T>
246 void do_descr(std::ostream& os)
const;
248 virtual void adjust(T& value);
249 virtual void do_get_help_xml(
CXMLElement&
self)
const;
255 template <
typename T>
262 template <
typename T,
typename S>
266 {
static_cast<T
>(lower_bound)}, required, descr);
269 template <
typename T>
275 template <
typename T,
typename S>
279 {
static_cast<T
>(lower_bound)}, required, descr);
283 template <
typename T>
290 template <
typename T,
typename S>
294 {
static_cast<T
>(upper_bound)}, required, descr);
297 template <
typename T,
typename S>
301 {
static_cast<T
>(upper_bound)}, required, descr);
304 template <
typename T,
typename S1,
typename S2>
308 {
static_cast<T
>(lower_bound), static_cast<T>(upper_bound)},
required, descr);
311 template <
typename T,
typename S1,
typename S2>
315 {
static_cast<T
>(lower_bound), static_cast<T>(upper_bound)},
required, descr);
318 template <
typename T,
typename S1,
typename S2>
322 {
static_cast<T
>(lower_bound), static_cast<T>(upper_bound)},
required, descr);
325 template <
typename T,
typename S1,
typename S2>
329 {
static_cast<T
>(lower_bound), static_cast<T>(upper_bound)},
required, descr);
342 template <
typename T>
357 virtual void do_descr(std::ostream& os)
const;
359 virtual bool do_set(
const std::string& str_value);
360 virtual void do_reset();
361 virtual std::string do_get_default_value()
const;
362 virtual std::string do_get_value_as_string()
const;
363 virtual void do_get_help_xml(
CXMLElement&
self)
const;
379 template <
typename F>
407 TFactoryParameter(
typename F::UniqueProduct& value,
const std::string& init,
bool required,
const char *descr);
409 virtual void do_descr(std::ostream& os)
const;
410 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
411 virtual bool do_set(
const std::string& str_value);
412 virtual void do_reset();
413 virtual std::string do_get_default_value()
const;
414 virtual std::string do_get_value_as_string()
const;
415 virtual void do_get_help_xml(
CXMLElement&
self)
const;
417 typename F::ProductPtr dummy_shared_value;
418 typename F::UniqueProduct dummy_unique_value;
420 typename F::ProductPtr& m_shared_value;
421 typename F::UniqueProduct& m_unique_value;
423 virtual void post_set();
425 std::string m_string_value;
426 std::string m_default_value;
444 template <
typename T>
459 virtual void do_descr(std::ostream& os)
const;
461 virtual bool do_set(
const std::string& str_value);
462 virtual void do_reset();
463 virtual std::string do_get_default_value()
const;
464 virtual std::string do_get_value_as_string()
const;
468 const std::set<T> m_valid_set;
481 template <
typename T>
495 virtual void do_descr(std::ostream& os)
const;
497 virtual void do_reset();
498 virtual bool do_set(
const std::string& str_value);
499 virtual std::string do_get_default_value()
const;
500 virtual std::string do_get_value_as_string()
const;
514 virtual void do_reset();
515 virtual bool do_set(
const std::string& str_value);
516 virtual std::string do_get_default_value()
const;
517 virtual std::string do_get_value_as_string()
const;
519 virtual void do_descr(std::ostream& os)
const;
520 virtual void do_get_help_xml(
CXMLElement&
self)
const;
521 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
524 std::string& m_value;
525 std::string m_default_value;
569 template <
typename T>
572 typedef typename FactoryTrait<T>::type F;
591 template <
typename T>
594 typedef typename FactoryTrait<T>::type F;
607 template <
typename T>
608 struct __dispatch_param_translate {
609 static std::string apply(T x) {
610 std::ostringstream s;
617 struct __dispatch_param_translate<std::string> {
618 static std::string apply(
const std::string& x) {
624 struct __dispatch_param_translate<const char *> {
625 static std::string apply(
const char * x) {
626 return std::string(x);
632 template <
typename T>
636 m_default_value(value),
641 template <
typename T>
644 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
645 os <<
"\n " << i->second.first <<
": " << i->second.second;
649 template <
typename T>
653 auto dict =
self.add_child(
"dict");
654 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
655 auto v = dict->add_child(
"value");
656 v->set_attribute(
"name", i->second.first);
657 v->set_child_text(i->second.second);
661 template <
typename T>
664 m_value = m_dict.get_value(str_value.c_str());
668 template <
typename T>
671 m_value = m_default_value;
674 template <
typename T>
677 return m_dict.get_name(m_default_value);
680 template <
typename T>
683 return m_dict.get_name(m_value);
686 template <
typename F>
690 m_shared_value(value),
691 m_unique_value(dummy_unique_value),
692 m_string_value(init),
693 m_default_value(init),
698 template <
typename F>
701 m_shared_value(dummy_shared_value),
702 m_unique_value(value),
703 m_string_value(init),
704 m_default_value(init),
711 template <
typename T>
714 os <<
"For a list of available plug-ins see run 'mia-plugin-help " 715 << T::instance().get_descriptor() <<
"'";
718 template <
typename T>
721 auto dict =
self.add_child(
"factory");
722 dict->set_attribute(
"name", T::instance().get_descriptor());
725 template <
typename T>
728 m_string_value = str_value;
732 template <
typename T>
735 if (!m_string_value.empty()) {
737 m_unique_value = T::instance().produce_unique(m_string_value);
739 m_shared_value = T::instance().produce(m_string_value);
743 template <
typename T>
746 m_string_value = m_default_value;
749 template <
typename T>
753 if (handler_map.find(T::instance().get_descriptor()) == handler_map.end()){
754 handler_map[T::instance().get_descriptor()] = &T::instance();
755 for (
auto i = T::instance().begin(); i != T::instance().end(); ++i)
756 i->second->add_dependend_handlers(handler_map);
760 template <
typename T>
763 return m_default_value;
766 template <
typename T>
769 if (m_unique && m_unique_value)
770 return m_unique_value->get_init_string();
771 if (!m_unique && m_shared_value)
772 return m_shared_value->get_init_string();
773 return m_string_value;
776 template <
typename T>
780 m_default_value(value),
781 m_valid_set(valid_set)
783 if (m_valid_set.empty())
784 throw std::invalid_argument(
"CSetParameter initialized with empty set");
788 template <
typename T>
791 return __dispatch_param_translate<T>::apply(m_default_value);
794 template <
typename T>
797 return __dispatch_param_translate<T>::apply(m_value);
800 template <
typename T>
803 auto i = m_valid_set.begin();
804 auto e = m_valid_set.end();
808 os <<
" Supported values are (" << *i;
816 template <
typename T>
819 auto set =
self.add_child(
"set");
820 for (
auto i = m_valid_set.begin(); i != m_valid_set.end(); ++i) {
821 auto v =
set->add_child(
"value");
822 v->set_attribute(
"name", __dispatch_param_translate<T>::apply(*i));
826 template <
typename T>
829 m_value = m_default_value;
832 template <
typename T>
835 std::stringstream s(str_value);
838 if (s.fail() || m_valid_set.find(val) == m_valid_set.end()) {
839 throw std::invalid_argument(
errmsg(str_value));
847 template <
typename T>
851 m_default_value(value)
857 template <
typename T>
863 template <
typename T>
866 std::stringstream s(str_value);
869 throw std::invalid_argument(
errmsg(str_value));
873 template <
typename T>
876 m_value = m_default_value;
879 template <
typename T>
882 std::ostringstream s;
883 s << m_default_value;
885 if (str.find(
',') != std::string::npos) {
886 std::ostringstream s2;
887 s2 <<
'[' << str <<
']';
893 template <
typename T>
896 return __dispatch_param_translate<T>::apply(m_value);
CSetParameter(T &value, const std::set< T > &valid_set, const char *descr, bool required=false)
CParameter * make_oci_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)
CParameter * make_positive_param(T &value, bool required, const char *descr)
CParameter * make_param(T &value, bool required, const char *descr)
TBoundedParameter< int > CSIBoundedParameter
an signed int parameter (with possible boundaries)
virtual void do_descr(std::ostream &os) const
TBoundedParameter< double > CDBoundedParameter
an float parameter, double accuracy (with possible boundaries)
TBoundedParameter< unsigned short > CUSBoundedParameter
an unsigned short parameter (with possible boundaries)
virtual void do_descr(std::ostream &os) const
A parameter that get's initialized by a factory to a shared or unique pointer.
TBoundedParameter< long > CSLBoundedParameter
an signed long parameter (with possible boundaries)
const std::string errmsg(const std::string &err_value) const
create an error message by using the given value that raises the error
void value(std::ostream &os) const
CParameter * make_oi_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)
CParameter * make_lc_param(T &value, S lower_bound, bool required, const char *descr)
A parameter that can only assume values out of a limited set.
CTParameter< bool > CBoolParameter
boolean parameter
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
TFactoryParameter(typename F::ProductPtr &value, const std::string &init, bool required, const char *descr)
The base class for parameters used in complex options.
std::map< std::string, const CPluginHandlerBase * > HandlerHelpMap
A map that is used to collect the plug-in handlers used in a program.
The base class for all plugin handlers.
Generic type of a complex paramter.
CParameter * make_uo_param(T &value, S upper_bound, bool required, const char *descr)
EParameterBounds
Scalar parameter with an expected value range.
virtual void do_descr(std::ostream &os) const =0
A parameter that can assume any value of the given value type.
TBoundedParameter< float > CFBoundedParameter
an float parameter, single accuracy (with possible boundaries)
CParameter * make_uc_param(T &value, S upper_bound, bool required, const char *descr)
void descr(std::ostream &os) const
This class implements a facade for the xml Element.
CParameter * make_coi_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)
virtual void do_descr(std::ostream &os) const
CParameter * make_nonnegative_param(T &value, bool required, const char *descr)
TBoundedParameter< short > CSSBoundedParameter
an signed short parameter (with possible boundaries)
CParameter * make_ci_param(T &value, S1 lower_bound, S2 upper_bound, bool required, const char *descr)
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
TBoundedParameter< unsigned int > CUIBoundedParameter
an unsigned int parameter (with possible boundaries)
CParameter * make_lo_param(T &value, S lower_bound, bool required, const char *descr)
IMPLEMENT_FLAG_OPERATIONS(EParameterBounds)
TBoundedParameter< unsigned long > CULBoundedParameter
an unsigned long parameter (with possible boundaries)
EXPORT_CORE std::ostream & operator<<(std::ostream &os, EParameterBounds flags)
TParameter(T &value, bool required, const char *descr)
CDictParameter(T &value, const TDictMap< T > &dict, const char *descr, bool required=false)
A mapper from emums to string values. - usefull for names flags.
#define NS_MIA_END
conveniance define to end the mia namespace