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#define BOOST_PROGRAM_OPTIONS_SOURCE
7#include <boost/program_options/config.hpp>
8
9#include <boost/program_options/positional_options.hpp>
10
11#include <boost/limits.hpp>
12
13#include <cassert>
14
15namespace boost { namespace program_options {
16
17 positional_options_description::positional_options_description()
18 {}
19
20 positional_options_description&
21 positional_options_description::add(const char* name, int max_count)
22 {
23 assert(max_count != -1 || m_trailing.empty());
24
25 if (max_count == -1)
26 m_trailing = name;
27 else {
28 m_names.resize(m_names.size() + max_count, name);
29 }
30 return *this;
31 }
32
33 unsigned
34 positional_options_description::max_total_count() const
35 {
36 return m_trailing.empty() ?
37 static_cast<unsigned>(m_names.size()) : (std::numeric_limits<unsigned>::max)();
38 }
39
40 const std::string&
41 positional_options_description::name_for_position(unsigned position) const
42 {
43 assert(position < max_total_count());
44
45 if (position < m_names.size())
46 return m_names[position];
47 else
48 return m_trailing;
49 }
50
51
52}}
53
54