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.

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

ACEXML_StrCharStream::~ACEXML_StrCharStream void   )  [virtual]
 

Destructor.

Definition at line 15 of file StrCharStream.cpp.

References close().

00016 {
00017   this->close();
00018 }


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 36 of file StrCharStream.cpp.

00037 {
00038   if (this->start_ != 0)
00039     return (this->end_ - this->start_); // @@ Will this work on all platforms?
00040   return -1;
00041 }

int ACEXML_StrCharStream::close void   )  [virtual]
 

Close this stream and release all resources used by it.

Implements ACEXML_CharStream.

Definition at line 44 of file StrCharStream.cpp.

Referenced by ~ACEXML_StrCharStream().

00045 {
00046   delete[] this->start_;
00047   delete[] this->encoding_;
00048   this->encoding_ = 0;
00049   delete[] this->name_;
00050   this->name_ = 0;
00051   this->start_ = this->ptr_ = this->end_ = 0;
00052   return 0;
00053 }

int ACEXML_StrCharStream::determine_encoding void   )  [virtual]
 

Determine the encoding of the file.

Definition at line 56 of file StrCharStream.cpp.

References ACEXML_Char, ACEXML_Encoding::get_encoding(), and ACE::strnew().

Referenced by open(), and rewind().

00057 {
00058   if (this->start_ == 0)
00059     return -1;
00060   char input[4] = {0,0,0,0};
00061   char* sptr  = (char*)this->start_;
00062   int i = 0;
00063   for ( ; i < 4 && sptr != (char*)this->end_; ++sptr, ++i)
00064     input[i] = *sptr;
00065   const ACEXML_Char* temp = ACEXML_Encoding::get_encoding (input);
00066   if (!temp)
00067     return -1;
00068   else
00069     {
00070       if (this->encoding_)
00071         delete [] this->encoding_;
00072       this->encoding_ = ACE::strnew (temp);
00073       // ACE_DEBUG ((LM_DEBUG, "String's encoding is %s\n", this->encoding_));
00074     }
00075   return 0;
00076 }

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 86 of file StrCharStream.cpp.

References ACEXML_Char.

00087 {
00088   if (this->start_ != 0 && this->ptr_ != this->end_)
00089     {
00090       ch = *this->ptr_++;
00091       return 0;
00092     }
00093   return -1;
00094 }

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

Implements ACEXML_CharStream.

Definition at line 120 of file StrCharStream.cpp.

00121 {
00122   return this->encoding_;
00123 }

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

Implements ACEXML_CharStream.

Definition at line 126 of file StrCharStream.cpp.

00127 {
00128   return this->name_;
00129 }

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.

References ACEXML_Char, determine_encoding(), ACE_OS::strlen(), and ACE::strnew().

Referenced by ACEXML_Parser::parse_entity_reference(), and ACEXML_Parser::parse_PE_reference().

00022 {
00023 
00024   if (str != 0 && name != 0
00025       && (this->start_ = ACE::strnew (str)) != 0
00026       && (this->name_ = ACE::strnew (name)) != 0)
00027     {
00028       this->ptr_ = this->start_;
00029       this->end_ = this->start_ + ACE_OS::strlen (this->start_);
00030       return this->determine_encoding();
00031     }
00032   return -1;                // Invalid string passed.
00033 }

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 112 of file StrCharStream.cpp.

00113 {
00114   if (this->start_ != 0 && this->ptr_ != this->end_)
00115     return *this->ptr_;
00116   return -1;
00117 }

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 97 of file StrCharStream.cpp.

References ACEXML_Char, and ACE_OS::strncpy().

00098 {
00099   if (this->start_ != 0 &&
00100       this->ptr_ != this->end_)
00101     {
00102       if (len * sizeof (ACEXML_Char) > (size_t) (this->end_ - this->ptr_))
00103         len = this->end_ - this->ptr_;
00104       ACE_OS::strncpy (str, this->ptr_, len);
00105       this->ptr_ += len;
00106       return static_cast<int> (len);
00107     }
00108   return 0;
00109 }

void ACEXML_StrCharStream::rewind void   )  [virtual]
 

Resets the pointer to the beginning of the stream.

Implements ACEXML_CharStream.

Definition at line 79 of file StrCharStream.cpp.

References determine_encoding().

00080 {
00081   this->ptr_ = this->start_;
00082   this->determine_encoding();
00083 }


Member Data Documentation

ACEXML_Char* ACEXML_StrCharStream::encoding_ [private]
 

Definition at line 95 of file StrCharStream.h.

ACEXML_Char* ACEXML_StrCharStream::end_ [private]
 

Definition at line 94 of file StrCharStream.h.

ACEXML_Char* ACEXML_StrCharStream::name_ [private]
 

Definition at line 96 of file StrCharStream.h.

ACEXML_Char* ACEXML_StrCharStream::ptr_ [private]
 

Definition at line 93 of file StrCharStream.h.

ACEXML_Char* ACEXML_StrCharStream::start_ [private]
 

Definition at line 92 of file StrCharStream.h.


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