Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Arg_Shifter Class Reference

This ADT shifts known args to the back of the argv vector, so deeper levels of argument parsing can locate the yet unprocessed arguments at the beginning of the vector. More...

#include <Arg_Shifter.h>

List of all members.

Public Methods

 ACE_Arg_Shifter (int& argc, ACE_TCHAR **argv, ACE_TCHAR **temp = 0)
 ~ACE_Arg_Shifter (void)
 Destructor.

ACE_TCHARget_current (void) const
 Get the current head of the vector.

ACE_TCHARget_the_parameter (const ACE_TCHAR* flag)
int cur_arg_strncasecmp (const ACE_TCHAR *flag)
int consume_arg (int number = 1)
 Consume <number> argument(s) by sticking them/it on the end of the vector.

int ignore_arg (int number = 1)
 Place <number> arguments in the same relative order ahead of the known arguemnts in the vector.

int is_anything_left (void) const
 Returns the number of args left to see in the vector.

int is_option_next (void) const
 Returns 1 if there's a next item in the vector and it begins with '-'.

int is_parameter_next (void) const
 Returns 1 if there's a next item in the vector and it doesn't begin with '-'.

int num_ignored_args (void) const
 Returns the number of irrelevant args seen.


Private Attributes

int& argc_
 The size of the argument vector.

int total_size_
 The size of argv_.

ACE_TCHAR** temp_
 The temporary array over which we traverse.

ACE_TCHAR** argv_
 The array in which the arguments are reordered.

int current_index_
 The element in <temp_> we're currently examining.

int back_
 The index of in which we'll stick the next unknown argument.

int front_
 The index of in which we'll stick the next known argument.


Detailed Description

This ADT shifts known args to the back of the argv vector, so deeper levels of argument parsing can locate the yet unprocessed arguments at the beginning of the vector.

The copies the pointers of the argv vector into a temporary array. As the iterates over the temp, is places known arguments in the rear of the argv and unknown ones in the beginning. So, after having visited all the arguments in the temp vector, has placed all the unknown arguments in their original order at the front of argv.


Constructor & Destructor Documentation

ACE_Arg_Shifter::ACE_Arg_Shifter ( int & argc,
ACE_TCHAR ** argv,
ACE_TCHAR ** temp = 0 ) [inline]
 

Initialize the to the vector over which to iterate, also providing the temporary array if the client doesn't want the arg_shifter to dynamically allocate its own. If internal dynamic allocation fails, the will set all the indices to the end of the vector, forbidding iteration. Following iteration over argv, the argc value will contain the number of unconsumed arguments.

ACE_Arg_Shifter::~ACE_Arg_Shifter ( void )
 

Destructor.


Member Function Documentation

int ACE_Arg_Shifter::consume_arg ( int number = 1 )
 

Consume <number> argument(s) by sticking them/it on the end of the vector.

int ACE_Arg_Shifter::cur_arg_strncasecmp ( const ACE_TCHAR * flag )
 

Check if the current argument matches (case insensitive) <flag>

------------------------------------------------------------

Case A: Perfect Match (case insensitive) 0 is returned.

ie: when current_arg = "-foobar" or "-FOOBAR" or "-fooBAR" this->cur_arg_strncasecmp ("-FooBar); will return 0

------------------------------------------------------------

Case B: Perfect Match (case insensitive) but the current_arg is longer than the flag. Returns a number equal to the index in the char* indicating the start of the extra characters

ie: when current_arg = "-foobar98023" this->cur_arg_strncasecmp ("-FooBar); will return 7

Notice: this number will always be > 0

------------------------------------------------------------

Case C: If neither of Case A or B is met (no match) then -1 is returned

ACE_TCHAR * ACE_Arg_Shifter::get_current ( void ) const
 

Get the current head of the vector.

ACE_TCHAR * ACE_Arg_Shifter::get_the_parameter ( const ACE_TCHAR * flag )
 

If the <flag> matches the current_arg of arg shifter this method will attempt to return the associated parameter value

Safe to call without checking that a current arg exists

In the following examples, a pointer to the char* "value" is ret

eg: main -foobar value, main -FooBar value main -FOOBARvalue

all of the above will all match the <flag> == -FooBar and will return a char* to "value"

main -foobar 4 would succeed and return a char* to "4" main -foobar -4 does not succeed (-4 is not a parameter) but instead, would return 0

0 is returned: If the current argument does not match flag If there is no parameter found after a 'matched' flag

If the flag is matched and the flag and paramter DO NOT RUN together, the flag is consumed, the parameter is returned, and the new current argument is the parameter value. ie '-foobarflag VALUE' leaves the new cur arg == "VALUE"

If the flag is matched and the flag and parameter RUN together '-foobarflagVALUE', the flag is NOT consumed and the cur arg is left pointing to the entire flag/value pair

int ACE_Arg_Shifter::ignore_arg ( int number = 1 )
 

Place <number> arguments in the same relative order ahead of the known arguemnts in the vector.

int ACE_Arg_Shifter::is_anything_left ( void ) const
 

Returns the number of args left to see in the vector.

int ACE_Arg_Shifter::is_option_next ( void ) const
 

Returns 1 if there's a next item in the vector and it begins with '-'.

int ACE_Arg_Shifter::is_parameter_next ( void ) const
 

Returns 1 if there's a next item in the vector and it doesn't begin with '-'.

int ACE_Arg_Shifter::num_ignored_args ( void ) const
 

Returns the number of irrelevant args seen.


Member Data Documentation

int & ACE_Arg_Shifter::argc_ [private]
 

The size of the argument vector.

ACE_TCHAR ** ACE_Arg_Shifter::argv_ [private]
 

The array in which the arguments are reordered.

int ACE_Arg_Shifter::back_ [private]
 

The index of in which we'll stick the next unknown argument.

int ACE_Arg_Shifter::current_index_ [private]
 

The element in <temp_> we're currently examining.

int ACE_Arg_Shifter::front_ [private]
 

The index of in which we'll stick the next known argument.

ACE_TCHAR ** ACE_Arg_Shifter::temp_ [private]
 

The temporary array over which we traverse.

int ACE_Arg_Shifter::total_size_ [private]
 

The size of argv_.


The documentation for this class was generated from the following files:
Generated at Fri Oct 5 07:01:03 2001 for ACE by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000