option.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_OPTION_HPP_VP_2004_02_25
  6. #define BOOST_OPTION_HPP_VP_2004_02_25
  7. #include <boost/program_options/config.hpp>
  8. #include <string>
  9. #include <vector>
  10. namespace boost { namespace program_options {
  11. /** Option found in input source.
  12. Contains a key and a value. The key, in turn, can be a string (name of
  13. an option), or an integer (position in input source) \-- in case no name
  14. is specified. The latter is only possible for command line.
  15. The template parameter specifies the type of char used for storing the
  16. option's value.
  17. */
  18. template<class charT>
  19. class basic_option {
  20. public:
  21. basic_option()
  22. : position_key(-1)
  23. , unregistered(false)
  24. , case_insensitive(false)
  25. {}
  26. basic_option(const std::string& xstring_key,
  27. const std::vector< std::string> &xvalue)
  28. : string_key(xstring_key)
  29. , position_key(-1)
  30. , value(xvalue)
  31. , unregistered(false)
  32. , case_insensitive(false)
  33. {}
  34. /** String key of this option. Intentionally independent of the template
  35. parameter. */
  36. std::string string_key;
  37. /** Position key of this option. All options without an explicit name are
  38. sequentially numbered starting from 0. If an option has explicit name,
  39. 'position_key' is equal to -1. It is possible that both
  40. position_key and string_key is specified, in case name is implicitly
  41. added.
  42. */
  43. int position_key;
  44. /** Option's value */
  45. std::vector< std::basic_string<charT> > value;
  46. /** The original unchanged tokens this option was
  47. created from. */
  48. std::vector< std::basic_string<charT> > original_tokens;
  49. /** True if option was not recognized. In that case,
  50. 'string_key' and 'value' are results of purely
  51. syntactic parsing of source. The original tokens can be
  52. recovered from the "original_tokens" member.
  53. */
  54. bool unregistered;
  55. /** True if string_key has to be handled
  56. case insensitive.
  57. */
  58. bool case_insensitive;
  59. };
  60. typedef basic_option<char> option;
  61. typedef basic_option<wchar_t> woption;
  62. }}
  63. #endif