|
- #pragma once
-
- #include <cpputils/mp.h>
-
- #include "group.h"
-
- namespace cppargs
- {
-
- template<typename T_arg, typename T_enable = void>
- struct group_init;
-
- template<typename T_arg>
- struct group_init<
- std::unique_ptr<T_arg>,
- utl::mp::enable_if<utl::mp::is_base_of<option, T_arg>>>
- {
- using option_ptr_type = std::unique_ptr<option>;
- using option_vector_type = std::vector<option_ptr_type>;
- using group_ptr_type = std::unique_ptr<group>;
- using group_vector_type = std::vector<group_ptr_type>;
-
- option_vector_type& options;
- group_vector_type& groups;
-
- template<typename X>
- void operator()(X&& x)
- { options.emplace_back(std::forward<X>(x)); }
- };
-
- template<typename T_arg>
- struct group_init<
- std::unique_ptr<T_arg>,
- utl::mp::enable_if<utl::mp::is_base_of<group, T_arg>>>
- {
- using option_ptr_type = std::unique_ptr<option>;
- using option_vector_type = std::vector<option_ptr_type>;
- using group_ptr_type = std::unique_ptr<group>;
- using group_vector_type = std::vector<group_ptr_type>;
-
- option_vector_type& options;
- group_vector_type& groups;
-
- template<typename X>
- void operator()(X&& x)
- { groups.emplace_back(std::forward<X>(x)); }
- };
-
- group_meta& group_meta::set_name(const std::string& value)
- {
- name = value;
- return *this;
- }
-
- group_meta& group_meta::set_description(const std::string& value)
- {
- description = value;
- return *this;
- }
-
- template<typename... T_args>
- group::group(
- const group_meta& p_meta,
- T_args&&... p_args)
- : meta(p_meta)
- {
- (void) (int[]) { 0, (group_init<T_args> { _options, _groups } (std::forward<T_args>(p_args)), 0)... };
- }
-
- const group::option_vector_type& group::options() const
- { return _options; }
-
- const group::group_vector_type& group::groups() const
- { return _groups; }
-
- }
|