positional_parameter.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // (C) Copyright Gennadiy Rozental 2005-2008.
  2. // Use, modification, and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 54633 $
  10. //
  11. // Description : positional parameter model
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_CLA_POSITIONAL_PARAMETER_HPP_062604GER
  14. #define BOOST_RT_CLA_POSITIONAL_PARAMETER_HPP_062604GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. #include <boost/test/utils/runtime/cla/basic_parameter.hpp>
  18. namespace boost {
  19. namespace BOOST_RT_PARAM_NAMESPACE {
  20. namespace cla {
  21. // ************************************************************************** //
  22. // ************** trivial_id_policy ************** //
  23. // ************************************************************************** //
  24. class trivial_id_policy : public identification_policy {
  25. public:
  26. trivial_id_policy()
  27. : identification_policy( rtti::type_id<trivial_id_policy>() )
  28. {}
  29. BOOST_RT_PARAM_UNNEEDED_VIRTUAL ~trivial_id_policy() {}
  30. virtual bool responds_to( cstring name ) const { return m_name == name; }
  31. virtual bool conflict_with( identification_policy const& ) const { return false; }
  32. virtual cstring id_2_report() const { return m_name; }
  33. virtual void usage_info( format_stream& fs ) const
  34. {
  35. if( !m_name.empty() )
  36. fs << BOOST_RT_PARAM_LITERAL( '<' ) << m_name << BOOST_RT_PARAM_LITERAL( '>' );
  37. else
  38. fs << BOOST_RT_PARAM_CSTRING_LITERAL( "<value>" );
  39. }
  40. virtual bool matching( parameter const& p, argv_traverser&, bool primary ) const
  41. {
  42. return primary && ( !p.has_argument() || p.p_multiplicable );
  43. }
  44. template<typename Modifier>
  45. void accept_modifier( Modifier const& m )
  46. {
  47. nfp::optionally_assign( m_name, m, name );
  48. }
  49. private:
  50. // Data members
  51. dstring m_name;
  52. };
  53. // ************************************************************************** //
  54. // ************** runtime::cla::positional_parameter ************** //
  55. // ************************************************************************** //
  56. template<typename T>
  57. class positional_parameter_t : public basic_parameter<T,trivial_id_policy> {
  58. typedef basic_parameter<T,trivial_id_policy> base;
  59. public:
  60. // Constructors
  61. explicit positional_parameter_t( cstring name )
  62. : base( name )
  63. {}
  64. };
  65. //____________________________________________________________________________//
  66. BOOST_RT_CLA_NAMED_PARAM_GENERATORS( positional_parameter )
  67. } // namespace cla
  68. } // namespace BOOST_RT_PARAM_NAMESPACE
  69. } // namespace boost
  70. #endif // BOOST_RT_CLA_POSITIONAL_PARAMETER_HPP_062604GER