1 | // Copyright Vladimir Prus 2004. |
---|---|
2 | // Distributed under the Boost Software License, Version 1.0. |
3 | // (See accompanying file LICENSE_1_0.txt |
4 | // or copy at http://www.boost.org/LICENSE_1_0.txt) |
5 | |
6 | #ifndef BOOST_PROGRAM_OPTIONS_SOURCE |
7 | # define BOOST_PROGRAM_OPTIONS_SOURCE |
8 | #endif |
9 | #include <boost/program_options/config.hpp> |
10 | |
11 | #include <boost/program_options/positional_options.hpp> |
12 | |
13 | #include <boost/limits.hpp> |
14 | |
15 | #include <cassert> |
16 | |
17 | namespace boost { namespace program_options { |
18 | |
19 | positional_options_description::positional_options_description() |
20 | {} |
21 | |
22 | positional_options_description& |
23 | positional_options_description::add(const char* name, int max_count) |
24 | { |
25 | assert(max_count != -1 || m_trailing.empty()); |
26 | |
27 | if (max_count == -1) |
28 | m_trailing = name; |
29 | else { |
30 | m_names.resize(new_size: m_names.size() + max_count, x: name); |
31 | } |
32 | return *this; |
33 | } |
34 | |
35 | unsigned |
36 | positional_options_description::max_total_count() const |
37 | { |
38 | return m_trailing.empty() ? |
39 | static_cast<unsigned>(m_names.size()) : (std::numeric_limits<unsigned>::max)(); |
40 | } |
41 | |
42 | const std::string& |
43 | positional_options_description::name_for_position(unsigned position) const |
44 | { |
45 | assert(position < max_total_count()); |
46 | |
47 | if (position < m_names.size()) |
48 | return m_names[position]; |
49 | else |
50 | return m_trailing; |
51 | } |
52 | |
53 | |
54 | }} |
55 | |
56 |