diff options
author | john_c <john_c@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2006-05-08 23:00:05 +0000 |
---|---|---|
committer | john_c <john_c@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2006-05-08 23:00:05 +0000 |
commit | d1160e68b1301a8b0e120ba8da56bb2e7d4fb49e (patch) | |
tree | cf04398acb7ad9fb45311eb105d60975028bbc03 /ace/Arg_Shifter.cpp | |
parent | 1c3dd540264435be21072a3a69a8a8e969bd2b1a (diff) | |
download | ATCD-d1160e68b1301a8b0e120ba8da56bb2e7d4fb49e.tar.gz |
Fri May 5 14:33:29 UTC 2006 Ciju John <john_c@ociweb.com>oci_wchar_refactor_post_1_5_1_branch
Diffstat (limited to 'ace/Arg_Shifter.cpp')
-rw-r--r-- | ace/Arg_Shifter.cpp | 214 |
1 files changed, 8 insertions, 206 deletions
diff --git a/ace/Arg_Shifter.cpp b/ace/Arg_Shifter.cpp index 3c2ebd9fe08..f29f2522ca7 100644 --- a/ace/Arg_Shifter.cpp +++ b/ace/Arg_Shifter.cpp @@ -1,212 +1,14 @@ #include "ace/Arg_Shifter.h" -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_strings.h" -#include "ace/OS_Errno.h" -#include "ace/OS_Memory.h" + +#if !defined (__ACE_INLINE__) +#include "ace/Arg_Shifter.inl" +#endif /* __ACE_INLINE__ */ + ACE_RCSID (ace, Arg_Shifter, "$Id$") - -ACE_BEGIN_VERSIONED_NAMESPACE_DECL - -ACE_Arg_Shifter::ACE_Arg_Shifter (int& argc, - const ACE_TCHAR** argv, - const ACE_TCHAR** temp) - : argc_ (argc), - total_size_ (argc), - temp_ (temp), - argv_ (argv), - current_index_ (0), - back_ (argc - 1), - front_ (0) -{ - this->init (); -} - -ACE_Arg_Shifter::ACE_Arg_Shifter (int& argc, - ACE_TCHAR** argv, - ACE_TCHAR** temp) - : argc_ (argc), - total_size_ (argc), - temp_ ((const ACE_TCHAR **) temp), - argv_ ((const ACE_TCHAR **) argv), - current_index_ (0), - back_ (argc - 1), - front_ (0) -{ - this->init (); -} - -void -ACE_Arg_Shifter::init (void) -{ - // If not provided with one, allocate a temporary array. - if (this->temp_ == 0) - ACE_NEW (this->temp_, - const ACE_TCHAR *[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_; -} - -const ACE_TCHAR * -ACE_Arg_Shifter::get_current (void) const -{ - const ACE_TCHAR * retval = 0; - - if (this->is_anything_left ()) - retval = this->temp_[current_index_]; - - return retval; -} - -const ACE_TCHAR * -ACE_Arg_Shifter::get_the_parameter (const ACE_TCHAR *flag) -{ - // the return 0's abound because this method - // would otherwise be a deep if { } else { } - - // check to see if any arguments still exist - if (!this->is_anything_left()) - return 0; - - // check to see if the flag is the argument - int offset = this->cur_arg_strncasecmp (flag); - if (offset == -1) - return 0; - - if (offset == 0) - { - this->consume_arg (); - - if (!this->is_parameter_next()) - { - return 0; - } - } - // the paramter is in the middle somewhere... - return this->temp_[current_index_] + offset; -} - -int -ACE_Arg_Shifter::cur_arg_strncasecmp (const ACE_TCHAR *flag) -{ - // Check for a current argument - if (this->is_anything_left()) - { - size_t flag_length = ACE_OS::strlen (flag); - - // Check for presence of the flag - if (ACE_OS::strncasecmp(this->temp_[current_index_], - flag, - flag_length) == 0) - { - if (ACE_OS::strlen(temp_[current_index_]) == - flag_length) - { - // match and lengths are equal - return 0; - } - else - { - // matches, with more info to boot! - size_t remaining = ACE_OS::strspn - (this->temp_[current_index_] + flag_length, - ACE_LIB_TEXT (" ")) + flag_length; - return static_cast<int> (remaining); - } - } - } - // failure - return -1; -} - -int -ACE_Arg_Shifter::consume_arg (int number) -{ - int retval = 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; - retval = 1; - } - - return retval; -} - -int -ACE_Arg_Shifter::ignore_arg (int number) -{ - int retval = 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_]; - - retval = 1; - this->argc_ += number; - } - - return retval; -} - -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_; -} - -ACE_END_VERSIONED_NAMESPACE_DECL +#if !defined (__ACE_INLINE__) +template class ACE_TArg_Shifter< ACE_TCHAR >; +#endif /* __ACE_INLINE__ */ |