Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Fix Windows compilation, add "reset" of Options
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Aug 2, 2021
1 parent f88c008 commit edef8cf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# (__) \__/(__) \____/

# This file is part of popl (program options parser lib)
# Copyright (C) 2015-2019 Johannes Pohl
# Copyright (C) 2015-2021 Johannes Pohl

# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.
Expand All @@ -18,7 +18,7 @@ if (CMAKE_VERSION VERSION_LESS "3.1")
else ()
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(PROJECT_VERSION "1.2.90")
set(PROJECT_VERSION "1.3.0")
endif ()


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ popl is a C++ command line arguments parser that supports the same set of option
* No external dependencies, just C++11
* Platform independent
* Supports the same set of options as GNU's `getopt`: short options, long options, non-option arguments, ...
* Supports parsing of `ini` files
* Templatized option parsing: arguments are directly casted into the desired target type
* Automatic creation of a usage message
* Console help message
Expand Down
2 changes: 1 addition & 1 deletion example/popl_example.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
This file is part of popl (program options parser lib)
Copyright (C) 2015-2019 Johannes Pohl
Copyright (C) 2015-2021 Johannes Pohl
This software may be modified and distributed under the terms
of the MIT license. See the LICENSE file for details.
Expand Down
34 changes: 22 additions & 12 deletions include/popl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
( _ \ / \( _ \( )
) __/( O )) __// (_/\
(__) \__/(__) \____/
version 1.2.90
version 1.3.0
https://github.com/badaix/popl
This file is part of popl (program options parser lib)
Copyright (C) 2015-2019 Johannes Pohl
Copyright (C) 2015-2021 Johannes Pohl
This software may be modified and distributed under the terms
of the MIT license. See the LICENSE file for details.
Expand All @@ -33,12 +33,15 @@
#include <sstream>
#include <stdexcept>
#include <vector>
#ifdef WINDOWS
#include <cctype>
#endif


namespace popl
{

#define POPL_VERSION "1.2.90"
#define POPL_VERSION "1.3.0"


/// Option's argument type
Expand Down Expand Up @@ -338,6 +341,9 @@ class OptionParser
/// @param argv command line arguments
void parse(int argc, const char* const argv[]);

/// Delete all parsed options
void reset();

/// Produce a help message
/// @param max_attribute show options up to this level (optional, advanced, expert)
/// @return the help message
Expand Down Expand Up @@ -761,8 +767,10 @@ inline void Value<T>::update_reference()
{
if (this->assign_to_)
{
if (this->is_set() || default_)
*this->assign_to_ = value();
if (!this->is_set() && default_)
*this->assign_to_ = *default_;
else if (this->is_set())
*this->assign_to_ = values_.back();
}
}

Expand Down Expand Up @@ -977,8 +985,6 @@ inline void OptionParser::parse(const std::string& ini_filename)
Option_ptr option = find_option(key);
if (option && (option->attribute() == Attribute::inactive))
option = nullptr;
// if (option && (option->argument_type() != Argument::required))
// option = nullptr;

if (option)
option->parse(OptionName::long_name, key_value.second.c_str());
Expand All @@ -989,11 +995,6 @@ inline void OptionParser::parse(const std::string& ini_filename)

inline void OptionParser::parse(int argc, const char* const argv[])
{
unknown_options_.clear();
non_option_args_.clear();
for (auto& opt : options_)
opt->clear();

for (int n = 1; n < argc; ++n)
{
const std::string arg(argv[n]);
Expand Down Expand Up @@ -1094,6 +1095,15 @@ inline void OptionParser::parse(int argc, const char* const argv[])
}


inline void OptionParser::reset()
{
unknown_options_.clear();
non_option_args_.clear();
for (auto& opt : options_)
opt->clear();
}


inline std::string OptionParser::help(const Attribute& max_attribute) const
{
ConsoleOptionPrinter option_printer(this);
Expand Down
2 changes: 1 addition & 1 deletion test/test_main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
This file is part of popl (program options parser lib)
Copyright (C) 2015-2019 Johannes Pohl
Copyright (C) 2015-2021 Johannes Pohl
This software may be modified and distributed under the terms
of the MIT license. See the LICENSE file for details.
Expand Down

0 comments on commit edef8cf

Please sign in to comment.