diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index b27b56f..8afb8dc 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -256,6 +256,10 @@ namespace cxxopts { public: + virtual + std::shared_ptr + clone() const = 0; + virtual void parse(const std::string& text) const = 0; @@ -694,6 +698,8 @@ namespace cxxopts template class standard_value : public Value { + using Self = standard_value; + public: standard_value() : m_result(std::make_shared()) @@ -706,6 +712,28 @@ namespace cxxopts { } + std::shared_ptr + clone() const + { + std::shared_ptr copy; + + if (m_result) + { + copy = std::make_shared(m_store); + } + else + { + copy = std::make_shared(); + } + + copy->m_default = m_default; + copy->m_implicit = m_implicit; + copy->m_default_value = m_default_value; + copy->m_implicit_value = m_implicit_value; + + return copy; + } + void parse(const std::string& text) const { @@ -825,6 +853,15 @@ namespace cxxopts { } + OptionDetails(const OptionDetails& rhs) + : m_desc(rhs.m_desc) + , m_count(rhs.m_count) + { + m_value = rhs.m_value->clone(); + } + + OptionDetails(OptionDetails&& rhs) = default; + const String& description() const { @@ -1202,10 +1239,17 @@ ParseResult::ParseResult(Iterator begin, Iterator end, std::vector positional, int& argc, char**& argv ) -: m_options(begin, end) -, m_positional(std::move(positional)) +: m_positional(std::move(positional)) , m_next_positional(m_positional.begin()) { + for (auto current = begin; current != end; ++current) + { + m_options.insert({ + current->first, + std::make_shared(*current->second) + }); + } + parse(argc, argv); }