TAO_Tokenizer Class Reference

#include <FlowSpec_Entry.h>

Collaboration diagram for TAO_Tokenizer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Tokenizer (const char *string, char delimiter)
 constructor.

 ~TAO_Tokenizer (void)
 destructor.

int parse (const char *string, char delimiter)
 parses the string and tokenizes it.

char * token (void)
 Returns the next token.

int num_tokens (void)
 Number of tokens.

const char * operator[] (size_t index) const

Protected Attributes

ACE_Array< char * > token_array_
size_t count_
size_t num_tokens_
char string_ [BUFSIZ]

Constructor & Destructor Documentation

TAO_Tokenizer::TAO_Tokenizer const char *  string,
char  delimiter
 

constructor.

Definition at line 5212 of file AVStreams_i.cpp.

References parse().

05213   :token_array_ (10),
05214    count_ (0)
05215 {
05216   this->parse (string, delimiter);
05217 }

TAO_Tokenizer::~TAO_Tokenizer void   ) 
 

destructor.

Definition at line 5219 of file AVStreams_i.cpp.

References num_tokens_, and CORBA::string_free().

05220 {
05221   for (unsigned int i=0; i<this->num_tokens_; i++)
05222     CORBA::string_free (this->token_array_[i]);
05223 }


Member Function Documentation

int TAO_Tokenizer::num_tokens void   ) 
 

Number of tokens.

Definition at line 5295 of file AVStreams_i.cpp.

References num_tokens_.

Referenced by TAO_Forward_FlowSpec_Entry::parse(), and TAO_FlowSpec_Entry::parse_address().

05296 {
05297   return static_cast<int> (this->num_tokens_);
05298 }

const char * TAO_Tokenizer::operator[] size_t  index  )  const
 

Definition at line 5301 of file AVStreams_i.cpp.

References num_tokens_, and token_array_.

05302 {
05303   if (index >= this->num_tokens_)
05304     return 0;
05305 
05306   return this->token_array_[index];
05307 }

int TAO_Tokenizer::parse const char *  string,
char  delimiter
 

parses the string and tokenizes it.

Definition at line 5227 of file AVStreams_i.cpp.

References ACE_CString, ACE_ERROR_RETURN, LM_ERROR, num_tokens_, ACE_Array_Base< T >::set(), ACE_Array_Base< T >::size(), CORBA::string_dup(), token(), and token_array_.

Referenced by TAO_Tokenizer().

05228 {
05229   ACE_CString new_string (string);
05230   u_int pos =0;
05231   int slash_pos = 0;
05232   u_int count = 0;
05233   int result;
05234   while (pos < new_string.length ())
05235     {
05236       slash_pos = new_string.find (delimiter, pos);
05237       ACE_CString substring;
05238       if (slash_pos != new_string.npos)
05239         {
05240           substring = new_string.substring (pos,
05241                                             slash_pos - pos);
05242           pos = slash_pos + 1;
05243         }
05244       else
05245         {
05246           substring = new_string.substring (pos);
05247           pos = static_cast<int> (new_string.length ());
05248         }
05249       char *token = CORBA::string_dup (substring.c_str ());
05250       result = this->token_array_.set (token, count);
05251       if (result == -1)
05252         {
05253           this->token_array_.size (this->token_array_.size ()*2);
05254           result = this->token_array_.set (token, count);
05255           if (result == -1)
05256             ACE_ERROR_RETURN ((LM_ERROR, "TAO_Tokenizer::parse error"), -1);
05257         }
05258       count++;
05259     }
05260 
05261   /*
05262   ACE_OS::strcpy (this->string_ , string);
05263   char delimiter_str [2] = {0, 0};
05264   delimiter_str [0] = delimiter;
05265   char *token = ACE_OS::strtok (this->string_, delimiter_str);
05266 
05267   while (token != 0)
05268     {
05269       result = this->token_array_.set (token, count);
05270       if (result == -1)
05271         {
05272           this->token_array_.size (this->token_array_.size ()*2);
05273           result = this->token_array_.set (token, count);
05274           if (result == -1)
05275             ACE_ERROR_RETURN ((LM_ERROR, "TAO_Tokenizer::parse error"), -1);
05276         }
05277       token = ACE_OS::strtok (0, delimiter_str);
05278       count++;
05279     }
05280   */
05281   this->num_tokens_ = count;
05282   return 0;
05283 }

char * TAO_Tokenizer::token void   ) 
 

Returns the next token.

Definition at line 5286 of file AVStreams_i.cpp.

References num_tokens_, and CORBA::string_dup().

Referenced by parse().

05287 {
05288   if (count_ < num_tokens_)
05289     return CORBA::string_dup (this->token_array_[this->count_++]);
05290   else
05291     return 0;
05292 }


Member Data Documentation

size_t TAO_Tokenizer::count_ [protected]
 

Definition at line 53 of file FlowSpec_Entry.h.

size_t TAO_Tokenizer::num_tokens_ [protected]
 

Definition at line 54 of file FlowSpec_Entry.h.

Referenced by num_tokens(), operator[](), parse(), token(), and ~TAO_Tokenizer().

char TAO_Tokenizer::string_[BUFSIZ] [protected]
 

Definition at line 55 of file FlowSpec_Entry.h.

ACE_Array<char*> TAO_Tokenizer::token_array_ [protected]
 

Definition at line 52 of file FlowSpec_Entry.h.

Referenced by operator[](), and parse().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:48:58 2006 for TAO_AV by doxygen 1.3.6