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;
139 void add_xmlhelp_attribute(
CXMLElement& node,
const std::string& tag,
const std::string& value)
const;
140 void add_xmlhelp_text(
CXMLElement& node,
const std::string& value)
const;
146 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
147 virtual bool do_set(
const std::string& str_value) = 0;
148 virtual void do_reset() = 0;
149 virtual std::string do_get_default_value()
const = 0;
150 virtual std::string do_get_value_as_string()
const = 0;
151 virtual void do_get_help_xml(
CXMLElement&
self)
const;
155 const std::string m_type;
168 template <
typename T>
183 virtual void do_descr(std::ostream& os)
const;
185 virtual bool do_set(
const std::string& str_value);
186 virtual void do_reset();
187 virtual void adjust(T& value);
188 virtual std::string do_get_default_value()
const;
189 virtual std::string do_get_value_as_string()
const;
191 const T m_default_value;
233 template <
typename T>
237 template <
typename S>
242 template <
typename S>
266 void do_descr(std::ostream& os)
const;
269 virtual void adjust(T& value);
270 virtual void do_get_help_xml(
CXMLElement&
self)
const;
276 template <
typename T>
283 template <
typename T,
typename S>
287 {
static_cast<T
>(lower_bound)}, required, descr);
290 template <
typename T>
296 template <
typename T,
typename S>
300 {
static_cast<T
>(lower_bound)}, required, descr);
304 template <
typename T>
311 template <
typename T,
typename S>
315 {
static_cast<T
>(upper_bound)}, required, descr);
318 template <
typename T,
typename S>
322 {
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);
332 template <
typename T,
typename S1,
typename S2>
336 {
static_cast<T
>(lower_bound), static_cast<T>(upper_bound)},
required, descr);
339 template <
typename T,
typename S1,
typename S2>
343 {
static_cast<T
>(lower_bound), static_cast<T>(upper_bound)},
required, descr);
346 template <
typename T,
typename S1,
typename S2>
350 {
static_cast<T
>(lower_bound), static_cast<T>(upper_bound)},
required, descr);
363 template <
typename T>
378 virtual void do_descr(std::ostream& os)
const;
380 virtual bool do_set(
const std::string& str_value);
381 virtual void do_reset();
382 virtual std::string do_get_default_value()
const;
383 virtual std::string do_get_value_as_string()
const;
384 virtual void do_get_help_xml(
CXMLElement&
self)
const;
400 template <
typename F>
428 TFactoryParameter(
typename F::UniqueProduct& value,
const std::string& init,
bool required,
const char *descr);
430 virtual void do_descr(std::ostream& os)
const;
431 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
432 virtual bool do_set(
const std::string& str_value);
433 virtual void do_reset();
434 virtual std::string do_get_default_value()
const;
435 virtual std::string do_get_value_as_string()
const;
436 virtual void do_get_help_xml(
CXMLElement&
self)
const;
438 typename F::ProductPtr dummy_shared_value;
439 typename F::UniqueProduct dummy_unique_value;
441 typename F::ProductPtr& m_shared_value;
442 typename F::UniqueProduct& m_unique_value;
444 virtual void post_set();
446 std::string m_string_value;
447 std::string m_default_value;
465 template <
typename T>
480 virtual void do_descr(std::ostream& os)
const;
482 virtual bool do_set(
const std::string& str_value);
483 virtual void do_reset();
484 virtual std::string do_get_default_value()
const;
485 virtual std::string do_get_value_as_string()
const;
489 const std::set<T> m_valid_set;
502 template <
typename T>
516 virtual void do_descr(std::ostream& os)
const;
518 virtual void do_reset();
519 virtual bool do_set(
const std::string& str_value);
520 virtual std::string do_get_default_value()
const;
521 virtual std::string do_get_value_as_string()
const;
535 virtual void do_reset();
536 virtual bool do_set(
const std::string& str_value);
537 virtual std::string do_get_default_value()
const;
538 virtual std::string do_get_value_as_string()
const;
540 virtual void do_descr(std::ostream& os)
const;
541 virtual void do_get_help_xml(
CXMLElement&
self)
const;
542 virtual void do_add_dependend_handler(
HandlerHelpMap& handler_map)
const;
545 std::string& m_value;
546 std::string m_default_value;
610 template <
typename T>
613 typedef typename FactoryTrait<T>::type F;
632 template <
typename T>
635 typedef typename FactoryTrait<T>::type F;
648 template <
typename T>
649 struct __dispatch_param_translate {
650 static std::string apply(T x) {
651 std::ostringstream s;
658 struct __dispatch_param_translate<std::string> {
659 static std::string apply(
const std::string& x) {
665 struct __dispatch_param_translate<const char *> {
666 static std::string apply(
const char * x) {
667 return std::string(x);
673 template <
typename T>
677 m_default_value(value),
682 template <
typename T>
685 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
686 os <<
"\n " << i->second.first <<
": " << i->second.second;
690 template <
typename T>
695 for (
auto i = m_dict.get_help_begin(); i != m_dict.get_help_end(); ++i) {
703 template <
typename T>
706 m_value = m_dict.get_value(str_value.c_str());
710 template <
typename T>
713 m_value = m_default_value;
716 template <
typename T>
719 return m_dict.get_name(m_default_value);
722 template <
typename T>
725 return m_dict.get_name(m_value);
728 template <
typename F>
732 m_shared_value(value),
733 m_unique_value(dummy_unique_value),
734 m_string_value(init),
735 m_default_value(init),
740 template <
typename F>
743 m_shared_value(dummy_shared_value),
744 m_unique_value(value),
745 m_string_value(init),
746 m_default_value(init),
753 template <
typename T>
756 os <<
"For a list of available plug-ins see run 'mia-plugin-help " 757 << T::instance().get_descriptor() <<
"'";
760 template <
typename T>
767 template <
typename T>
770 m_string_value = str_value;
774 template <
typename T>
777 if (!m_string_value.empty()) {
779 m_unique_value = T::instance().produce_unique(m_string_value);
781 m_shared_value = T::instance().produce(m_string_value);
785 template <
typename T>
788 m_string_value = m_default_value;
791 template <
typename T>
795 if (handler_map.find(T::instance().get_descriptor()) == handler_map.end()){
796 handler_map[T::instance().get_descriptor()] = &T::instance();
797 for (
auto i = T::instance().begin(); i != T::instance().end(); ++i)
798 i->second->add_dependend_handlers(handler_map);
802 template <
typename T>
805 return m_default_value;
808 template <
typename T>
811 if (m_unique && m_unique_value)
812 return m_unique_value->get_init_string();
813 if (!m_unique && m_shared_value)
814 return m_shared_value->get_init_string();
815 return m_string_value;
818 template <
typename T>
822 m_default_value(value),
823 m_valid_set(valid_set)
825 if (m_valid_set.empty())
826 throw std::invalid_argument(
"CSetParameter initialized with empty set");
830 template <
typename T>
833 return __dispatch_param_translate<T>::apply(m_default_value);
836 template <
typename T>
839 return __dispatch_param_translate<T>::apply(m_value);
842 template <
typename T>
845 auto i = m_valid_set.begin();
846 auto e = m_valid_set.end();
850 os <<
" Supported values are (" << *i;
858 template <
typename T>
862 for (
auto i = m_valid_set.begin(); i != m_valid_set.end(); ++i) {
868 template <
typename T>
871 m_value = m_default_value;
874 template <
typename T>
877 std::stringstream s(str_value);
880 if (s.fail() || m_valid_set.find(val) == m_valid_set.end()) {
881 throw std::invalid_argument(
errmsg(str_value));
889 template <
typename T>
893 m_default_value(value)
899 template <
typename T>
905 template <
typename T>
908 std::stringstream s(str_value);
911 throw std::invalid_argument(
errmsg(str_value));
915 template <
typename T>
918 m_value = m_default_value;
921 template <
typename T>
924 std::ostringstream s;
925 s << m_default_value;
927 if (str.find(
',') != std::string::npos) {
928 std::ostringstream s2;
929 s2 <<
'[' << str <<
']';
935 template <
typename T>
938 return __dispatch_param_translate<T>::apply(m_value);
void descr(std::ostream &os) const
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)
void add_xmlhelp_text(CXMLElement &node, const std::string &value) const
TBoundedParameter< double > CDBoundedParameter
an float parameter, double accuracy (with possible boundaries)
TBoundedParameter< std::vector< float > > CVFBoundedParameter
an float parameter, single accuracy (with possible boundaries)
TBoundedParameter< uint16_t > 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.
const std::string errmsg(const std::string &err_value) const
create an error message by using the given value that raises the error
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)
void value(std::ostream &os) const
A parameter that can only assume values out of a limited set.
TBoundedParameter< int64_t > CSLBoundedParameter
an signed long parameter (with possible boundaries)
CTParameter< bool > CBoolParameter
boolean parameter
TBoundedParameter< std::vector< int16_t > > CVSSBoundedParameter
an signed short parameter (with possible boundaries)
#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.
TBoundedParameter< uint32_t > CUIBoundedParameter
an unsigned int parameter (with possible boundaries)
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
TBoundedParameter< int32_t > CSIBoundedParameter
an signed int parameter (with possible boundaries)
A parameter that can assume any value of the given value type.
TBoundedParameter< float > CFBoundedParameter
an float parameter, single accuracy (with possible boundaries)
TBoundedParameter< std::vector< uint16_t > > CVUSBoundedParameter
an unsigned short parameter (with possible boundaries)
virtual void do_descr(std::ostream &os) const
boundary< T >::value_type boundary_type
CParameter * make_uc_param(T &value, S upper_bound, bool required, const char *descr)
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)
CParameter * make_nonnegative_param(T &value, bool required, const char *descr)
TBoundedParameter< uint64_t > CULBoundedParameter
an unsigned long parameter (with possible boundaries)
void add_xmlhelp_attribute(CXMLElement &node, const std::string &tag, const std::string &value) const
TBoundedParameter< int16_t > CSSBoundedParameter
an signed short parameter (with possible boundaries)
CXMLElement & add_xmlhelp_childnode(CXMLElement &parent, const std::string &tag) const
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< std::vector< uint64_t > > CVULBoundedParameter
an unsigned long parameter (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)
IMPLEMENT_FLAG_OPERATIONS(EParameterBounds)
virtual void do_descr(std::ostream &os) const
TBoundedParameter< std::vector< int64_t > > CVSLBoundedParameter
an signed long parameter (with possible boundaries)
EXPORT_CORE std::ostream & operator<<(std::ostream &os, EParameterBounds flags)
TParameter(T &value, bool required, const char *descr)
TBoundedParameter< std::vector< double > > CVDBoundedParameter
an float parameter, double accuracy (with possible boundaries)
CDictParameter(T &value, const TDictMap< T > &dict, const char *descr, bool required=false)
A mapper from emums to string values. - usefull for names flags.
TBoundedParameter< std::vector< uint32_t > > CVUIBoundedParameter
an unsigned int parameter (with possible boundaries)
#define NS_MIA_END
conveniance define to end the mia namespace