Public Member Functions | Private Attributes

ACEXML_StrCharStream Class Reference

#include <common/StrCharStream.h>

Inheritance diagram for ACEXML_StrCharStream:
Inheritance graph
[legend]
Collaboration diagram for ACEXML_StrCharStream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ACEXML_StrCharStream (void)
 Default constructor.
virtual ~ACEXML_StrCharStream (void)
 Destructor.
int open (const ACEXML_Char *str, const ACEXML_Char *name)
 Initializing StrCharStream with str and name.
virtual int available (void)
virtual int close (void)
virtual int determine_encoding (void)
virtual int get (ACEXML_Char &ch)
virtual int read (ACEXML_Char *str, size_t len)
virtual int peek (void)
virtual const ACEXML_ChargetEncoding (void)
virtual const ACEXML_ChargetSystemId (void)
virtual void rewind (void)

Private Attributes

ACEXML_Charstart_
ACEXML_Charptr_
ACEXML_Charend_
ACEXML_Charencoding_
ACEXML_Charname_

Detailed Description

An implementation of ACEXML_CharStream for reading input from a null-terminated ACEXML_Char string.

Definition at line 31 of file StrCharStream.h.


Constructor & Destructor Documentation

ACEXML_StrCharStream::ACEXML_StrCharStream ( void   ) 

Default constructor.

Definition at line 9 of file StrCharStream.cpp.

  : start_ (0), ptr_ (0), end_ (0), encoding_ (0), name_ (0)
{
}

ACEXML_StrCharStream::~ACEXML_StrCharStream ( void   )  [virtual]

Destructor.

Definition at line 15 of file StrCharStream.cpp.

{
  this->close();
}


Member Function Documentation

int ACEXML_StrCharStream::available ( void   )  [virtual]

Returns the available ACEXML_Char in the buffer. -1 if the object is not initialized properly.

Implements ACEXML_CharStream.

Definition at line 40 of file StrCharStream.cpp.

{
  if (this->start_ != 0)
    return static_cast<int> (this->end_ - this->start_); // @@ Will this work on all platforms?
  return -1;
}

int ACEXML_StrCharStream::close ( void   )  [virtual]

Close this stream and release all resources used by it.

Implements ACEXML_CharStream.

Definition at line 48 of file StrCharStream.cpp.

{
  delete[] this->start_;
  delete[] this->encoding_;
  this->encoding_ = 0;
  delete[] this->name_;
  this->name_ = 0;
  this->start_ = this->ptr_ = this->end_ = 0;
  return 0;
}

int ACEXML_StrCharStream::determine_encoding ( void   )  [virtual]

Determine the encoding of the file.

Definition at line 60 of file StrCharStream.cpp.

{
  if (this->start_ == 0)
    return -1;
  char input[4] = {0,0,0,0};
  char* sptr  = (char*)this->start_;
  int i = 0;
  for ( ; i < 4 && sptr != (char*)this->end_; ++sptr, ++i)
    input[i] = *sptr;
  const ACEXML_Char* temp = ACEXML_Encoding::get_encoding (input);
  if (!temp)
    return -1;
  else
    {
      delete [] this->encoding_;
      this->encoding_ = ACE::strnew (temp);
      // ACE_DEBUG ((LM_DEBUG, "String's encoding is %s\n", this->encoding_));
    }
  return 0;
}

int ACEXML_StrCharStream::get ( ACEXML_Char ch  )  [virtual]

Read the next ACEXML_Char. Return -1 if we are not able to return an ACEXML_Char, 0 if EOS is reached, or 1 if succeed.

Implements ACEXML_CharStream.

Definition at line 89 of file StrCharStream.cpp.

{
  if (this->start_ != 0 && this->ptr_ != this->end_)
    {
      ch = *this->ptr_++;
      return 0;
    }
  return -1;
}

const ACEXML_Char * ACEXML_StrCharStream::getEncoding ( void   )  [virtual]

Implements ACEXML_CharStream.

Definition at line 123 of file StrCharStream.cpp.

{
  return this->encoding_;
}

const ACEXML_Char * ACEXML_StrCharStream::getSystemId ( void   )  [virtual]

Implements ACEXML_CharStream.

Definition at line 129 of file StrCharStream.cpp.

{
  return this->name_;
}

int ACEXML_StrCharStream::open ( const ACEXML_Char str,
const ACEXML_Char name 
)

Initializing StrCharStream with str and name.

Definition at line 21 of file StrCharStream.cpp.

{

  if (str != 0 && name != 0)
    {
      delete [] this->start_;
      if ((this->start_ = ACE::strnew (str)) == 0)
        return -1;
      delete [] this->name_;
      if ((this->name_ = ACE::strnew (name)) == 0)
        return -1;
      this->ptr_ = this->start_;
      this->end_ = this->start_ + ACE_OS::strlen (this->start_);
      return this->determine_encoding();
    }
  return -1;                // Invalid string passed.
}

int ACEXML_StrCharStream::peek ( void   )  [virtual]

Peek the next ACEXML_Char in the CharStream. Return the character if succeess, -1 if EOS is reached.

Implements ACEXML_CharStream.

Definition at line 115 of file StrCharStream.cpp.

{
  if (this->start_ != 0 && this->ptr_ != this->end_)
    return *this->ptr_;
  return -1;
}

int ACEXML_StrCharStream::read ( ACEXML_Char str,
size_t  len 
) [virtual]

Read the next batch of ACEXML_Char strings

Implements ACEXML_CharStream.

Definition at line 100 of file StrCharStream.cpp.

{
  if (this->start_ != 0 &&
      this->ptr_ != this->end_)
    {
      if (len * sizeof (ACEXML_Char) > (size_t) (this->end_ - this->ptr_))
        len = this->end_ - this->ptr_;
      ACE_OS::strncpy (str, this->ptr_, len);
      this->ptr_ += len;
      return static_cast<int> (len);
    }
  return 0;
}

void ACEXML_StrCharStream::rewind ( void   )  [virtual]

Resets the pointer to the beginning of the stream.

Implements ACEXML_CharStream.

Definition at line 82 of file StrCharStream.cpp.

{
  this->ptr_ = this->start_;
  this->determine_encoding();
}


Member Data Documentation

Definition at line 95 of file StrCharStream.h.

Definition at line 94 of file StrCharStream.h.

Definition at line 96 of file StrCharStream.h.

Definition at line 93 of file StrCharStream.h.

Definition at line 92 of file StrCharStream.h.


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