00001 #ifndef _STREAM_H_
00002 #define _STREAM_H_
00003
00004 #include "Object.h"
00005 #include <iostream>
00006 #include <string>
00007 #include <fstream>
00008 #include <stdio.h>
00009 #include "ObjectPool.h"
00010 #include "ObjectParser.h"
00011 #include "typetraits.h"
00012
00013 namespace FD {
00014
00015
00016
00017
00018
00022 class Stream : public Object
00023 {
00024 protected:
00025 int owner;
00026 public:
00027 Stream(bool _owner=true)
00028 : owner(_owner)
00029 {}
00030 virtual ~Stream() {}
00031 };
00032
00036 class IStream : virtual public Stream {
00037
00038 std::istream *int_istream;
00039 public:
00040 IStream(std::istream *_str, bool _owner=true)
00041 : Stream(_owner)
00042 , int_istream(_str)
00043 {}
00044 IStream &read (char *ch, int len) {int_istream->read(ch,len); return *this;}
00045 int gcount() {return int_istream->gcount();}
00046 int eof() {return int_istream->eof();}
00047 int fail() {return int_istream->fail();}
00048 IStream &getline (char *ch, int len) {int_istream->getline(ch,len); return *this;}
00049 operator std::istream &() {return *int_istream;}
00050 void printOn(std::ostream &out) const {out << "<IStream unknown>";}
00051 ~IStream() {if (owner) {delete dynamic_cast<std::istream *>(int_istream);owner=false;}}
00052
00053 IStream &seekg (int pos, std::ios::seekdir dir) {int_istream->seekg(pos, dir); return *this;}
00054
00055 template <class T>
00056 IStream &operator >> (T &obj) {*int_istream >> obj; return *this;}
00057
00058 };
00059
00063 class OStream : virtual public Stream {
00064 std::ostream *int_ostream;
00065 public:
00066 OStream(std::ostream *_str, bool _owner=true)
00067 : Stream(_owner)
00068 , int_ostream(_str)
00069 {}
00070 OStream &write (const char *ch, int len) {int_ostream->write(ch,len); return *this;}
00071 int eof() {return int_ostream->eof();}
00072 int fail() {return int_ostream->fail();}
00073 void flush() {int_ostream->flush();}
00074 operator std::ostream &() {return *int_ostream;}
00075 void printOn(std::ostream &out) const {out << "<OStream unknown>";}
00076 ~OStream() {if (owner) {delete dynamic_cast<std::ostream *>(int_ostream);owner=false;}}
00077
00078 OStream &seekp (int pos, std::ios::seekdir dir) {int_ostream->seekp(pos, dir); return *this;}
00079
00080 template <class T>
00081 OStream &operator << (const T &obj) {*int_ostream << obj; return *this;}
00082
00083 };
00084
00088 class IOStream : public IStream, public OStream {
00089 std::iostream *int_iostream;
00090 public:
00091 IOStream(std::iostream *_str, bool _owner=true)
00092 : Stream(_owner)
00093 , IStream(_str, _owner)
00094 , OStream(_str, _owner)
00095 , int_iostream(_str)
00096 {}
00097 int eof() {return int_iostream->eof();}
00098 int fail() {return int_iostream->fail();}
00099 operator std::iostream &() {return *int_iostream;}
00100 void printOn(std::ostream &out) const {out << "<IOStream unknown>";}
00101 ~IOStream() {if (owner) {delete dynamic_cast<std::iostream *>(int_iostream);owner=false;}}
00102
00103 IOStream &seekg (int pos, std::ios::seekdir dir) {int_iostream->seekg(pos, dir); return *this;}
00104 IOStream &seekp (int pos, std::ios::seekdir dir) {int_iostream->seekp(pos, dir); return *this;}
00105
00106 };
00107
00108
00109 }
00110
00111
00112
00113
00114 #endif