rtstreams.hpp

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 
00046 namespace RTT
00047 {
00057 namespace rt_std
00058 {
00059 
00075     class RTT_API basic_streams
00076     {
00077 
00078         public:
00079             virtual ~basic_streams();
00080 
00086 /*
00087             virtual void write( const char * c );
00088             virtual void write( const char * c, size_t n );
00089             virtual void write( const string s );
00090             virtual void put( char ch );
00091 */
00097 /*            
00098             virtual string read( int n );
00099             virtual string read( char delimiter );
00100             virtual char read();
00101 */
00102     };
00103 
00112     class RTT_API basic_istreams
00113         : virtual public basic_streams
00114     {
00115 
00116         public:
00117             typedef streambufs::streamsize streamsize;
00118 
00119             basic_istreams( streambufs& s ) : buf(s) {}
00120             virtual ~basic_istreams();
00121 
00122             int get();
00123             basic_istreams& get(char& c);
00124             basic_istreams& get(char* c, streamsize n, char delim);
00125             basic_istreams& get(char* c, char delim);
00126 
00127             basic_istreams& read( char* c, streamsize n );
00128             streamsize readsome( char* c, streamsize n);
00129 
00130 
00131             basic_istreams& operator>>( int &i );
00132             basic_istreams& operator>>( char &c );
00133             basic_istreams& operator>>( double &f );
00134             basic_istreams& operator>>( std::string &s );
00135             basic_istreams& operator>>( unsigned int &u );
00136         private:
00137             streambufs& buf;
00138     };
00139 
00144     class RTT_API basic_ostreams : virtual public basic_streams
00145     {
00146 
00147         public:
00148             typedef streambufs::streamsize streamsize;
00149 
00150             basic_ostreams( streambufs& s ) : buf(s) {}
00151             virtual ~basic_ostreams();
00152 
00153             virtual basic_ostreams& put( char c );
00154             virtual basic_ostreams& write( const char * c, streamsize n );
00155 
00160             basic_ostreams& operator<<( int i );
00161             basic_ostreams& operator<<( long i );
00162             basic_ostreams& operator<<( char c );
00163             basic_ostreams& operator<<( char * c );
00164             basic_ostreams& operator<<( double f );
00165             basic_ostreams& operator<<( std::string s );
00166             basic_ostreams& operator<<( unsigned int u );
00167             basic_ostreams& operator<<( basic_ostreams & ( *f ) ( basic_ostreams & ) );
00168         private:
00169             streambufs& buf;
00170     };
00171 
00172 //#ifdef __KERNEL__
00173 // defined in the namespace rt_std
00177     basic_ostreams& endl( basic_ostreams& );
00178 //#endif
00179 
00183     class RTT_API basic_iostreams
00184         : public basic_istreams, public basic_ostreams
00185     {
00186         public:
00187         basic_iostreams( streambufs& s) 
00188             : basic_istreams(s), basic_ostreams(s) {}
00189     };
00190             
00191 
00192     struct RTT_API print_helper { printbufs printer; };
00193 
00199     class RTT_API printstream
00200         : private print_helper, public basic_ostreams
00201     {
00202 
00203         public:
00204             printstream() : basic_ostreams(printer) {}
00205             virtual ~printstream();
00206     };
00207 
00211     extern printstream cout;
00212     
00213     struct RTT_API string_helper { string_helper() : str() {}; string_helper(const std::string& _init) :  str(_init) {};  stringbufs str; };
00214     
00218     class RTT_API stringstreams
00219         : private string_helper, public basic_iostreams
00220         {
00221             public:
00222                 stringstreams(const std::string& _init) : string_helper(_init), basic_iostreams(str) {}
00223                 stringstreams() : string_helper(), basic_iostreams(str) {}
00224                 virtual ~stringstreams();
00225         };
00226         
00227 }
00228 }
00229 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3