summaryrefslogtreecommitdiff
path: root/boost/test/utils/runtime/cla/argv_traverser.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/test/utils/runtime/cla/argv_traverser.hpp')
-rw-r--r--boost/test/utils/runtime/cla/argv_traverser.hpp133
1 files changed, 69 insertions, 64 deletions
diff --git a/boost/test/utils/runtime/cla/argv_traverser.hpp b/boost/test/utils/runtime/cla/argv_traverser.hpp
index 6f6e03dfc8..10fb67bde4 100644
--- a/boost/test/utils/runtime/cla/argv_traverser.hpp
+++ b/boost/test/utils/runtime/cla/argv_traverser.hpp
@@ -1,4 +1,4 @@
-// (C) Copyright Gennadiy Rozental 2005-2014.
+// (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)
@@ -15,86 +15,91 @@
#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP
#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP
-// Boost.Runtime.Parameter
-#include <boost/test/utils/runtime/config.hpp>
+// Boost.Test Runtime parameters
+#include <boost/test/utils/runtime/fwd.hpp>
-// Boost.Test
-#include <boost/test/utils/class_properties.hpp>
-
-// Boost
-#include <boost/noncopyable.hpp>
-#include <boost/shared_array.hpp>
+#include <boost/test/detail/suppress_warnings.hpp>
namespace boost {
-
-namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE {
-
+namespace runtime {
namespace cla {
// ************************************************************************** //
// ************** runtime::cla::argv_traverser ************** //
// ************************************************************************** //
-class argv_traverser : noncopyable {
- class parser;
+class argv_traverser {
+ typedef char const** argv_type;
public:
- // Constructor
- argv_traverser();
-
- // public_properties
- unit_test::readwrite_property<bool> p_ignore_mismatch;
- unit_test::readwrite_property<char_type> p_separator;
-
- // argc+argv <-> internal buffer exchange
- void init( int argc, char_type** argv );
- void remainder( int& argc, char_type** argv );
-
- // token based parsing
- cstring token() const;
- void next_token();
-
- // whole input parsing
- cstring input() const;
- void trim( std::size_t size );
- bool match_front( cstring );
- bool match_front( char_type c );
- bool eoi() const;
-
- // transaction logic support
- void commit();
- void rollback();
-
- // current position access; used to save some reference points in input
- std::size_t input_pos() const;
-
- // returns true if mismatch detected during input parsing handled successfully
- bool handle_mismatch();
+ /// 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
- dstring m_buffer;
- cstring m_work_buffer;
- cstring m_token;
- cstring::iterator m_commited_end;
-
- shared_array<char_type> m_remainder;
- std::size_t m_remainder_size;
+ // 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 BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE
-
+} // namespace runtime
} // namespace boost
-#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE
-
-#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE
-# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline
-#endif
-# include <boost/test/utils/runtime/cla/argv_traverser.ipp>
-
-#endif
+#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP