Public Member Functions | Protected Attributes

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]

Detailed Description

Definition at line 31 of file FlowSpec_Entry.h.


Constructor & Destructor Documentation

TAO_Tokenizer::TAO_Tokenizer ( const char *  string,
char  delimiter 
)

constructor.

Definition at line 4478 of file AVStreams_i.cpp.

  :token_array_ (10, (char*)0, 0),
   count_ (0)
{
  this->parse (string, delimiter);
}

TAO_Tokenizer::~TAO_Tokenizer ( void   ) 

destructor.

Definition at line 4485 of file AVStreams_i.cpp.

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


Member Function Documentation

int TAO_Tokenizer::num_tokens ( void   ) 

Number of tokens.

Definition at line 4561 of file AVStreams_i.cpp.

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

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

Definition at line 4567 of file AVStreams_i.cpp.

{
  if (index >= this->num_tokens_)
    return 0;

  return this->token_array_[index];
}

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

parses the string and tokenizes it.

Definition at line 4493 of file AVStreams_i.cpp.

{
  ACE_CString new_string (string);
  u_int pos =0;
  ACE_CString::size_type slash_pos = 0;
  u_int count = 0;
  int result;
  while (pos < new_string.length ())
    {
      slash_pos = new_string.find (delimiter, pos);
      ACE_CString substring;
      if (slash_pos != new_string.npos)
        {
          substring = new_string.substring (pos,
                                            slash_pos - pos);
          pos = slash_pos + 1;
        }
      else
        {
          substring = new_string.substring (pos);
          pos = static_cast<int> (new_string.length ());
        }
      char *token = CORBA::string_dup (substring.c_str ());
      result = this->token_array_.set (token, count);
      if (result == -1)
        {
          this->token_array_.size (this->token_array_.size ()*2);
          result = this->token_array_.set (token, count);
          if (result == -1)
            ACE_ERROR_RETURN ((LM_ERROR, "TAO_Tokenizer::parse error"), -1);
        }
      count++;
    }

  /*
  ACE_OS::strcpy (this->string_ , string);
  char delimiter_str [2] = {0, 0};
  delimiter_str [0] = delimiter;
  char *token = ACE_OS::strtok (this->string_, delimiter_str);

  while (token != 0)
    {
      result = this->token_array_.set (token, count);
      if (result == -1)
        {
          this->token_array_.size (this->token_array_.size ()*2);
          result = this->token_array_.set (token, count);
          if (result == -1)
            ACE_ERROR_RETURN ((LM_ERROR, "TAO_Tokenizer::parse error"), -1);
        }
      token = ACE_OS::strtok (0, delimiter_str);
      count++;
    }
  */
  this->num_tokens_ = count;
  return 0;
}

char * TAO_Tokenizer::token ( void   ) 

Returns the next token.

Definition at line 4552 of file AVStreams_i.cpp.

{
  if (count_ < num_tokens_)
    return CORBA::string_dup (this->token_array_[this->count_++]);
  else
    return 0;
}


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.

char TAO_Tokenizer::string_[BUFSIZ] [protected]

Definition at line 55 of file FlowSpec_Entry.h.

Definition at line 52 of file FlowSpec_Entry.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines