positional_options.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef BOOST_PROGRAM_OPTIONS_POSITIONAL_OPTIONS_VP_2004_03_02
  6. #define BOOST_PROGRAM_OPTIONS_POSITIONAL_OPTIONS_VP_2004_03_02
  7. #include <boost/program_options/config.hpp>
  8. #include <vector>
  9. #include <string>
  10. #if defined(BOOST_MSVC)
  11. # pragma warning (push)
  12. # pragma warning (disable:4251) // class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'boost::program_options::positional_options_description'
  13. #endif
  14. namespace boost { namespace program_options {
  15. /** Describes positional options.
  16. The class allows to guess option names for positional options, which
  17. are specified on the command line and are identified by the position.
  18. The class uses the information provided by the user to associate a name
  19. with every positional option, or tell that no name is known.
  20. The primary assumption is that only the relative order of the
  21. positional options themselves matters, and that any interleaving
  22. ordinary options don't affect interpretation of positional options.
  23. The user initializes the class by specifying that first N positional
  24. options should be given the name X1, following M options should be given
  25. the name X2 and so on.
  26. */
  27. class BOOST_PROGRAM_OPTIONS_DECL positional_options_description {
  28. public:
  29. positional_options_description();
  30. /** Species that up to 'max_count' next positional options
  31. should be given the 'name'. The value of '-1' means 'unlimited'.
  32. No calls to 'add' can be made after call with 'max_value' equal to
  33. '-1'.
  34. */
  35. positional_options_description&
  36. add(const char* name, int max_count);
  37. /** Returns the maximum number of positional options that can
  38. be present. Can return (numeric_limits<unsigned>::max)() to
  39. indicate unlimited number. */
  40. unsigned max_total_count() const;
  41. /** Returns the name that should be associated with positional
  42. options at 'position'.
  43. Precondition: position < max_total_count()
  44. */
  45. const std::string& name_for_position(unsigned position) const;
  46. private:
  47. // List of names corresponding to the positions. If the number of
  48. // positions is unlimited, then the last name is stored in
  49. // m_trailing;
  50. std::vector<std::string> m_names;
  51. std::string m_trailing;
  52. };
  53. }}
  54. #if defined(BOOST_MSVC)
  55. # pragma warning (pop)
  56. #endif
  57. #endif