diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-05-01 22:25:06 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-05-01 22:25:06 +0000 |
commit | f593488b605fda12edbba21da69aa53324771539 (patch) | |
tree | d9ffc2eb44823eee15a6cd1e69b9fbe64a5c6616 /ace/Arg_Shifter.cpp | |
parent | e4302aeff3f0cd1e5a5ee79916fb3998aac88732 (diff) | |
download | ATCD-f593488b605fda12edbba21da69aa53324771539.tar.gz |
*** empty log message ***
Diffstat (limited to 'ace/Arg_Shifter.cpp')
-rw-r--r-- | ace/Arg_Shifter.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/ace/Arg_Shifter.cpp b/ace/Arg_Shifter.cpp new file mode 100644 index 00000000000..a988fa27928 --- /dev/null +++ b/ace/Arg_Shifter.cpp @@ -0,0 +1,117 @@ +// $Id$ + +#include "Arg_Shifter.h" + +ACE_Arg_Shifter::ACE_Arg_Shifter (int &argc, char **argv, char **temp) + : argc_ (argc), + total_size_ (argc), + temp_ (temp), + argv_ (argv), + current_index_ (0), + back_ (argc - 1), + front_ (0) +{ + // If not provided with one, allocate a temporary array. + if (this->temp_ == 0) + this->temp_ = new char *[this->total_size_]; + + if (this->temp_ != 0) + { + // Fill the temporary array. + this->argc_ = 0; + for (int i = 0; i < this->total_size_; i++) + { + this->temp_[i] = this->argv_[i]; + this->argv_[i] = 0; + } + } + else + { + // Allocation failed, prohibit iteration. + this->current_index_ = this->argc_; + this->front_ = this->argc_; + } +} + +ACE_Arg_Shifter::~ACE_Arg_Shifter (void) +{ + // Delete the temporary vector. + delete [] temp_; +} + +char * +ACE_Arg_Shifter::get_current (void) const +{ + char *return_value = 0; + + if (this->is_anything_left ()) + return_value = this->temp_[current_index_]; + + return return_value; +} + +int +ACE_Arg_Shifter::consume_arg (int number) +{ + int return_value = 0; + + // Stick knowns at the end of the vector (consumed). + if (this->is_anything_left() >= number) + { + for (int i = 0, j = this->back_ - (number - 1); + i < number; + i++, j++, this->current_index_++) + this->argv_[j] = this->temp_[this->current_index_]; + + this->back_ -= number; + return_value = 1; + } + + return return_value; +} + +int +ACE_Arg_Shifter::ignore_arg (int number) +{ + int return_value = 0; + + // Keep unknowns at the head of the vector. + if (this->is_anything_left () >= number) + { + for (int i = 0; + i < number; + i++, this->current_index_++, this->front_++) + this->argv_[this->front_] = this->temp_[this->current_index_]; + + return_value = 1; + this->argc_ += number; + } + + return return_value; +} + +int +ACE_Arg_Shifter::is_anything_left (void) const +{ + return this->total_size_ - this->current_index_; +} + +int +ACE_Arg_Shifter::is_option_next (void) const +{ + return this->is_anything_left () && + this->temp_[this->current_index_][0] == '-'; +} + +int +ACE_Arg_Shifter::is_parameter_next (void) const +{ + return this->is_anything_left () + && this->temp_[this->current_index_][0] != '-'; +} + +int +ACE_Arg_Shifter::num_ignored_args (void) const +{ + return this->front_; +} |