Orocos Real-Time Toolkit  2.6.0
rtstreams.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Oct 10 16:17:00 CEST 2002  rtstreams.hpp 
00003 
00004                         rtstreams.hpp -  description
00005                            -------------------
00006     begin                : Thu October 10 2002
00007     copyright            : (C) 2002 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009  
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/ 
00037  
00038 #include "fosi.h"
00039 
00040 #include "rtconversions.hpp"
00041 #include "rtstreambufs.hpp"
00042 
00043 #ifndef RTSTREAMS_HPP
00044 #define RTSTREAMS_HPP
00045 
00056 namespace RTT
00057 {
00058 namespace os
00059 {
00060 
00076     class RTT_API basic_streams
00077     {
00078 
00079         public:
00080             virtual ~basic_streams();
00081 
00087 /*
00088             virtual void write( const char * c );
00089             virtual void write( const char * c, size_t n );
00090             virtual void write( const string s );
00091             virtual void put( char ch );
00092 */
00098 /*            
00099             virtual string read( int n );
00100             virtual string read( char delimiter );
00101             virtual char read();
00102 */
00103     };
00104 
00113     class RTT_API basic_istreams
00114         : virtual public basic_streams
00115     {
00116 
00117         public:
00118             typedef streambufs::streamsize streamsize;
00119 
00120             basic_istreams( streambufs& s ) : buf(s) {}
00121             virtual ~basic_istreams();
00122 
00123             int get();
00124             basic_istreams& get(char& c);
00125             basic_istreams& get(char* c, streamsize n, char delim);
00126             basic_istreams& get(char* c, char delim);
00127 
00128             basic_istreams& read( char* c, streamsize n );
00129             streamsize readsome( char* c, streamsize n);
00130 
00131 
00132             basic_istreams& operator>>( int &i );
00133             basic_istreams& operator>>( char &c );
00134             basic_istreams& operator>>( double &f );
00135             basic_istreams& operator>>( std::string &s );
00136             basic_istreams& operator>>( unsigned int &u );
00137         private:
00138             streambufs& buf;
00139     };
00140 
00145     class RTT_API basic_ostreams : virtual public basic_streams
00146     {
00147 
00148         public:
00149             typedef streambufs::streamsize streamsize;
00150 
00151             basic_ostreams( streambufs& s ) : buf(s) {}
00152             virtual ~basic_ostreams();
00153 
00154             virtual basic_ostreams& put( char c );
00155             virtual basic_ostreams& write( const char * c, streamsize n );
00156 
00161             basic_ostreams& operator<<( int i );
00162             basic_ostreams& operator<<( long i );
00163             basic_ostreams& operator<<( char c );
00164             basic_ostreams& operator<<( char * c );
00165             basic_ostreams& operator<<( double f );
00166             basic_ostreams& operator<<( std::string s );
00167             basic_ostreams& operator<<( unsigned int u );
00168             basic_ostreams& operator<<( basic_ostreams & ( *f ) ( basic_ostreams & ) );
00169         private:
00170             streambufs& buf;
00171     };
00172 
00173 //#ifdef __KERNEL__
00174 // defined in the namespace os
00178     basic_ostreams& endl( basic_ostreams& );
00179 //#endif
00180 
00184     class RTT_API basic_iostreams
00185         : public basic_istreams, public basic_ostreams
00186     {
00187         public:
00188         basic_iostreams( streambufs& s) 
00189             : basic_istreams(s), basic_ostreams(s) {}
00190     };
00191             
00192 
00193     struct RTT_API print_helper { printbufs printer; };
00194 
00200     class RTT_API printstream
00201         : private print_helper, public basic_ostreams
00202     {
00203 
00204         public:
00205             printstream() : basic_ostreams(printer) {}
00206             virtual ~printstream();
00207     };
00208 
00212     extern printstream cout;
00213     
00214     struct RTT_API string_helper { string_helper() : str() {}; string_helper(const std::string& _init) :  str(_init) {};  stringbufs str; };
00215     
00219     class RTT_API stringstreams
00220         : private string_helper, public basic_iostreams
00221         {
00222             public:
00223                 stringstreams(const std::string& _init) : string_helper(_init), basic_iostreams(str) {}
00224                 stringstreams() : string_helper(), basic_iostreams(str) {}
00225                 virtual ~stringstreams();
00226         };
00227         
00228 }
00229 }
00230 #endif