Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Streams/OutStreams.h

Go to the documentation of this file.

    00001 /**
    00002 * @file OutStreams.h
    00003 *
    00004 * Declaration of out stream classes for different media and formats.
    00005 *
    00006 * @author Thomas Röfer
    00007 * @author Martin Lötzsch
    00008 */
    00009
    00010 #ifndef __OutStreams_h_
    00011 #define __OutStreams_h_
    00012
    00013 #include "InOut.h"
    00014 #include "Platform/File.h"
    00015 #include <string.h>
    00016
    00017 /**
    00018 * @class PhysicalOutStream
    00019 *
    00020 * The base class for physical out streams. Derivates of PhysicalOutStream only handle the
    00021 * writing of data to a medium, not of formating data.
    00022 */
    00023 class PhysicalOutStream
    00024 {
    00025 public:
    00026 /**
    00027 * The function writes a number of bytes into a physical stream.
    00028 * @param p The address the data is located at.
    00029 * @param size The number of bytes to be written.
    00030   */
    00031   virtual void writeToStream(const void* p,int size) = 0;
    00032
    00033 };
    00034
    00035 /**
    00036 * @class StreamWriter
    00037 *
    00038 * Generic class for formating data to be used in streams.
    00039 * The physical writing is then done by OutStream derivates.
    00040 */
    00041 class StreamWriter
    00042 {
    00043 protected:
    00044 /**
    00045 * Writes a character to a stream.
    00046 * @param d the data to write.
    00047 * @param stream the stream to write on.
    00048   */
    00049   virtual void writeChar(char d, PhysicalOutStream& stream) = 0;
    00050
    00051   /**
    00052   * Writes a unsigned character to a stream.
    00053   * @param d the data to write.
    00054   * @param stream the stream to write on.
    00055   */
    00056   virtual void writeUChar(unsigned char d, PhysicalOutStream& stream) = 0;
    00057
    00058   /**
    00059   * Writes a short to a stream.
    00060   * @param d the data to write.
    00061   * @param stream the stream to write on.
    00062   */
    00063   virtual void writeShort(short d, PhysicalOutStream& stream) = 0;
    00064
    00065   /**
    00066   * Writes a unsigned short to a stream.
    00067   * @param d the data to write.
    00068   * @param stream the stream to write on.
    00069   */
    00070   virtual void writeUShort(unsigned short d, PhysicalOutStream& stream) = 0;
    00071
    00072   /**
    00073   * Writes a int to a stream.
    00074   * @param d the data to write.
    00075   * @param stream the stream to write on.
    00076   */
    00077   virtual void writeInt(int d, PhysicalOutStream& stream) = 0;
    00078
    00079   /**
    00080   * Writes a unsigned int to a stream.
    00081   * @param d the data to write.
    00082   * @param stream the stream to write on.
    00083   */
    00084   virtual void writeUInt(unsigned int d, PhysicalOutStream& stream) = 0;
    00085
    00086   /**
    00087   * Writes a long to a stream.
    00088   * @param d the data to write.
    00089   * @param stream the stream to write on.
    00090   */
    00091   virtual void writeLong(long d, PhysicalOutStream& stream) = 0;
    00092
    00093   /**
    00094   * Writes a unsigned long to a stream.
    00095   * @param d the data to write.
    00096   * @param stream the stream to write on.
    00097   */
    00098   virtual void writeULong(unsigned long d, PhysicalOutStream& stream) = 0;
    00099
    00100   /**
    00101   * Writes a float to a stream.
    00102   * @param d the data to write.
    00103   * @param stream the stream to write on.
    00104   */
    00105   virtual void writeFloat(float d, PhysicalOutStream& stream) = 0;
    00106
    00107   /**
    00108   * Writes a double to a stream.
    00109   * @param d the data to write.
    00110   * @param stream the stream to write on.
    00111   */
    00112   virtual void writeDouble(double d, PhysicalOutStream& stream) = 0;
    00113
    00114   /**
    00115   * Writes a string to a stream.
    00116   * @param d the data to write.
    00117   * @param stream the stream to write on.
    00118   */
    00119   virtual void writeString(const char *d, PhysicalOutStream& stream) = 0;
    00120
    00121   /**
    00122   * Writes a 'end of line' to a stream.
    00123   * @param stream the stream to write on.
    00124   */
    00125   virtual void writeEndL(PhysicalOutStream& stream) = 0;
    00126
    00127   /**
    00128   * The function writes a number of bytes into the stream.
    00129   * @param p The address the data is located at.
    00130   * @param size The number of bytes to be written.
    00131   * @param stream the stream to write on.
    00132   */
    00133   virtual void writeData(const void* p,int size, PhysicalOutStream& stream) = 0;
    00134 };
    00135
    00136
    00137 /**
    00138 * @class OutStream
    00139 *
    00140 * Generic class for classes that do both formating and physical writing of data to streams.
    00141 */
    00142 template <class S, class W> class OutStream : public S, public W, public Out
    00143 {
    00144 public:
    00145   /** Standard constructor */
    00146   OutStream() {};
    00147
    00148   /**
    00149   * The function writes a number of bytes into a stream.
    00150   * @param p The address the data is located at.
    00151   * @param size The number of bytes to be written.
    00152   */
    00153   virtual void write(const void* p,int size)
    00154   { writeData(p, size, *this); }
    00155
    00156 protected:
    00157 /**
    00158 * Virtual redirection for operator<<(const char& value).
    00159   */
    00160   virtual void outChar(char d)
    00161   { writeChar(d,*this); }
    00162
    00163   /**
    00164   * Virtual redirection for operator<<(const unsigned char& value).
    00165   */
    00166   virtual void outUChar(unsigned char d)
    00167   { writeUChar(d,*this); }
    00168
    00169   /**
    00170   * Virtual redirection for operator<<(const short& value).
    00171   */
    00172   virtual void outShort(short d)
    00173   { writeShort(d,*this); }
    00174
    00175   /**
    00176   * Virtual redirection for operator<<(const unsigned short& value).
    00177   */
    00178   virtual void outUShort(unsigned short d)
    00179   { writeUShort(d,*this); }
    00180
    00181   /**
    00182   * Virtual redirection for operator<<(const int& value).
    00183   */
    00184   virtual void outInt(int d)
    00185   { writeInt(d,*this); }
    00186
    00187   /**
    00188   * Virtual redirection for operator<<(const unsigned& value).
    00189   */
    00190   virtual void outUInt(unsigned int d)
    00191   { writeUInt(d,*this); }
    00192
    00193   /**
    00194   * Virtual redirection for operator<<(const long& value).
    00195   */
    00196   virtual void outLong(long d)
    00197   { writeLong(d,*this); }
    00198
    00199   /**
    00200   * Virtual redirection for operator<<(const unsigned long& value).
    00201   */
    00202   virtual void outULong(unsigned long d)
    00203   { writeULong(d,*this); }
    00204
    00205   /**
    00206   * Virtual redirection for operator<<(const float& value).
    00207   */
    00208   virtual void outFloat(float d)
    00209   { writeFloat(d,*this); }
    00210
    00211   /**
    00212   * Virtual redirection for operator<<(const double& value).
    00213   */
    00214   virtual void outDouble(double d)
    00215   { writeDouble(d,*this); }
    00216
    00217   /**
    00218   * Virtual redirection for operator<<(const char* value).
    00219   */
    00220   virtual void outString(const char *d)
    00221   { writeString(d,*this); }
    00222
    00223
    00224   /**
    00225   * Virtual redirection for operator<<(Out& (*f)(Out&)) that writes
    00226   * the symbol "endl";
    00227   */
    00228   virtual void outEndL()
    00229   { writeEndL(*this); }
    00230 };
    00231
    00232
    00233 /**
    00234 * @class OutBinary
    00235 *
    00236 * Formats data binary to be used in streams.
    00237 * The physical writing is then done by OutStream derivates.
    00238 */
    00239 class OutBinary : public StreamWriter
    00240 {
    00241 protected:
    00242 /**
    00243 * Writes a character to a stream.
    00244 * @param d the data to write.
    00245 * @param stream the stream to write on.
    00246   */
    00247   virtual void writeChar(char d, PhysicalOutStream& stream)
    00248   { stream.writeToStream(&d,sizeof(d)); }
    00249
    00250   /**
    00251   * Writes a unsigned character to a stream.
    00252   * @param d the data to write.
    00253   * @param stream the stream to write on.
    00254   */
    00255   virtual void writeUChar(unsigned char d, PhysicalOutStream& stream)
    00256   { stream.writeToStream(&d,sizeof(d)); }
    00257
    00258   /**
    00259   * Writes a short to a stream.
    00260   * @param d the data to write.
    00261   * @param stream the stream to write on.
    00262   */
    00263   virtual void writeShort(short d, PhysicalOutStream& stream)
    00264   { stream.writeToStream(&d,sizeof(d)); }
    00265
    00266   /**
    00267   * Writes a unsigned short to a stream.
    00268   * @param d the data to write.
    00269   * @param stream the stream to write on.
    00270   */
    00271   virtual void writeUShort(unsigned short d, PhysicalOutStream& stream)
    00272   { stream.writeToStream(&d,sizeof(d)); }
    00273
    00274   /**
    00275   * Writes a int to a stream.
    00276   * @param d the data to write.
    00277   * @param stream the stream to write on.
    00278   */
    00279   virtual void writeInt(int d, PhysicalOutStream& stream)
    00280   { stream.writeToStream(&d,sizeof(d)); }
    00281
    00282   /**
    00283   * Writes a unsigned int to a stream.
    00284   * @param d the data to write.
    00285   * @param stream the stream to write on.
    00286   */
    00287   virtual void writeUInt(unsigned int d, PhysicalOutStream& stream)
    00288   { stream.writeToStream(&d,sizeof(d)); }
    00289
    00290   /**
    00291   * Writes a long to a stream.
    00292   * @param d the data to write.
    00293   * @param stream the stream to write on.
    00294   */
    00295   virtual void writeLong(long d, PhysicalOutStream& stream)
    00296   { stream.writeToStream(&d,sizeof(d)); }
    00297
    00298   /**
    00299   * Writes a unsigned long to a stream.
    00300   * @param d the data to write.
    00301   * @param stream the stream to write on.
    00302   */
    00303   virtual void writeULong(unsigned long d, PhysicalOutStream& stream)
    00304   { stream.writeToStream(&d,sizeof(d)); }
    00305
    00306   /**
    00307   * Writes a float to a stream.
    00308   * @param d the data to write.
    00309   * @param stream the stream to write on.
    00310   */
    00311   virtual void writeFloat(float d, PhysicalOutStream& stream)
    00312   { stream.writeToStream(&d,sizeof(d)); }
    00313
    00314   /**
    00315   * Writes a double to a stream.
    00316   * @param d the data to write.
    00317   * @param stream the stream to write on.
    00318   */
    00319   virtual void writeDouble(double d, PhysicalOutStream& stream)
    00320   { stream.writeToStream(&d,sizeof(d)); }
    00321
    00322   /**
    00323   * Writes a string to a stream.
    00324   * @param d the data to write.
    00325   * @param stream the stream to write on.
    00326   */
    00327   virtual void writeString(const char *d, PhysicalOutStream& stream)
    00328   { int size = (int)strlen(d); stream.writeToStream(&size,sizeof(size)); stream.writeToStream(d,size);}
    00329
    00330   /**
    00331   * Writes a 'end of line' to a stream.
    00332   * @param stream the stream to write on.
    00333   */
    00334   virtual void writeEndL(PhysicalOutStream& stream) {};
    00335
    00336   /**
    00337   * The function writes a number of bytes into the stream.
    00338   * @param p The address the data is located at.
    00339   * @param size The number of bytes to be written.
    00340   * @param stream the stream to write on.
    00341   */
    00342   virtual void writeData(const void* p,int size, PhysicalOutStream& stream)
    00343   { stream.writeToStream(p,size); }
    00344
    00345 };
    00346
    00347 /**
    00348 * @class OutText
    00349 *
    00350 * Formats data as text to be used in streams.
    00351 * The physical writing is then done by PhysicalOutStream derivates.
    00352 */
    00353 class OutText : public StreamWriter
    00354 {
    00355 private:
    00356   /** A buffer for formatting the numeric data to a text format. */
    00357   char buf[50];
    00358 protected:
    00359 /**
    00360 * Writes a character to a stream.
    00361 * @param d the data to write.
    00362 * @param stream the stream to write on.
    00363   */
    00364   virtual void writeChar(char d, PhysicalOutStream& stream)
    00365   { sprintf(buf," %d",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00366
    00367   /**
    00368   * Writes a unsigned character to a stream.
    00369   * @param d the data to write.
    00370   * @param stream the stream to write on.
    00371   */
    00372   virtual void writeUChar(unsigned char d, PhysicalOutStream& stream)
    00373   { sprintf(buf," %u",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00374
    00375   /**
    00376   * Writes a short to a stream.
    00377   * @param d the data to write.
    00378   * @param stream the stream to write on.
    00379   */
    00380   virtual void writeShort(short d, PhysicalOutStream& stream)
    00381   { sprintf(buf," %d",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00382
    00383   /**
    00384   * Writes a unsigned short to a stream.
    00385   * @param d the data to write.
    00386   * @param stream the stream to write on.
    00387   */
    00388   virtual void writeUShort(unsigned short d, PhysicalOutStream& stream)
    00389   { sprintf(buf," %u",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00390
    00391   /**
    00392   * Writes a int to a stream.
    00393   * @param d the data to write.
    00394   * @param stream the stream to write on.
    00395   */
    00396   virtual void writeInt(int d, PhysicalOutStream& stream)
    00397   { sprintf(buf," %d",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00398
    00399   /**
    00400   * Writes a unsigned int to a stream.
    00401   * @param d the data to write.
    00402   * @param stream the stream to write on.
    00403   */
    00404   virtual void writeUInt(unsigned int d, PhysicalOutStream& stream)
    00405   { sprintf(buf," %u",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00406
    00407   /**
    00408   * Writes a long to a stream.
    00409   * @param d the data to write.
    00410   * @param stream the stream to write on.
    00411   */
    00412   virtual void writeLong(long d, PhysicalOutStream& stream)
    00413   { sprintf(buf," %ld",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00414
    00415   /**
    00416   * Writes a unsigned long to a stream.
    00417   * @param d the data to write.
    00418   * @param stream the stream to write on.
    00419   */
    00420   virtual void writeULong(unsigned long d, PhysicalOutStream& stream)
    00421   { sprintf(buf," %lu",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00422
    00423   /**
    00424   * Writes a float to a stream.
    00425   * @param d the data to write.
    00426   * @param stream the stream to write on.
    00427   */
    00428   virtual void writeFloat(float d, PhysicalOutStream& stream)
    00429   { sprintf(buf," %g",double(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00430
    00431   /**
    00432   * Writes a double to a stream.
    00433   * @param d the data to write.
    00434   * @param stream the stream to write on.
    00435   */
    00436   virtual void writeDouble(double d, PhysicalOutStream& stream)
    00437   { sprintf(buf," %g",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00438
    00439   /**
    00440   * Writes a string to a stream.
    00441   * @param d the data to write.
    00442   * @param stream the stream to write on.
    00443   */
    00444   virtual void writeString(const char *d, PhysicalOutStream& stream);
    00445
    00446   /**
    00447   * Writes a 'end of line' to a stream.
    00448   * @param stream the stream to write on.
    00449   */
    00450   virtual void writeEndL(PhysicalOutStream& stream)
    00451   { sprintf(buf,"\r\n"); stream.writeToStream(buf,(int)strlen(buf)); }
    00452
    00453   /**
    00454   * The function writes a number of bytes into the stream.
    00455   * @param p The address the data is located at.
    00456   * @param size The number of bytes to be written.
    00457   * @param stream the stream to write on.
    00458   */
    00459   virtual void writeData(const void* p,int size, PhysicalOutStream& stream);
    00460 };
    00461
    00462 /**
    00463 * @class OutTextRaw
    00464 *
    00465 * Formats data as raw text to be used in streams.
    00466 * The physical writing is then done by PhysicalOutStream derivates.
    00467 * Different from OutText, OutTextRaw does not escape spaces
    00468 * and other special characters and no spaces are inserted before numbers.
    00469 * (The result of the OutTextRaw StreamWriter is the same as the result of "std::cout")
    00470 */
    00471 class OutTextRaw : public StreamWriter
    00472 {
    00473 private:
    00474   /** A buffer for formatting the numeric data to a text format. */
    00475   char buf[50];
    00476 protected:
    00477 /**
    00478 * Writes a character to a stream.
    00479 * @param d the data to write.
    00480 * @param stream the stream to write on.
    00481   */
    00482   virtual void writeChar(char d, PhysicalOutStream& stream)
    00483   { sprintf(buf,"%d",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00484
    00485   /**
    00486   * Writes a unsigned character to a stream.
    00487   * @param d the data to write.
    00488   * @param stream the stream to write on.
    00489   */
    00490   virtual void writeUChar(unsigned char d, PhysicalOutStream& stream)
    00491   { sprintf(buf,"%u",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00492
    00493   /**
    00494   * Writes a short to a stream.
    00495   * @param d the data to write.
    00496   * @param stream the stream to write on.
    00497   */
    00498   virtual void writeShort(short d, PhysicalOutStream& stream)
    00499   { sprintf(buf,"%d",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00500
    00501   /**
    00502   * Writes a unsigned short to a stream.
    00503   * @param d the data to write.
    00504   * @param stream the stream to write on.
    00505   */
    00506   virtual void writeUShort(unsigned short d, PhysicalOutStream& stream)
    00507   { sprintf(buf,"%u",int(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00508
    00509   /**
    00510   * Writes a int to a stream.
    00511   * @param d the data to write.
    00512   * @param stream the stream to write on.
    00513   */
    00514   virtual void writeInt(int d, PhysicalOutStream& stream)
    00515   { sprintf(buf,"%d",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00516
    00517   /**
    00518   * Writes a unsigned int to a stream.
    00519   * @param d the data to write.
    00520   * @param stream the stream to write on.
    00521   */
    00522   virtual void writeUInt(unsigned int d, PhysicalOutStream& stream)
    00523   { sprintf(buf,"%u",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00524
    00525   /**
    00526   * Writes a long to a stream.
    00527   * @param d the data to write.
    00528   * @param stream the stream to write on.
    00529   */
    00530   virtual void writeLong(long d, PhysicalOutStream& stream)
    00531   { sprintf(buf,"%ld",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00532
    00533   /**
    00534   * Writes a unsigned long to a stream.
    00535   * @param d the data to write.
    00536   * @param stream the stream to write on.
    00537   */
    00538   virtual void writeULong(unsigned long d, PhysicalOutStream& stream)
    00539   { sprintf(buf,"%lu",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00540
    00541   /**
    00542   * Writes a float to a stream.
    00543   * @param d the data to write.
    00544   * @param stream the stream to write on.
    00545   */
    00546   virtual void writeFloat(float d, PhysicalOutStream& stream)
    00547   { sprintf(buf,"%g",double(d)); stream.writeToStream(buf,(int)strlen(buf)); }
    00548
    00549   /**
    00550   * Writes a double to a stream.
    00551   * @param d the data to write.
    00552   * @param stream the stream to write on.
    00553   */
    00554   virtual void writeDouble(double d, PhysicalOutStream& stream)
    00555   { sprintf(buf,"%g",d); stream.writeToStream(buf,(int)strlen(buf)); }
    00556
    00557   /**
    00558   * Writes a string to a stream.
    00559   * @param d the data to write.
    00560   * @param stream the stream to write on.
    00561   */
    00562   virtual void writeString(const char *d, PhysicalOutStream& stream);
    00563
    00564   /**
    00565   * Writes a 'end of line' to a stream.
    00566   * @param stream the stream to write on.
    00567   */
    00568   virtual void writeEndL(PhysicalOutStream& stream)
    00569   { sprintf(buf,"\r\n"); stream.writeToStream(buf,(int)strlen(buf)); }
    00570
    00571   /**
    00572   * The function writes a number of bytes into the stream.
    00573   * @param p The address the data is located at.
    00574   * @param size The number of bytes to be written.
    00575   * @param stream the stream to write on.
    00576   */
    00577   virtual void writeData(const void* p,int size, PhysicalOutStream& stream);
    00578 };
    00579
    00580
    00581
    00582 /**
    00583 * @class OutFile.
    00584 *
    00585 * An PhysicalOutStream that writes the data to a file.
    00586 */
    00587 class OutFile : public PhysicalOutStream
    00588 {
    00589 private:
    00590   File* stream; /**< Object representing the file. */
    00591
    00592 public:
    00593   /** Default constructor */
    00594   OutFile() : stream(0) {};
    00595
    00596   /** Destructor */
    00597   ~OutFile() { if (stream != 0) delete stream; }
    00598
    00599   /**
    00600   * The function states whether the file actually exists.
    00601   * @return Does the file exist?
    00602   */
    00603   virtual bool exists() const {return (stream != 0 ? stream->exists() : false);}
    00604
    00605 protected:
    00606   /**
    00607   * Opens the stream.
    00608   * @param name The name of the file to open. It will be interpreted
    00609   *             as relative to the configuration directory. If the file
    00610   *             does not exist, it will be created. If it already
    00611   *             exists, its previous contents will be discared.
    00612   */
    00613   void open(const char* name)
    00614   { stream=new File(name,"wb"); }
    00615
    00616   /**
    00617   * Opens the stream.
    00618   * @param name The name of the file to open. It will be interpreted
    00619   *             as relative to the configuration directory. If the file
    00620   *             does not exist, it will be created. If it already
    00621   *             exists, its previous contents will be preserved,
    00622   *             if append = true.
    00623   * @param append Determines, if the file content is preserved or discared.
    00624   */
    00625   void open(const char* name, bool append)
    00626   { stream = append ? new File(name,"ab") : new File(name,"wb");}
    00627
    00628   /**
    00629   * The function writes a number of bytes into the file.
    00630   * @param p The address the data is located at.
    00631   * @param size The number of bytes to be written.
    00632   */
    00633   virtual void writeToStream(const void *p,int size)
    00634   { if (stream!=0) stream->write(p,size); }
    00635 };
    00636
    00637 /**
    00638 * @class OutMemory.
    00639 *
    00640 * A  PhysicalOutStream that writes the data to a memory block.
    00641 */
    00642 class OutMemory : public PhysicalOutStream
    00643 {
    00644 private:
    00645   char* memory; /**< Points to the next byte to write at. */
    00646   int length; /**< The number of stored bytes */
    00647   void* start; /**< Points to the first byte */
    00648
    00649 public:
    00650   /** Default constructor */
    00651   OutMemory() : memory(0), length(0), start(0) {}
    00652
    00653   /**
    00654   * Returns the number of written bytes
    00655   */
    00656   int getLength() { return length; }
    00657
    00658   /**
    00659   * Returns the address of the first byte
    00660   */
    00661   void* getMemory() { return start; }
    00662
    00663 protected:
    00664 /**
    00665 * opens the stream.
    00666 * @param mem The address of the memory block into which is written.
    00667   */
    00668   void open(void* mem)
    00669   { memory = (char*)mem; start = mem; length = 0;}
    00670
    00671   /**
    00672   * The function writes a number of bytes into memory.
    00673   * @param p The address the data is located at.
    00674   * @param size The number of bytes to be written.
    00675   */
    00676   virtual void writeToStream(const void *p, int size)
    00677   { if(memory != 0) { memcpy(memory,p,size); memory += size; length += size; } }
    00678 };
    00679
    00680 /**
    00681 * @class OutSize.
    00682 *
    00683 * A PhysicalOutStream that doesn't write any data. Instead it works as a
    00684 * counter that determines how many bytes would be streamed into memory.
    00685 * It can be used to determine the size of the memory block that is
    00686 * required as the parameter for an instance of class OutMemoryStream.
    00687 */
    00688 class OutSize : public PhysicalOutStream
    00689 {
    00690 private:
    00691   unsigned size; /**< Accumulator of the required number of bytes. */
    00692
    00693 public:
    00694 /**
    00695 * The function resets the counter to zero.
    00696   */
    00697   void reset() {size = 0;}
    00698
    00699   /**
    00700   * Constructor.
    00701   */
    00702   OutSize() {reset();}
    00703
    00704   /**
    00705   * The function returns the number of bytes required to store the
    00706   * data written so far.
    00707   * @return The size of the memory block required for the data written.
    00708   */
    00709   unsigned getSize() const {return size;}
    00710
    00711 protected:
    00712 /**
    00713 * The function counts the number of bytes that should be written.
    00714 * @param p The address the data is located at.
    00715 * @param s The number of bytes to be written.
    00716   */
    00717   virtual void writeToStream(const void* p,int s) {size += s;}
    00718
    00719 };
    00720
    00721 /**
    00722 * @class OutBinaryFile
    00723 *
    00724 * A binary stream into a file.
    00725 */
    00726 class OutBinaryFile : public OutStream<OutFile,OutBinary>
    00727 {
    00728 public:
    00729   /**
    00730   * Constructor.
    00731   * @param name The name of the file to open. It will be interpreted
    00732   *             as relative to the configuration directory. If the file
    00733   *             does not exist, it will be created. If it already
    00734   *             exists, its previous contents will be discared.
    00735   */
    00736   OutBinaryFile(const char* name)
    00737   { open(name); }
    00738
    00739   /**
    00740   * Constructor.
    00741   * @param name The name of the file to open. It will be interpreted
    00742   *             as relative to the configuration directory. If the file
    00743   *             does not exist, it will be created. If it already
    00744   *             exists, its previous contents will be preserved,
    00745   *             if append = true.
    00746   * @param append Determines, if the file content is preserved or discared.
    00747   */
    00748   OutBinaryFile(const char* name, bool append)
    00749   { open(name, append); }
    00750 };
    00751
    00752 /**
    00753 * @class OutBinaryMemory
    00754 *
    00755 * A binary stream into a memory region.
    00756 */
    00757 class OutBinaryMemory : public OutStream<OutMemory,OutBinary>
    00758 {
    00759 public:
    00760 /**
    00761 * Constructor.
    00762 * @param mem The address of the memory block into which is written.
    00763   */
    00764   OutBinaryMemory(void* mem)
    00765   { open(mem); }
    00766 };
    00767
    00768 /**
    00769 * @class OutBinarySize
    00770 *
    00771 * A binary stream size counter
    00772 */
    00773 class OutBinarySize : public OutStream<OutSize,OutBinary>
    00774 {
    00775 public:
    00776 /**
    00777 * Constructor.
    00778   */
    00779   OutBinarySize() {}
    00780 };
    00781
    00782 /**
    00783 * @class OutTextFile
    00784 *
    00785 * A text stream into a file.
    00786 */
    00787 class OutTextFile : public OutStream<OutFile,OutText>
    00788 {
    00789 public:
    00790   /**
    00791   * Constructor.
    00792   * @param name The name of the file to open. It will be interpreted
    00793   *             as relative to the configuration directory. If the file
    00794   *             does not exist, it will be created. If it already
    00795   *             exists, its previous contents will be discared.
    00796   */
    00797   OutTextFile(const char* name)
    00798   { open(name); }
    00799
    00800   /**
    00801   * Constructor.
    00802   * @param name The name of the file to open. It will be interpreted
    00803   *             as relative to the configuration directory. If the file
    00804   *             does not exist, it will be created. If it already
    00805   *             exists, its previous contents will be preserved,
    00806   *             if append = true.
    00807   * @param append Determines, if the file content is preserved or discared.
    00808   */
    00809   OutTextFile(const char* name, bool append)
    00810   { open(name, append); }
    00811 };
    00812
    00813 /**
    00814 * @class OutTextRawFile
    00815 *
    00816 * A text stream into a file.
    00817 */
    00818 class OutTextRawFile : public OutStream<OutFile,OutTextRaw>
    00819 {
    00820 public:
    00821   /**
    00822   * Constructor.
    00823   * @param name The name of the file to open. It will be interpreted
    00824   *             as relative to the configuration directory. If the file
    00825   *             does not exist, it will be created. If it already
    00826   *             exists, its previous contents will be discared.
    00827   */
    00828   OutTextRawFile(const char* name)
    00829   { open(name); }
    00830
    00831   /**
    00832   * Constructor.
    00833   * @param name The name of the file to open. It will be interpreted
    00834   *             as relative to the configuration directory. If the file
    00835   *             does not exist, it will be created. If it already
    00836   *             exists, its previous contents will be preserved,
    00837   *             if append = true.
    00838   * @param append Determines, if the file content is preserved or discared.
    00839   */
    00840   OutTextRawFile(const char* name, bool append)
    00841   { open(name, append); }
    00842 };
    00843
    00844 /**
    00845 * @class OutTextMemory
    00846 *
    00847 * A text stream into a memory region.
    00848 */
    00849 class OutTextMemory : public OutStream<OutMemory,OutText>
    00850 {
    00851 public:
    00852 /**
    00853 * Constructor.
    00854 * @param mem The address of the memory block into which is written.
    00855   */
    00856   OutTextMemory(void* mem)
    00857   { open(mem); }
    00858 };
    00859
    00860 /**
    00861 * @class OutTextRawMemory
    00862 *
    00863 * A text stream into a memory region.
    00864 */
    00865 class OutTextRawMemory : public OutStream<OutMemory,OutTextRaw>
    00866 {
    00867 public:
    00868 /**
    00869 * Constructor.
    00870 * @param mem The address of the memory block into which is written.
    00871   */
    00872   OutTextRawMemory(void* mem)
    00873   { open(mem); }
    00874 };
    00875
    00876 /**
    00877 * @class OutTextSize
    00878 *
    00879 * A Text stream size counter
    00880 */
    00881 class OutTextSize : public OutStream<OutSize,OutText>
    00882 {
    00883 public:
    00884 /**
    00885 * Constructor.
    00886   */
    00887   OutTextSize() {}
    00888 };
    00889
    00890 /**
    00891 * @class OutTextRawSize
    00892 *
    00893 * A Text stream size counter
    00894 */
    00895 class OutTextRawSize : public OutStream<OutSize,OutTextRaw>
    00896 {
    00897 public:
    00898 /**
    00899 * Constructor.
    00900   */
    00901   OutTextRawSize() {}
    00902 };
    00903
    00904
    00905
    00906 #endif //__OutStreams_h_