stream.h
资源名称:leda.tar.gz [点击查看]
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:5k
源码类别:
数值算法/人工智能
开发平台:
MultiPlatform
- /*******************************************************************************
- +
- + LEDA-R 3.2.3
- +
- + stream.h
- +
- + Copyright (c) 1995 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 66123 Saarbruecken, Germany
- + All rights reserved.
- +
- *******************************************************************************/
- #ifndef LEDA_STREAM_H
- #define LEDA_STREAM_H
- #include <LEDA/basic.h>
- #if defined (__ZTC__)
- #include <fstream.hpp>
- #include <strstream.hpp>
- /* bug in ZORTECH library ?
- cannot derive from streams */
- typedef ifstream file_istream;
- typedef ofstream file_ostream;
- typedef istrstream string_istream;
- typedef ostrstream string_ostream;
- #else
- #include <fstream.h>
- #include <strstream.h>
- /*{Manpage {file_istream} {} {File Input Streams} }*/
- struct file_istream : public ifstream {
- /*{Mdefinition
- An instance $I$ of the data type $file_istream$ is an CC istream
- connected to a file $F$, i.e., all input operations or operators
- applied to $I$ read from $F$. }*/
- /*{Mcreation I }*/
- file_istream(char* s) : ifstream(s) {}
- file_istream(string s) : ifstream(~s) {}
- /*{Mcreate creates an instance $I$ of type file_istream connected to
- file $s$. }*/
- /*{Moperations 2 5.5 }*/
- /*{Mtext
- All operations and operators ($>>$) defined for CC istreams can
- be applied to file input streams as well.
- }*/
- bool open(string s) { ifstream::open(~s); return !fail(); }
- };
- /*{Manpage {file_ostream} {} {File Output Streams} }*/
- struct file_ostream : public ofstream {
- /*{Mdefinition
- An instance $O$ of the data type $file_ostream$ is an CC ostream
- connected to a file $F$, i.e., all output operations or operators
- applied to $O$ write to $F$. }*/
- /*{Mcreation O }*/
- file_ostream(string s) : ofstream(~s) {}
- file_ostream(char* s) : ofstream(s) {}
- /*{Mcreate creates an instance $O$ of type file_ostream connected to
- file $s$.}*/
- /*{Moperations 2 5.5 }*/
- /*{Mtext
- All operations and operators ($<<$) defined for CC ostreams can
- be applied to file output streams as well.
- }*/
- bool open(string s) { ofstream::open(~s); return !fail(); }
- };
- /*{Manpage {string_istream} {} {String Input Streams} }*/
- struct string_istream : public istrstream {
- /*{Mdefinition
- An instance $I$ of the data type $string_istream$ is an CC istream
- connected to a string $s$, i.e., all input operations or operators
- applied to $I$ read from $s$. }*/
- /*{Mcreation I }*/
- string_istream(char* s) : istrstream(s) {}
- string_istream(string s) : istrstream(~s) {}
- /*{Mcreate creates an instance $I$ of type string_istream connected to
- the string $s$. }*/
- string_istream(int argc, char** argv) : istrstream(~string(argc,argv)) {}
- /*{Moperations 2 5.5 }*/
- /*{Mtext
- All operations and operators ($>>$) defined for CC istreams can
- be applied to string input streams as well.
- }*/
- };
- /*{Manpage {string_ostream} {} {String Output Streams} }*/
- struct string_ostream : public ostrstream {
- /*{Mdefinition
- An instance $O$ of the data type $string_ostream$ is an CC ostream
- connected to an internal string buffer, i.e., all output operations
- or operators applied to $O$ write into this internal buffer. The current
- value of the buffer is called the contents of $O$.}*/
- /*{Mcreation O }*/
- string_ostream() {};
- /*{Mcreate creates an instance $O$ of type string_ostream.}*/
- /*{Moperations 2 5.5 }*/
- string str() { return ostrstream::str(); };
- /*{Mop returns the current contents of $O$.}*/
- /*{Mtext
- All operations and operators ($<<$) defined for CC ostreams can
- be applied to string output streams as well.
- }*/
- };
- #endif
- #if !defined(unix) || defined(__lucid)
- typedef file_ostream cmd_ostream;
- typedef file_istream cmd_istream;
- #else
- #include <stdio.h>
- /*{Manpage {cmd_istream} {} {Command Input Streams} }*/
- struct cmd_istream : public ifstream
- {
- /*{Mdefinition
- An instance $I$ of the data type $cmd_istream$ is an CC istream
- connected to the output of a shell command $cmd$, i.e., all input operations
- or operators applied to $I$ read from the standard output of command $cmd$. }*/
- /*{Mcreation I }*/
- cmd_istream(char* cmd) : ifstream(fileno(popen(cmd,"r"))) {}
- cmd_istream(string cmd) : ifstream(fileno(popen(~cmd,"r"))) {}
- /*{Mcreate creates an instance $I$ of type cmd_istream connected to the
- output of command $cmd$. }*/
- /*{Moperations 2 5.5 }*/
- /*{Mtext
- All operations and operators ($>>$) defined for CC istreams can
- be applied to command input streams as well.
- }*/
- };
- /*{Manpage {cmd_ostream} {} {Command Output Streams} }*/
- struct cmd_ostream : public ofstream {
- /*{Mdefinition
- An instance $O$ of the data type $cmd_ostream$ is an CC ostream
- connected to the input of a shell command $cmd$, i.e., all output operations
- or operators applied to $O$ write into the standard input of command $cmd$. }*/
- /*{Mcreation O }*/
- cmd_ostream(char* cmd) : ofstream(fileno(popen(cmd,"w"))) {}
- cmd_ostream(string cmd) : ofstream(fileno(popen(~cmd,"w"))) {}
- /*{Mcreate
- creates an instance $O$ of type cmd_ostream connected to the input of
- command $cmd$. }*/
- /*{Moperations 2 5.5 }*/
- /*{Mtext
- All operations and operators ($<<$) defined for CC ostreams can
- be applied to command output streams as well.
- }*/
- };
- #endif
- #endif