21 #ifndef mia_core_parameters_hh
22 #define mia_core_parameters_hh
67 const char *type()
const;
71 void descr(std::ostream& os)
const;
78 std::string get_value_as_string()
const;
84 void value(std::ostream& os)
const;
89 bool required_set()
const;
94 bool set(
const std::string& str_value);
97 const char *get_descr()
const;
112 std::string get_default_value()
const;
118 void get_help_xml(xmlpp::Element& root)
const;
126 virtual void post_set();
134 virtual void do_descr(std::ostream& os)
const = 0;
137 const std::string errmsg(
const std::string& err_value)
const;
142 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
143 virtual bool do_set(
const std::string& str_value) = 0;
144 virtual void do_reset() = 0;
145 virtual std::string do_get_default_value()
const = 0;
146 virtual std::string do_get_value_as_string()
const = 0;
147 virtual void do_get_help_xml(xmlpp::Element&
self)
const;
163 template <
typename T>
178 virtual void do_descr(std::ostream& os)
const;
180 virtual bool do_set(
const std::string& str_value);
181 virtual void do_reset();
182 virtual void adjust(T& value);
183 virtual std::string do_get_default_value()
const;
184 virtual std::string do_get_value_as_string()
const;
186 const T m_default_value;
197 template <
typename T>
213 void do_descr(std::ostream& os)
const;
215 virtual void adjust(T& value);
216 virtual void do_get_help_xml(xmlpp::Element&
self)
const;
231 template <
typename T>
246 virtual void do_descr(std::ostream& os)
const;
248 virtual bool do_set(
const std::string& str_value);
249 virtual void do_reset();
250 virtual std::string do_get_default_value()
const;
251 virtual std::string do_get_value_as_string()
const;
252 virtual void do_get_help_xml(xmlpp::Element&
self)
const;
268 template <
typename F>
296 TFactoryParameter(
typename F::UniqueProduct& value,
const std::string& init,
bool required,
const char *descr);
298 virtual void do_descr(std::ostream& os)
const;
299 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
300 virtual bool do_set(
const std::string& str_value);
301 virtual void do_reset();
302 virtual std::string do_get_default_value()
const;
303 virtual std::string do_get_value_as_string()
const;
304 virtual void do_get_help_xml(xmlpp::Element&
self)
const;
306 typename F::ProductPtr dummy_shared_value;
307 typename F::UniqueProduct dummy_unique_value;
309 typename F::ProductPtr& m_shared_value;
310 typename F::UniqueProduct& m_unique_value;
312 virtual void post_set();
314 std::string m_string_value;
315 std::string m_default_value;
333 template <
typename T>
348 virtual void do_descr(std::ostream& os)
const;
350 virtual bool do_set(
const std::string& str_value);
351 virtual void do_reset();
352 virtual std::string do_get_default_value()
const;
353 virtual std::string do_get_value_as_string()
const;
354 void do_get_help_xml(xmlpp::Element&
self)
const;
357 const std::set<T> m_valid_set;
370 template <
typename T>
384 virtual void do_descr(std::ostream& os)
const;
386 virtual void do_reset();
387 virtual bool do_set(
const std::string& str_value);
388 virtual std::string do_get_default_value()
const;
389 virtual std::string do_get_value_as_string()
const;
403 virtual void do_reset();
404 virtual bool do_set(
const std::string& str_value);
405 virtual std::string do_get_default_value()
const;
406 virtual std::string do_get_value_as_string()
const;
408 virtual void do_descr(std::ostream& os)
const;
409 virtual void do_get_help_xml(xmlpp::Element&
self)
const;
410 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
413 std::string& m_value;
414 std::string m_default_value;
446 template <
typename T>
449 typedef typename FactoryTrait<T>::type F;
468 template <
typename T>
471 typedef typename FactoryTrait<T>::type F;
477 template <
typename T>
490 template <
typename T>
491 struct __dispatch_param_translate {
492 static std::string apply(T x) {
493 std::ostringstream s;
500 struct __dispatch_param_translate<
std::string> {
501 static std::string apply(
const std::string& x) {
507 struct __dispatch_param_translate<const char *> {
508 static std::string apply(
const char * x) {
509 return std::string(x);
515 template <
typename T>
519 m_default_value(value),
524 template <
typename T>
527 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
528 os <<
"\n " << i->second.first <<
": " << i->second.second;
532 template <
typename T>
536 auto dict =
self.add_child(
"dict");
537 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
538 auto v = dict->add_child(
"value");
539 v->set_attribute(
"name", i->second.first);
540 v->set_child_text(i->second.second);
544 template <
typename T>
547 m_value = m_dict.get_value(str_value.c_str());
551 template <
typename T>
554 m_value = m_default_value;
557 template <
typename T>
560 return m_dict.get_name(m_default_value);
563 template <
typename T>
566 return m_dict.get_name(m_value);
569 template <
typename F>
571 const std::string& init,
bool required,
const char *descr):
573 m_shared_value(value),
574 m_unique_value(dummy_unique_value),
575 m_string_value(init),
576 m_default_value(init),
581 template <
typename F>
584 m_shared_value(dummy_shared_value),
585 m_unique_value(value),
586 m_string_value(init),
587 m_default_value(init),
594 template <
typename T>
597 os <<
"For a list of available plug-ins see run 'mia-plugin-help "
598 << T::instance().get_descriptor() <<
"'";
601 template <
typename T>
604 auto dict =
self.add_child(
"factory");
605 dict->set_attribute(
"name", T::instance().get_descriptor());
608 template <
typename T>
611 m_string_value = str_value;
615 template <
typename T>
618 if (!m_string_value.empty()) {
620 m_unique_value = T::instance().produce_unique(m_string_value);
622 m_shared_value = T::instance().produce(m_string_value);
626 template <
typename T>
629 m_string_value = m_default_value;
632 template <
typename T>
636 if (handler_map.find(T::instance().get_descriptor()) == handler_map.end()){
637 handler_map[T::instance().get_descriptor()] = &T::instance();
638 for (
auto i = T::instance().begin(); i != T::instance().end(); ++i)
639 i->second->add_dependend_handlers(handler_map);
643 template <
typename T>
646 return m_default_value;
649 template <
typename T>
652 if (m_unique && m_unique_value)
653 return m_unique_value->get_init_string();
654 if (!m_unique && m_shared_value)
655 return m_shared_value->get_init_string();
656 return m_string_value;
659 template <
typename T>
663 m_default_value(value),
664 m_valid_set(valid_set)
666 if (m_valid_set.empty())
667 throw std::invalid_argument(
"CSetParameter initialized with empty set");
671 template <
typename T>
674 return __dispatch_param_translate<T>::apply(m_default_value);
677 template <
typename T>
680 return __dispatch_param_translate<T>::apply(m_value);
683 template <
typename T>
686 auto i = m_valid_set.begin();
687 auto e = m_valid_set.end();
691 os <<
" Supported values are (" << *i;
699 template <
typename T>
702 auto set =
self.add_child(
"set");
703 for (
auto i = m_valid_set.begin(); i != m_valid_set.end(); ++i) {
704 auto v = set->add_child(
"value");
705 v->set_attribute(
"name", __dispatch_param_translate<T>::apply(*i));
709 template <
typename T>
712 m_value = m_default_value;
715 template <
typename T>
718 std::stringstream s(str_value);
721 if (s.fail() || m_valid_set.find(val) == m_valid_set.end()) {
722 throw std::invalid_argument(errmsg(str_value));
730 template <
typename T>
734 m_default_value(value)
740 template <
typename T>
746 template <
typename T>
749 std::stringstream s(str_value);
752 throw std::invalid_argument(errmsg(str_value));
756 template <
typename T>
759 m_value = m_default_value;
762 template <
typename T>
765 std::ostringstream s;
766 s << m_default_value;
768 if (str.find(
',') != std::string::npos) {
769 std::ostringstream s2;
770 s2 <<
'[' << str <<
']';
776 template <
typename T>
779 return __dispatch_param_translate<T>::apply(m_value);
CSetParameter(T &value, const std::set< T > &valid_set, const char *descr, bool required=false)
TRangeParameter< float > CFloatParameter
a float parameter (with range)
virtual void do_descr(std::ostream &os) const
TRangeParameter< double > CDoubleParameter
a double parameter (with range)
virtual void do_descr(std::ostream &os) const
virtual void do_descr(std::ostream &os) const
A parameter that get's initialized by a factory to a shared or unique pointer.
void value(std::ostream &os) const
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.
virtual void do_descr(std::ostream &os) const =0
A parameter that can assume any value of the given value type.
TRangeParameter< int > CIntParameter
an integer parameter (with range)
CParameter * make_param(std::shared_ptr< T > &value, const std::string &init, bool required, const char *descr)
create a factory parameter that initializes to a std::shared_ptr
void descr(std::ostream &os) const
TRangeParameter< unsigned int > CUIntParameter
an unsigned integer parameter (with range)
virtual void do_descr(std::ostream &os) const
Scalar parameter with an expected value range.
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
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