Add C++ bindings master
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 6 Sep 2024 14:49:01 +0000 (10:49 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 6 Sep 2024 19:21:29 +0000 (15:21 -0400)
commita80b22c5f492e2ba0c249be98fb7dc07b5ef1abb
tree5fb5f6834d453d5523d227c5424b6a8dd8ecab6b
parent3364251abec12da42cb42ce049885248a69ea15b
Add C++ bindings

Add argpar.hpp, providing C++ bindings around the argpar public API.

 - Everything is under the `argpar` namespace.
 - Create an argpar argument iterator with the `Iter` constructor:

     Iter(unsigned int argc, const char * const *argv,
  const argpar_opt_descr_t *descrs);

   For simplicity and to avoid adding unnecessary costs to the
   abstraction, the constructor accepts an array of
   `argpar_opt_descr_t`.
 - Call next() to obtain the next item.  If the end of the command line
   has been reached, an empty optional is returned.
 - Differentiate between opt and non-opt argument items using
   argpar::Item::type(), argpar::Item::isOpt() or
   argpar::Item::isNonOpt().
 - Parse errors are reported using exceptions.  Specific exception types
   derive from `argpar::Error`.

Improve the testsuite to cover the C++ API.  The test program is now
split in 3 files:

 - test-argpar-c.c: provides the test_succeed_c() and test_fail_c()
   functions, testing a given case using the C API.
 - test-argpar-cxx.cpp: provides the testSucceedCxx() and testFailCxx()
   functions, testing a given case using the C++ API.
 - test-argpar.cpp: contains the test cases, calls the C and C++ test
   functions for each case.

Make configure look for a C++11 compiler.  Add the necessary m4 files
from autoconf-archive.

In the C++ test, we need an `optional` type to provide as a template
parameter of `argpar::Iter`.  Given that we compile as C++11, we can't
use `std::optional`.  Add a copy of `optional.hpp` from the
optional-lite project [1].

Add a copy of the {fmt} library [2], in order to format strings
conveniently in the test.

Philippe updated `README.adoc` to mention the new C++ API.

[1] https://github.com/martinmoene/optional-lite
[2] https://github.com/fmtlib/fmt

Change-Id: Iacf4da8837e8dea79b770346f6fcf3406f0668db
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
31 files changed:
LICENSES/BSL-1.0.txt [new file with mode: 0644]
Makefile.am
README.adoc
REUSE.toml [new file with mode: 0644]
argpar/argpar.hpp [new file with mode: 0644]
configure.ac
m4/ax_cxx_compile_stdcxx.m4 [new file with mode: 0644]
m4/ax_cxx_compile_stdcxx_11.m4 [new file with mode: 0644]
tests/Makefile.am
tests/test-argpar-c.c [new file with mode: 0644]
tests/test-argpar-c.h [new file with mode: 0644]
tests/test-argpar-cxx.cpp [new file with mode: 0644]
tests/test-argpar-cxx.hpp [new file with mode: 0644]
tests/test-argpar.c [deleted file]
tests/test-argpar.cpp [new file with mode: 0644]
tests/vendor/fmt/args.h [new file with mode: 0644]
tests/vendor/fmt/base.h [new file with mode: 0644]
tests/vendor/fmt/chrono.h [new file with mode: 0644]
tests/vendor/fmt/color.h [new file with mode: 0644]
tests/vendor/fmt/compile.h [new file with mode: 0644]
tests/vendor/fmt/core.h [new file with mode: 0644]
tests/vendor/fmt/format-inl.h [new file with mode: 0644]
tests/vendor/fmt/format.h [new file with mode: 0644]
tests/vendor/fmt/os.h [new file with mode: 0644]
tests/vendor/fmt/ostream.h [new file with mode: 0644]
tests/vendor/fmt/printf.h [new file with mode: 0644]
tests/vendor/fmt/ranges.h [new file with mode: 0644]
tests/vendor/fmt/std.h [new file with mode: 0644]
tests/vendor/fmt/xchar.h [new file with mode: 0644]
tests/vendor/optional-lite/optional.hpp [new file with mode: 0644]
tests/vendor/optional-lite/optional.hpp.license [new file with mode: 0644]
This page took 0.024603 seconds and 4 git commands to generate.