Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 Methods

 ACEXML_StrCharStream (void)
 Default constructor. More...

 ACEXML_StrCharStream (const ACEXML_Char *str)
 Initializing Constructor. More...

virtual ~ACEXML_StrCharStream (void)
 Destructor. More...

int open (const ACEXML_Char *str)
 Initializing and reset the StrCharStream with str. More...

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 void rewind (void)

Private Attributes

ACEXML_Charstart_
ACEXML_Charptr_
ACEXML_Charend_
ACEXML_Charencoding_

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

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

ACEXML_StrCharStream::ACEXML_StrCharStream const ACEXML_Char   str
 

Initializing Constructor.

Definition at line 13 of file StrCharStream.cpp.

References ACEXML_Char, and open.

00014   : start_ (0), ptr_ (0), end_ (0), encoding_ (0)
00015 {
00016   this->open (str);
00017 }

ACEXML_StrCharStream::~ACEXML_StrCharStream void    [virtual]
 

Destructor.

Definition at line 20 of file StrCharStream.cpp.

References close.

00021 {
00022   this->close();
00023 }


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

References end_, and start_.

00045 {
00046   if (this->start_ != 0)
00047     return (this->end_ - this->start_); // @@ Will this work on all platforms?
00048   return -1;
00049 }

int ACEXML_StrCharStream::close void    [virtual]
 

Close this stream and release all resources used by it.

Implements ACEXML_CharStream.

Definition at line 52 of file StrCharStream.cpp.

References encoding_, end_, ptr_, and start_.

Referenced by ~ACEXML_StrCharStream.

00053 {
00054   delete[] this->start_;
00055   delete[] this->encoding_;
00056   this->start_ = this->ptr_ = this->end_ = 0;
00057   return 0;
00058 }

int ACEXML_StrCharStream::determine_encoding void    [virtual]
 

Determine the encoding of the file.

Definition at line 61 of file StrCharStream.cpp.

References ACE_DEBUG, ACEXML_Char, encoding_, ACEXML_Encoding::encoding_names_, end_, ACEXML_Encoding::get_encoding, LM_DEBUG, ACEXML_Encoding::OTHER, start_, ACE_OS_String::strcmp, and ACE::strnew.

Referenced by open.

00062 {
00063   char input[4];
00064   char* sptr  = (char*)this->start_;
00065   int i = 0;
00066   for ( ; i < 4 && sptr != (char*)this->end_; ++sptr, ++i)
00067     {
00068       input[i] = *sptr;
00069     }
00070   if (i < 4)
00071     return -1;
00072   const ACEXML_Char* temp = ACEXML_Encoding::get_encoding (input);
00073   if (!temp)
00074     return -1;
00075   if (ACE_OS::strcmp (temp,
00076                       ACEXML_Encoding::encoding_names_[ACEXML_Encoding::OTHER]) == 0)
00077     return -1;
00078   else
00079     {
00080       this->encoding_ = ACE::strnew (temp);
00081       ACE_DEBUG ((LM_DEBUG, "String's encoding is %s\n", this->encoding_));
00082     }
00083   return 0;
00084 }

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

References ACEXML_Char, end_, ptr_, and start_.

00094 {
00095   if (this->start_ != 0 && this->ptr_ != this->end_)
00096     {
00097       ch = *this->ptr_++;
00098 
00099       return 0;
00100     }
00101 
00102   return -1;
00103 }

const ACEXML_Char * ACEXML_StrCharStream::getEncoding void    [virtual]
 

Implements ACEXML_CharStream.

Definition at line 131 of file StrCharStream.cpp.

References encoding_.

00132 {
00133   return this->encoding_;
00134 }

int ACEXML_StrCharStream::open const ACEXML_Char   str
 

Initializing and reset the StrCharStream with str.

Definition at line 26 of file StrCharStream.cpp.

References ACEXML_Char, determine_encoding, encoding_, end_, ptr_, start_, ACE_OS_String::strlen, and ACE::strnew.

Referenced by ACEXML_StrCharStream.

00027 {
00028   delete[] this->start_;
00029   delete[] this->encoding_;
00030 
00031   if (str != 0 && (this->start_ = ACE::strnew (str)) != 0)
00032     {
00033       this->ptr_ = this->start_;
00034       this->end_ = this->start_ + ACE_OS_String::strlen (this->start_);
00035       this->determine_encoding();
00036       return 0;
00037     }
00038 
00039   this->start_ = this->ptr_ = this->end_ = 0;
00040   return -1;                // Invalid string passed.
00041 }

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

References end_, ptr_, and start_.

00124 {
00125   if (this->start_ != 0 && this->ptr_ != this->end_)
00126     return *this->ptr_;
00127   return -1;
00128 }

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

References ACEXML_Char, end_, ptr_, start_, and ACE_OS_String::strncpy.

00108 {
00109   if (this->start_ != 0 &&
00110       this->ptr_ != this->end_)
00111     {
00112       if ((int) len > this->end_ - this->ptr_)
00113         len = this->end_ - this->ptr_;
00114 
00115       ACE_OS_String::strncpy (str, this->ptr_, len);
00116       this->ptr_ += len;
00117       return ACE_static_cast(int, len);
00118     }
00119   return 0;
00120 }

void ACEXML_StrCharStream::rewind void    [virtual]
 

Resets the pointer to the beginning of the stream.

Definition at line 87 of file StrCharStream.cpp.

References ptr_, and start_.

00088 {
00089   this->ptr_ = this->start_;
00090 }


Member Data Documentation

ACEXML_Char* ACEXML_StrCharStream::encoding_ [private]
 

Definition at line 94 of file StrCharStream.h.

Referenced by close, determine_encoding, getEncoding, and open.

ACEXML_Char* ACEXML_StrCharStream::end_ [private]
 

Definition at line 93 of file StrCharStream.h.

Referenced by available, close, determine_encoding, get, open, peek, and read.

ACEXML_Char* ACEXML_StrCharStream::ptr_ [private]
 

Definition at line 92 of file StrCharStream.h.

Referenced by close, get, open, peek, read, and rewind.

ACEXML_Char* ACEXML_StrCharStream::start_ [private]
 

Definition at line 91 of file StrCharStream.h.

Referenced by available, close, determine_encoding, get, open, peek, read, and rewind.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 13:27:29 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002