argv_traverser.hpp 2.7 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: 57992 $
  10. //
  11. // Description : defines facility to hide input traversing details
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_CLA_ARGV_TRAVERSER_HPP_062604GER
  14. #define BOOST_RT_CLA_ARGV_TRAVERSER_HPP_062604GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. // Boost.Test
  18. #include <boost/test/utils/class_properties.hpp>
  19. // Boost
  20. #include <boost/noncopyable.hpp>
  21. #include <boost/shared_array.hpp>
  22. namespace boost {
  23. namespace BOOST_RT_PARAM_NAMESPACE {
  24. namespace cla {
  25. // ************************************************************************** //
  26. // ************** runtime::cla::argv_traverser ************** //
  27. // ************************************************************************** //
  28. class argv_traverser : noncopyable {
  29. class parser;
  30. public:
  31. // Constructor
  32. argv_traverser();
  33. // public_properties
  34. unit_test::readwrite_property<bool> p_ignore_mismatch;
  35. unit_test::readwrite_property<char_type> p_separator;
  36. // argc+argv <-> internal buffer exchange
  37. void init( int argc, char_type** argv );
  38. void remainder( int& argc, char_type** argv );
  39. // token based parsing
  40. cstring token() const;
  41. void next_token();
  42. // whole input parsing
  43. cstring input() const;
  44. void trim( std::size_t size );
  45. bool match_front( cstring );
  46. bool match_front( char_type c );
  47. bool eoi() const;
  48. // transaction logic support
  49. void commit();
  50. void rollback();
  51. // current position access; used to save some reference points in input
  52. std::size_t input_pos() const;
  53. // returns true if mismatch detected during input parsing handled successfully
  54. bool handle_mismatch();
  55. private:
  56. // Data members
  57. dstring m_buffer;
  58. cstring m_work_buffer;
  59. cstring m_token;
  60. cstring::iterator m_commited_end;
  61. shared_array<char_type> m_remainder;
  62. std::size_t m_remainder_size;
  63. };
  64. } // namespace cla
  65. } // namespace BOOST_RT_PARAM_NAMESPACE
  66. } // namespace boost
  67. #ifndef BOOST_RT_PARAM_OFFLINE
  68. # define BOOST_RT_PARAM_INLINE inline
  69. # include <boost/test/utils/runtime/cla/argv_traverser.ipp>
  70. #endif
  71. #endif // BOOST_RT_CLA_ARGV_TRAVERSER_HPP_062604GER