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

ACEXML_FileCharStream Class Reference

#include "ACEXML/common/FileCharStream.h"

Inheritance diagram for ACEXML_FileCharStream:

Inheritance graph
[legend]
Collaboration diagram for ACEXML_FileCharStream:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACEXML_FileCharStream (void)
 Default constructor. More...

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

int open (const ACEXML_Char *name)
 Open a file. More...

virtual int available (void)
virtual int close (void)
virtual int get (ACEXML_Char &ch)
virtual int read (ACEXML_Char *str, size_t len)
virtual int determine_encoding (void)
virtual int peek (void)
virtual void rewind (void)
virtual const ACEXML_ChargetEncoding (void)

Protected Methods

virtual int getchar_i (char &ch)

Private Attributes

ACEXML_Charfilename_
ACEXML_Charencoding_
off_t size_
FILE * infile_
ACEXML_Char peek_

Detailed Description

An implementation of ACEXML_CharStream for reading input from a file.

Definition at line 32 of file FileCharStream.h.


Constructor & Destructor Documentation

ACEXML_FileCharStream::ACEXML_FileCharStream void   
 

Default constructor.

Definition at line 7 of file FileCharStream.cpp.

00008   : filename_ (0), encoding_ (0), size_ (0), infile_ (NULL), peek_ (0)
00009 {
00010 }

ACEXML_FileCharStream::~ACEXML_FileCharStream void    [virtual]
 

Destructor.

Definition at line 12 of file FileCharStream.cpp.

References close.

00013 {
00014   this->close();
00015 }


Member Function Documentation

int ACEXML_FileCharStream::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 88 of file FileCharStream.cpp.

References ACE_OS::ftell, and size_.

00089 {
00090   long curr;
00091   if ((curr = ACE_OS::ftell (this->infile_)) < 0)
00092     return -1;
00093   return (this->size_ - curr);
00094 }

int ACEXML_FileCharStream::close void    [virtual]
 

Close this stream and release all resources used by it.

Implements ACEXML_CharStream.

Definition at line 97 of file FileCharStream.cpp.

References encoding_, ACE_OS::fclose, filename_, infile_, peek_, and size_.

Referenced by ~ACEXML_FileCharStream.

00098 {
00099   if (this->infile_ != NULL)
00100     {
00101       ACE_OS::fclose (this->infile_);
00102       this->infile_ = NULL;
00103     }
00104   delete[] this->filename_;
00105   this->filename_ = 0;
00106   delete[] this->encoding_;
00107   this->encoding_ = 0;
00108   this->size_ = 0;
00109   this->peek_ = 0;
00110   return 0;
00111 }

int ACEXML_FileCharStream::determine_encoding void    [virtual]
 

Determine the encoding of the file.

Definition at line 41 of file FileCharStream.cpp.

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

Referenced by open.

00042 {
00043   char input[4];
00044   int retval = 0;
00045   int i = 0;
00046   for (; i < 4 && retval != -1; ++i)
00047     retval = this->getchar_i(input[i]);
00048   if (i < 4)
00049     return -1;
00050 
00051   // Rewind the stream
00052   this->rewind();
00053 
00054   const ACEXML_Char* temp = ACEXML_Encoding::get_encoding (input);
00055   if (!temp)
00056     return -1;
00057   if (ACE_OS::strcmp (temp,
00058                       ACEXML_Encoding::encoding_names_[ACEXML_Encoding::OTHER]) == 0)
00059     return -1;
00060   else
00061     {
00062       this->encoding_ = ACE::strnew (temp);
00063       ACE_DEBUG ((LM_DEBUG, "File's encoding is %s\n", this->encoding_));
00064     }
00065   // Move over the byte-order-mark if present.
00066   char ch;
00067   for (int j = 0; j < 2; ++j)
00068     {
00069       this->getchar_i (ch);
00070       if (ch == '\xFF' || ch == '\xFE' || ch == '\xEF')
00071         continue;
00072       else
00073         {
00074           ungetc (ch, this->infile_);
00075           break;
00076         }
00077     }
00078   return 0;
00079 }

int ACEXML_FileCharStream::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 129 of file FileCharStream.cpp.

References ACEXML_Char, and ACE_OS::fgetc.

00130 {
00131 #if defined (ACE_USES_WCHAR)
00132   return this->get_i (ch);
00133 #else
00134   ch = (ACEXML_Char) ACE_OS::fgetc (this->infile_);
00135   return (feof(this->infile_) ? -1 : 0);
00136 #endif /* ACE_USES_WCHAR */
00137 }

int ACEXML_FileCharStream::getchar_i char &    ch [protected, virtual]
 

Read the next character as a normal character. Return -1 if EOF is reached, else return 0.

Definition at line 115 of file FileCharStream.cpp.

References ACE_OS::fgetc.

Referenced by determine_encoding.

00116 {
00117   ch = ACE_OS::fgetc (this->infile_);
00118   return (feof(this->infile_) ? -1 : 0);
00119 }

const ACEXML_Char * ACEXML_FileCharStream::getEncoding void    [virtual]
 

Implements ACEXML_CharStream.

Definition at line 224 of file FileCharStream.cpp.

References encoding_.

00225 {
00226   return this->encoding_;
00227 }

int ACEXML_FileCharStream::open const ACEXML_Char   name
 

Open a file.

Definition at line 18 of file FileCharStream.cpp.

References ACE_stat, ACE_TEXT, ACEXML_Char, determine_encoding, encoding_, filename_, ACE_OS::fopen, infile_, size_, ACE_OS::stat, and ACE::strnew.

Referenced by ACEXML_StreamFactory::create_stream.

00019 {
00020   delete[] this->filename_;
00021   this->filename_ = 0;
00022 
00023   delete[] this->encoding_;
00024   this->encoding_ = 0;
00025 
00026   this->infile_ = ACE_OS::fopen (name, ACE_TEXT ("r"));
00027   if (this->infile_ == NULL)
00028     return -1;
00029 
00030   ACE_stat statbuf;
00031   if (ACE_OS::stat (name, &statbuf) < 0)
00032     return -1;
00033 
00034   this->size_ = statbuf.st_size;
00035   this->filename_ = ACE::strnew (name);
00036   this->determine_encoding();
00037   return 0;
00038 }

int ACEXML_FileCharStream::peek void    [virtual]
 

Peek the next ACEXML_Char in the CharStream. Return the character if success, -1 if EOF is reached.

Implements ACEXML_CharStream.

Definition at line 175 of file FileCharStream.cpp.

References ACEXML_Char, ACE_OS::fgetc, and infile_.

00176 {
00177 #if defined (ACE_USES_WCHAR)
00178   return this->peek_i();
00179 #else
00180   ACEXML_Char ch = ACE_OS::fgetc (this->infile_);
00181   ::ungetc (ch, this->infile_);
00182   return ch;
00183 #endif /* ACE_USES_WCHAR */
00184 }

int ACEXML_FileCharStream::read ACEXML_Char   str,
size_t    len
[virtual]
 

Read the next batch of ACEXML_Char strings

Implements ACEXML_CharStream.

Definition at line 122 of file FileCharStream.cpp.

References ACEXML_Char, and ACE_OS::fread.

00124 {
00125   return ACE_static_cast(int, ACE_OS::fread (str, len, 1, this->infile_));
00126 }

void ACEXML_FileCharStream::rewind void    [virtual]
 

Resets the file pointer to the beginning of the stream.

Definition at line 82 of file FileCharStream.cpp.

References ACE_OS::rewind.

Referenced by determine_encoding.

00083 {
00084   ACE_OS::rewind (this->infile_);
00085 }


Member Data Documentation

ACEXML_Char* ACEXML_FileCharStream::encoding_ [private]
 

Definition at line 115 of file FileCharStream.h.

Referenced by close, determine_encoding, getEncoding, and open.

ACEXML_Char* ACEXML_FileCharStream::filename_ [private]
 

Definition at line 114 of file FileCharStream.h.

Referenced by close, and open.

FILE* ACEXML_FileCharStream::infile_ [private]
 

Definition at line 117 of file FileCharStream.h.

Referenced by close, open, and peek.

ACEXML_Char ACEXML_FileCharStream::peek_ [private]
 

Definition at line 122 of file FileCharStream.h.

Referenced by close.

off_t ACEXML_FileCharStream::size_ [private]
 

Definition at line 116 of file FileCharStream.h.

Referenced by available, close, and open.


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