Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Output Class Reference

#include <Output.hpp>

Inheritance diagram for Output::

XMLOutput List of all members.

Public Methods

char OUTPUT_STATIC CreateFile (char *filename, int mybufsize=65536)
void OUTPUT_STATIC CloseFile ()
void OUTPUT_STATIC CloseAndDeleteFile ()
void OUTPUT_STATIC Flush ()
char OUTPUT_STATIC * GetBufPtr (int *len)
void OUTPUT_STATIC SaveBytes (int bytecount)
int OUTPUT_STATIC GetCurFileSize ()
void OUTPUT_STATIC StoreData (char *ptr, int len)
void OUTPUT_STATIC StoreInt32 (int val)
void OUTPUT_STATIC StoreChar (char c)
void OUTPUT_STATIC StoreNewline ()
char OUTPUT_STATIC * GetDataPtr (int len)

Member Function Documentation

void OUTPUT_STATIC Output::CloseAndDeleteFile   [inline]
 

Definition at line 129 of file Output.hpp.

00131    {
00132       Flush();
00133       if(savefilename!=NULL)
00134       {
00135          if(output!=NULL)
00136             fclose(output);
00137          unlink(savefilename);
00138       }
00139       free(buf);
00140       return;
00141    }

void OUTPUT_STATIC Output::CloseFile   [inline]
 

Definition at line 117 of file Output.hpp.

00119    {
00120       Flush();
00121       if(savefilename!=NULL)
00122       {
00123          if(output!=NULL)
00124             fclose(output);
00125       }
00126       free(buf);
00127    }

char OUTPUT_STATIC Output::CreateFile char *    filename,
int    mybufsize = 65536
[inline]
 

Definition at line 71 of file Output.hpp.

00074    {
00075       if(filename==NULL)
00076       {
00077          savefilename=NULL;
00078          output=stdout;
00079 
00080          // We allocate the memory
00081          buf=(char *)malloc(mybufsize);
00082          if(buf==NULL)
00083             ExitNoMem();
00084 
00085 #ifdef WIN32
00086          _setmode(_fileno(stdout),_O_BINARY);
00087 #endif
00088       }
00089       else
00090       {
00091          // We allocate the output buffer memory and a little more for the filename
00092          buf=(char *)malloc(mybufsize+strlen(filename)+1);
00093          if(buf==NULL)
00094             ExitNoMem();
00095 
00096          savefilename=buf+mybufsize;
00097          strcpy(savefilename,filename);
00098 
00099          // We only open the output file, if strlen(filename)>0.
00100          // Otherwise, no output is performed at all.
00101          // (This is the test-case)
00102          if(strlen(filename)!=0)
00103          {
00104             output=fopen(filename,"wb");
00105             if(output==NULL)
00106                return 0;
00107          }
00108          else
00109             output=NULL;
00110       }
00111       bufsize=mybufsize;
00112       curpos=0;
00113       overallsize=0;
00114       return 1;
00115    }

void OUTPUT_STATIC Output::Flush   [inline]
 

Definition at line 143 of file Output.hpp.

00145    {
00146       overallsize+=curpos;
00147 
00148       if(output==NULL)
00149       {
00150          curpos=0;
00151          return;
00152       }
00153 
00154       char  *ptr=buf;
00155       int   byteswritten;
00156 
00157       // We write the output between '0' and 'curpos'
00158       // We only write at most 30000 bytes - to avoid some glitches
00159       // in the implementation of 'fwrite'.
00160 
00161       while(curpos>0)
00162       {
00163          byteswritten=fwrite(ptr,1,(curpos<30000) ? curpos : 30000,output);
00164          if(byteswritten==0)
00165          {
00166             Error("Could not write output file!");
00167             Exit();
00168          }
00169          curpos-=byteswritten;
00170          ptr+=byteswritten;
00171       }
00172    }

char OUTPUT_STATIC* Output::GetBufPtr int *    len [inline]
 

Definition at line 174 of file Output.hpp.

00176    {
00177       *len=bufsize-curpos;
00178       return buf+curpos;
00179    }

int OUTPUT_STATIC Output::GetCurFileSize   [inline]
 

Definition at line 188 of file Output.hpp.

00188 {  return overallsize+curpos; }

char OUTPUT_STATIC* Output::GetDataPtr int    len [inline]
 

Definition at line 246 of file Output.hpp.

Referenced by XMLOutput::attribWhitespaces(), XMLOutput::endElement(), XMLOutput::endEmptyElement(), and XMLOutput::startAttribute().

00249    {
00250       if(bufsize-curpos<len)
00251       {
00252          Flush();
00253          if(bufsize-curpos<len)
00254          {
00255             Error("Fatal Error !");
00256             Exit();
00257          }
00258       }
00259       curpos+=len;
00260       return buf+curpos-len;
00261    }

void OUTPUT_STATIC Output::SaveBytes int    bytecount [inline]
 

Definition at line 181 of file Output.hpp.

00184    {
00185       curpos+=bytecount;
00186    }

void OUTPUT_STATIC Output::StoreChar char    c [inline]
 

Definition at line 218 of file Output.hpp.

Referenced by XMLOutput::characters(), XMLOutput::endAttribute(), and XMLOutput::startElement().

00220    {
00221       if(bufsize-curpos<1)
00222          Flush();
00223 
00224       buf[curpos]=c;
00225       curpos++;
00226    }

void OUTPUT_STATIC Output::StoreData char *    ptr,
int    len
[inline]
 

Definition at line 193 of file Output.hpp.

Referenced by XMLOutput::characters(), and XMLOutput::startElement().

00195    {
00196       while(bufsize-curpos<len)
00197       {
00198          mymemcpy(buf+curpos,ptr,bufsize-curpos);
00199          len-=bufsize-curpos;
00200          ptr+=bufsize-curpos;
00201          curpos=bufsize;
00202          Flush();
00203       }
00204       mymemcpy(buf+curpos,ptr,len);
00205       curpos+=len;
00206    }

void OUTPUT_STATIC Output::StoreInt32 int    val [inline]
 

Definition at line 208 of file Output.hpp.

00210    {
00211       if(bufsize-curpos<4)
00212          Flush();
00213 
00214       *(int *)(buf+curpos)=val;
00215       curpos+=4;
00216    }

void OUTPUT_STATIC Output::StoreNewline   [inline]
 

Definition at line 228 of file Output.hpp.

00230    {
00231       if(usedosnewline)
00232       {
00233          if(bufsize-curpos<2)
00234             Flush();
00235 
00236          buf[curpos++]='\r';
00237       }
00238       else
00239       {
00240          if(bufsize-curpos<1)
00241             Flush();
00242       }
00243       buf[curpos++]='\n';
00244    }


The documentation for this class was generated from the following file:
Generated on Sat Oct 13 16:08:55 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001