1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// (C) Copyright Gennadiy Rozental 2001.
// Use, modification, and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : defines facility to hide input traversing details
// ***************************************************************************
#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP
#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP
// Boost.Test Runtime parameters
#include <boost/test/utils/runtime/fwd.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
namespace boost {
namespace runtime {
namespace cla {
// ************************************************************************** //
// ************** runtime::cla::argv_traverser ************** //
// ************************************************************************** //
class argv_traverser {
typedef char const** argv_type;
public:
/// Constructs traverser based on argc/argv pair
/// argv is taken "by reference" and later can be
/// updated in remainder method
argv_traverser( int argc, argv_type argv )
: m_argc( argc )
, m_curr_token( 0 )
, m_token_size( 0 )
, m_argv( argv )
{
// save program name
save_token();
}
/// Returns new argc
int remainder()
{
return m_argc;
}
/// Returns true, if we reached end on input
bool eoi() const
{
return m_curr_token == m_argc;
}
/// Returns current token in the input
cstring current_token()
{
if( eoi() )
return cstring();
return cstring( m_argv[m_curr_token], m_token_size );
}
/// Saves current token for remainder
void save_token()
{
++m_curr_token;
if( !eoi() )
m_token_size = ::strlen( m_argv[m_curr_token] );
}
/// Commit current token and iterate to next one
void next_token()
{
if( !eoi() ) {
for( std::size_t i = m_curr_token; i < m_argc-1; ++i )
m_argv[i] = m_argv[i + 1];
--m_argc;
m_token_size = ::strlen( m_argv[m_curr_token] );
}
}
private:
// Data members
std::size_t m_argc; // total number of arguments
std::size_t m_curr_token; // current token index in argv
std::size_t m_token_size; // current token size
argv_type m_argv; // all arguments
};
} // namespace cla
} // namespace runtime
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP
|