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

# Tools/Streams/InOut.h

Go to the documentation of this file.

    00001 /**
    00002 * @file InOut.h
    00003 *
    00004 * Definition of the abstract base classes In and Out for streams.
    00005 * Include this header file for declaring streaming operators.
    00006 *
    00007 * @author Thomas Röfer
    00008 * @author Martin Lötzsch
    00009 */
    00010
    00011 #ifndef __InOut_h_
    00012 #define __InOut_h_
    00013
    00014 /**
    00015 * The class Out is the abstract base class for all classes
    00016 * that implement writing into streams.
    00017 */
    00018 class Out
    00019 {
    00020 protected:
    00021 /**
    00022 * Virtual redirection for operator<<(const char& value).
    00023   */
    00024   virtual void outChar(char) = 0;
    00025
    00026   /**
    00027   * Virtual redirection for operator<<(const unsigned char& value).
    00028   */
    00029   virtual void outUChar(unsigned char) = 0;
    00030
    00031   /**
    00032   * Virtual redirection for operator<<(const short& value).
    00033   */
    00034   virtual void outShort(short) = 0;
    00035
    00036   /**
    00037   * Virtual redirection for operator<<(const unsigned short& value).
    00038   */
    00039   virtual void outUShort(unsigned short) = 0;
    00040
    00041   /**
    00042   * Virtual redirection for operator<<(const int& value).
    00043   */
    00044   virtual void outInt(int) = 0;
    00045
    00046   /**
    00047   * Virtual redirection for operator<<(const unsigned& value).
    00048   */
    00049   virtual void outUInt(unsigned int) = 0;
    00050
    00051   /**
    00052   * Virtual redirection for operator<<(const long& value).
    00053   */
    00054   virtual void outLong(long) = 0;
    00055
    00056   /**
    00057   * Virtual redirection for operator<<(const unsigned long& value).
    00058   */
    00059   virtual void outULong(unsigned long) = 0;
    00060
    00061   /**
    00062   * Virtual redirection for operator<<(const float& value).
    00063   */
    00064   virtual void outFloat(float) = 0;
    00065
    00066   /**
    00067   * Virtual redirection for operator<<(const double& value).
    00068   */
    00069   virtual void outDouble(double) = 0;
    00070
    00071   /**
    00072   * Virtual redirection for operator<<(const char* value).
    00073   */
    00074   virtual void outString(const char *) = 0;
    00075
    00076   /**
    00077   * Virtual redirection for operator<<(Out& (*f)(Out&)) that writes
    00078   * the symbol "endl";
    00079   */
    00080   virtual void outEndL() = 0;
    00081
    00082 public:
    00083 /**
    00084 * Operator that writes a char into a stream.
    00085 * @param value The value that is written.
    00086 * @return The stream.
    00087   */
    00088   Out& operator<<(const char value) {outChar(value); return *this;}
    00089
    00090   /**
    00091   * Operator that writes an unsigned char into a stream.
    00092   * @param value The value that is written.
    00093   * @return The stream.
    00094   */
    00095   Out& operator<<(const unsigned char value) {outUChar(value); ; return *this;}
    00096
    00097   /**
    00098   * Operator that writes a short int into a stream.
    00099   * @param value The value that is written.
    00100   * @return The stream.
    00101   */
    00102   Out& operator<<(const short value) {outShort(value); ; return *this;}
    00103
    00104   /**
    00105   * Operator that writes an unsigned short int into a stream.
    00106   * @param value The value that is written.
    00107   * @return The stream.
    00108   */
    00109   Out& operator<<(const unsigned short value) {outUShort(value); ; return *this;}
    00110
    00111   /**
    00112   * Operator that writes an int into a stream.
    00113   * @param value The value that is written.
    00114   * @return The stream.
    00115   */
    00116   Out& operator<<(const int value) {outInt(value); ; return *this;}
    00117
    00118   /**
    00119   * Operator that writes an unsigned int into a stream.
    00120   * @param value The value that is written.
    00121   * @return The stream.
    00122   */
    00123   Out& operator<<(const unsigned int value) {outUInt(value); ; return *this;}
    00124
    00125   /**
    00126   * Operator that writes a long int into a stream.
    00127   * @param value The value that is written.
    00128   * @return The stream.
    00129   */
    00130   Out& operator<<(const long value) {outLong(value); ; return *this;}
    00131
    00132   /**
    00133   * Operator that writes an unsigned long int into a stream.
    00134   * @param value The value that is written.
    00135   * @return The stream.
    00136   */
    00137   Out& operator<<(const unsigned long value) {outULong(value); ; return *this;}
    00138
    00139   /**
    00140   * Operator that writes a float into a stream.
    00141   * @param value The value that is written.
    00142   * @return The stream.
    00143   */
    00144   Out& operator<<(const float value) {outFloat(value); ; return *this;}
    00145
    00146   /**
    00147   * Operator that writes a double into a stream.
    00148   * @param value The value that is written.
    00149   * @return The stream.
    00150   */
    00151   Out& operator<<(const double value) {outDouble(value); ; return *this;}
    00152
    00153   /**
    00154   * Operator that writes a string into a stream.
    00155   * @param value The value that is written.
    00156   * @return The stream.
    00157   */
    00158   Out& operator<<(const char* value) {outString(value); ; return *this;};
    00159
    00160   /**
    00161   * Operator that writes the endl-symbol into a stream.
    00162   * @param f A function that is normally endl.
    00163   * @return The stream.
    00164   */
    00165   Out& operator<<(Out& (*f)(Out&)) {outEndL(); return *this;}
    00166
    00167   /**
    00168   * The function writes a number of bytes into a stream.
    00169   * @param p The address the data is located at.
    00170   * @param size The number of bytes to be written.
    00171   */
    00172   virtual void write(const void* p,int size) = 0;
    00173 };
    00174
    00175
    00176 /**
    00177 * This function can be inserted into a stream to represent an end of line.
    00178 * @param stream The stream the endl-symbol is inserted into.
    00179 * @return The stream.
    00180 */
    00181 inline Out& endl(Out& stream) {return stream;}
    00182
    00183
    00184 /**
    00185 * The class In is the abstract base class for all classes
    00186 * that implement reading from streams.
    00187 */
    00188 class In
    00189 {
    00190 protected:
    00191 /**
    00192 * Virtual redirection for operator>>(char& value).
    00193   */
    00194   virtual void inChar(char&) = 0;
    00195
    00196   /**
    00197   * Virtual redirection for operator>>(unsigend char& value).
    00198   */
    00199   virtual void inUChar(unsigned char&) = 0;
    00200
    00201   /**
    00202   * Virtual redirection for operator>>(short& value).
    00203   */
    00204   virtual void inShort(short&) = 0;
    00205
    00206   /**
    00207   * Virtual redirection for operator>>(unsigend short& value).
    00208   */
    00209   virtual void inUShort(unsigned short&) = 0;
    00210
    00211   /**
    00212   * Virtual redirection for operator>>(int& value).
    00213   */
    00214   virtual void inInt(int&) = 0;
    00215
    00216   /**
    00217   * Virtual redirection for operator>>(unsigend int& value).
    00218   */
    00219   virtual void inUInt(unsigned int&) = 0;
    00220
    00221   /**
    00222   * Virtual redirection for operator>>(long& value).
    00223   */
    00224   virtual void inLong(long&) = 0;
    00225
    00226   /**
    00227   * Virtual redirection for operator>>(unsigend long& value).
    00228   */
    00229   virtual void inULong(unsigned long&) = 0;
    00230
    00231   /**
    00232   * Virtual redirection for operator>>(float& value).
    00233   */
    00234   virtual void inFloat(float&) = 0;
    00235
    00236   /**
    00237   * Virtual redirection for operator>>(double& value).
    00238   */
    00239   virtual void inDouble(double&) = 0;
    00240
    00241   /**
    00242   * Virtual redirection for operator>>(char* value).
    00243   */
    00244   virtual void inString(char*) = 0;
    00245
    00246   /**
    00247   * Virtual redirection for operator>>(In& (*f)(In&)) that reads
    00248   * the symbol "endl";
    00249   */
    00250   virtual void inEndL() = 0;
    00251
    00252 public:
    00253 /**
    00254 * Operator that reads a char from a stream.
    00255 * @param value The value that is read.
    00256 * @return The stream.
    00257   */
    00258   In& operator>>(char& value) {inChar(value); return *this;}
    00259
    00260   /**
    00261   * Operator that reads an unsigned char from a stream.
    00262   * @param value The value that is read.
    00263   * @return The stream.
    00264   */
    00265   In& operator>>(unsigned char& value) {inUChar(value); return *this;}
    00266
    00267   /**
    00268   * Operator that reads a short int from a stream.
    00269   * @param value The value that is read.
    00270   * @return The stream.
    00271   */
    00272   In& operator>>(short& value) {inShort(value); return *this;}
    00273
    00274   /**
    00275   * Operator that reads an unsigned short int from a stream.
    00276   * @param value The value that is read.
    00277   * @return The stream.
    00278   */
    00279   In& operator>>(unsigned short& value) {inUShort(value); return *this;}
    00280
    00281   /**
    00282   * Operator that reads an int from a stream.
    00283   * @param value The value that is read.
    00284   * @return The stream.
    00285   */
    00286   In& operator>>(int& value) {inInt(value); return *this;}
    00287   /**
    00288   * Operator that reads an unsigned int from a stream.
    00289   * @param value The value that is read.
    00290   * @return The stream.
    00291   */
    00292   In& operator>>(unsigned int& value) {inUInt(value); return *this;}
    00293
    00294   /**
    00295   * Operator that reads a long int from a stream.
    00296   * @param value The value that is read.
    00297   * @return The stream.
    00298   */
    00299   In& operator>>(long& value) {inLong(value); return *this;}
    00300   /**
    00301   * Operator that reads an unsigned long int from a stream.
    00302   * @param value The value that is read.
    00303   * @return The stream.
    00304   */
    00305   In& operator>>(unsigned long& value) {inULong(value); return *this;}
    00306
    00307   /**
    00308   * Operator that reads a float from a stream.
    00309   * @param value The value that is read.
    00310   * @return The stream.
    00311   */
    00312
    00313   In& operator>>(float& value) {inFloat(value); return *this;}
    00314
    00315   /**
    00316   * Operator that reads a double from a stream.
    00317   * @param value The value that is read.
    00318   * @return The stream.
    00319   */
    00320   In& operator>>(double& value) {inDouble(value); return *this;}
    00321
    00322   /**
    00323   * Operator that reads a string from a stream.
    00324   * @param value The value that is read. Note that value must point
    00325   *              to a memory area that is large enough to carry
    00326   *              the string.
    00327   * @return The stream.
    00328   */
    00329   In& operator>>(char* value) {inString(value); return *this;};
    00330
    00331   /**
    00332   * Operator that reads the endl-symbol from a stream.
    00333   * @param f A function that is normally endl.
    00334   * @return The stream.
    00335   */
    00336   In& operator>>(In& (*f)(In&)) {inEndL(); return *this;}
    00337
    00338   /**
    00339   * The function reads a number of bytes from a stream.
    00340   * @param p The address the data is written to. Note that p
    00341   *          must point to a memory area that is at least
    00342   *          "size" bytes large.
    00343   * @param size The number of bytes to be read.
    00344   */
    00345   virtual void read(void* p,int size) = 0;
    00346
    00347   /**
    00348   * The function skips a number of bytes in a stream.
    00349   * @param size The number of bytes to be skipped.
    00350   */
    00351   virtual void skip(int size) = 0;
    00352
    00353   /**
    00354   * Determines whether the end of file has been reached.
    00355   */
    00356   virtual bool eof() const = 0;
    00357 };
    00358
    00359
    00360 /**
    00361 * This function can be read from a stream to represent an end of line.
    00362 * @param stream The stream the endl-symbol is read from.
    00363 * @return The stream.
    00364 */
    00365 inline In& endl(In& stream) {return stream;}
    00366
    00367
    00368
    00369 #endif //__InOut_h_