char_parameter.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 : defines model of parameter with single char name
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_CLA_CHAR_PARAMETER_HPP_062604GER
  14. #define BOOST_RT_CLA_CHAR_PARAMETER_HPP_062604GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. #include <boost/test/utils/runtime/validation.hpp>
  18. #include <boost/test/utils/runtime/cla/basic_parameter.hpp>
  19. #include <boost/test/utils/runtime/cla/id_policy.hpp>
  20. namespace boost {
  21. namespace BOOST_RT_PARAM_NAMESPACE {
  22. namespace cla {
  23. // ************************************************************************** //
  24. // ************** char_name_policy ************** //
  25. // ************************************************************************** //
  26. class char_name_policy : public basic_naming_policy {
  27. public:
  28. // Constructor
  29. char_name_policy();
  30. BOOST_RT_PARAM_UNNEEDED_VIRTUAL ~char_name_policy() {}
  31. // policy interface
  32. virtual bool conflict_with( identification_policy const& ) const;
  33. // Accept modifier
  34. template<typename Modifier>
  35. void accept_modifier( Modifier const& m )
  36. {
  37. basic_naming_policy::accept_modifier( m );
  38. BOOST_RT_PARAM_VALIDATE_LOGIC( p_name->size() <= 1, "Invalid parameter name " << p_name );
  39. }
  40. };
  41. // ************************************************************************** //
  42. // ************** runtime::cla::char_parameter ************** //
  43. // ************************************************************************** //
  44. template<typename T>
  45. class char_parameter_t : public basic_parameter<T,char_name_policy> {
  46. typedef basic_parameter<T,char_name_policy> base;
  47. public:
  48. // Constructors
  49. explicit char_parameter_t( char_type name ) : base( cstring( &name, 1 ) ) {}
  50. };
  51. //____________________________________________________________________________//
  52. template<typename T>
  53. inline shared_ptr<char_parameter_t<T> >
  54. char_parameter( char_type name )
  55. {
  56. return shared_ptr<char_parameter_t<T> >( new char_parameter_t<T>( name ) );
  57. }
  58. //____________________________________________________________________________//
  59. inline shared_ptr<char_parameter_t<cstring> >
  60. char_parameter( char_type name )
  61. {
  62. return shared_ptr<char_parameter_t<cstring> >( new char_parameter_t<cstring>( name ) );
  63. }
  64. //____________________________________________________________________________//
  65. } // namespace cla
  66. } // namespace BOOST_RT_PARAM_NAMESPACE
  67. } // namespace boost
  68. #ifndef BOOST_RT_PARAM_OFFLINE
  69. # define BOOST_RT_PARAM_INLINE inline
  70. # include <boost/test/utils/runtime/cla/char_parameter.ipp>
  71. #endif
  72. #endif // BOOST_RT_CLA_CHAR_PARAMETER_HPP_062604GER