Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:42

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Use, modification, and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  File        : $RCSfile$
0009 //
0010 //  Version     : $Revision$
0011 //
0012 //  Description : defines facility to hide input traversing details
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP
0016 #define BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP
0017 
0018 // Boost.Test Runtime parameters
0019 #include <boost/test/utils/runtime/fwd.hpp>
0020 #include <cstring>
0021 
0022 #include <boost/test/detail/suppress_warnings.hpp>
0023 
0024 namespace boost {
0025 namespace runtime {
0026 namespace cla {
0027 
0028 // ************************************************************************** //
0029 // **************          runtime::cla::argv_traverser        ************** //
0030 // ************************************************************************** //
0031 
0032 class argv_traverser {
0033     typedef char const** argv_type;
0034 public:
0035     /// Constructs traverser based on argc/argv pair
0036     /// argv is taken "by reference" and later can be
0037     /// updated in remainder method
0038     argv_traverser( int argc, argv_type argv )
0039     : m_argc( argc )
0040     , m_curr_token( 0 )
0041     , m_token_size( 0 )
0042     , m_argv( argv )
0043     {
0044         // save program name
0045         save_token();
0046     }
0047 
0048     /// Returns new argc
0049     int         remainder()
0050     {
0051         return static_cast<int>(m_argc);
0052     }
0053 
0054     /// Returns true, if we reached end on input
0055     bool        eoi() const
0056     {
0057         return m_curr_token == m_argc;
0058     }
0059 
0060     /// Returns current token in the input
0061     cstring     current_token()
0062     {
0063         if( eoi() )
0064             return cstring();
0065 
0066         return cstring( m_argv[m_curr_token], m_token_size );
0067     }
0068 
0069     /// Saves current token for remainder
0070     void        save_token()
0071     {
0072         ++m_curr_token;
0073 
0074         if( !eoi() )
0075             m_token_size = ::strlen( m_argv[m_curr_token] );
0076     }
0077 
0078     /// Commit current token and iterate to next one
0079     void        next_token()
0080     {
0081         if( !eoi() ) {
0082             for( std::size_t i = m_curr_token; i < m_argc-1; ++i )
0083                 m_argv[i] = m_argv[i + 1];
0084 
0085             --m_argc;
0086 
0087             m_token_size = ::strlen( m_argv[m_curr_token] );
0088         }
0089     }
0090 
0091 private:
0092 
0093     // Data members
0094     std::size_t m_argc;         // total number of arguments
0095     std::size_t m_curr_token;   // current token index in argv
0096     std::size_t m_token_size;   // current token size
0097     argv_type   m_argv;         // all arguments
0098 };
0099 
0100 } // namespace cla
0101 } // namespace runtime
0102 } // namespace boost
0103 
0104 #include <boost/test/detail/enable_warnings.hpp>
0105 
0106 #endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP