Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

IOStream_T.cpp

Go to the documentation of this file.
00001 // $Id: IOStream_T.cpp,v 1.1.1.3 2001/12/04 14:33:02 chad Exp $
00002 
00003 #ifndef ACE_IOSTREAM_T_C
00004 #define ACE_IOSTREAM_T_C
00005 
00006 #include "ace/IOStream_T.h"
00007 
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif /* ACE_LACKS_PRAGMA_ONCE */
00011 
00012 ACE_RCSID(ace, IOStream_T, "$Id: IOStream_T.cpp,v 1.1.1.3 2001/12/04 14:33:02 chad Exp $")
00013 
00014 #if !defined (ACE_LACKS_ACE_IOSTREAM)
00015 
00016 #if defined (ACE_HAS_MINIMUM_IOSTREAMH_INCLUSION) && defined (__GNUG__)
00017 # if !defined (ACE_IOSTREAM_T_H)
00018     // _Only_ define this when compiling this .cpp file standalone, not
00019     // when instantiating templates.  Its purpose is to provide something
00020     // for global constructors and destructors to be tied to.  Without it,
00021     // they would be tied to the file(name).  With Cygnus g++ 2.7.2/VxWorks,
00022     // that name is used directly in variable names in the munched ctor/dtor
00023     // file.  That name contains a ".", so it's not a legal C variable name.
00024     // The root of all this trouble is a static instance (of Iostream_init)
00025     // declared in the iostream.h header file.
00026     int ACE_IOStream_global_of_builtin_type_to_avoid_munch_problems = 0;
00027 # endif /* ! ACE_IOSTREAM_T_H */
00028 #endif /* ACE_HAS_MINIMUM_IOSTREAMH_INCLUSION && __GNUG__ */
00029 
00030 #if !defined (__ACE_INLINE__)
00031 #include "ace/IOStream_T.i"
00032 #endif /* !__ACE_INLINE__ */
00033 
00034 // We will be given a STREAM by the iostream object which creates us.
00035 // See the ACE_IOStream template for how that works.  Like other
00036 // streambuf objects, we can be input-only, output-only or both.
00037 
00038 template <class STREAM>
00039 ACE_Streambuf_T<STREAM>::ACE_Streambuf_T (STREAM *peer,
00040                                           u_int streambuf_size,
00041                                           int io_mode)
00042   : ACE_Streambuf (streambuf_size, io_mode),
00043     peer_ (peer)
00044 {
00045   // A streambuf allows for unbuffered IO where every character is
00046   // read as requested and written as provided.  To me, this seems
00047   // terribly inefficient for socket-type operations, so I've disabled
00048   // it.  All of the work would be done by the underflow/overflow
00049   // functions anyway and I haven't implemented anything there to
00050   // support unbuffered IO.
00051 
00052 #if !defined (ACE_LACKS_UNBUFFERED_STREAMBUF)
00053   this->unbuffered (0);
00054 #endif /* ! ACE_LACKS_UNBUFFERED_STREAMBUF */
00055 
00056   // Linebuffered is similar to unbuffered.  Again, I don't have any
00057   // need for this and I don't see the advantage.  I believe this
00058   // would have to be supported by underflow/overflow to be effective.
00059 #if !defined (ACE_LACKS_LINEBUFFERED_STREAMBUF)
00060   this->linebuffered (0);
00061 #endif /* ! ACE_LACKS_LINEBUFFERED_STREAMBUF */
00062 }
00063 
00064 // The typical constructor.  This will initiailze your STREAM and then
00065 // setup the iostream baseclass to use a custom streambuf based on
00066 // STREAM.
00067 
00068 template <class STREAM>
00069 ACE_IOStream<STREAM>::ACE_IOStream (STREAM &stream,
00070                                     u_int streambuf_size)
00071   : iostream (0),
00072     STREAM (stream)
00073 {
00074   ACE_NEW (streambuf_,
00075            ACE_Streambuf_T<STREAM> ((STREAM *) this,
00076                                     streambuf_size));
00077   iostream::init (this->streambuf_);
00078 }
00079 
00080 template <class STREAM>
00081 ACE_IOStream<STREAM>::ACE_IOStream (u_int streambuf_size)
00082   : iostream (0)
00083 {
00084   ACE_NEW (this->streambuf_,
00085            ACE_Streambuf_T<STREAM> ((STREAM *) this,
00086                                     streambuf_size));
00087   iostream::init (this->streambuf_);
00088 }
00089 
00090 // We have to get rid of the streambuf_ ourselves since we gave it to
00091 // iostream ()
00092 
00093 template <class STREAM>
00094 ACE_IOStream<STREAM>::~ACE_IOStream (void)
00095 {
00096   delete this->streambuf_;
00097 }
00098 
00099 // The only ambituity in the multiple inheritance is the close ()
00100 // function.
00101 
00102 template <class STREAM> int
00103 ACE_IOStream<STREAM>::close (void)
00104 {
00105   return STREAM::close ();
00106 }
00107 
00108 template <class STREAM> ACE_IOStream<STREAM> &
00109 ACE_IOStream<STREAM>::operator>> (ACE_Time_Value *&tv)
00110 {
00111   ACE_Time_Value *old_tv = this->streambuf_->recv_timeout (tv);
00112   tv = old_tv;
00113   return *this;
00114 }
00115 
00116 #if defined (ACE_HAS_STRING_CLASS)
00117 
00118 // A simple string operator.  The base iostream has 'em for char* but
00119 // that isn't always the best thing for a String.  If we don't provide
00120 // our own here, we may not get what we want.
00121 
00122 template <class STREAM> ACE_IOStream<STREAM> &
00123 ACE_IOStream<STREAM>::operator>> (ACE_IOStream_String &v)
00124 {
00125   if (ipfx0 ())
00126     {
00127       char c;
00128       this->get (c);
00129 
00130       for (v = c;
00131            this->get (c) && !isspace (c);
00132            v += c)
00133         continue;
00134     }
00135 
00136   isfx ();
00137 
00138   return *this;
00139 }
00140 
00141 template <class STREAM> ACE_IOStream<STREAM> &
00142 ACE_IOStream<STREAM>::operator<< (ACE_IOStream_String &v)
00143 {
00144   if (opfx ())
00145     {
00146 #if defined (ACE_WIN32) && defined (_MSC_VER)
00147       for (int i = 0; i < v.GetLength (); ++i)
00148 #else
00149       for (u_int i = 0; i < (u_int) v.length (); ++i)
00150 #endif /* ACE_WIN32 && defined (_MSC_VER) */
00151         this->put (v[i]);
00152     }
00153 
00154   osfx ();
00155 
00156   return *this;
00157 }
00158 
00159 // A more clever put operator for strings that knows how to deal with
00160 // quoted strings containing back-quoted quotes.
00161 
00162 template <class STREAM> STREAM &
00163 operator>> (STREAM &stream,
00164             ACE_Quoted_String &str)
00165 {
00166   char c;
00167 
00168   if (!(stream >> c)) // eat space up to the first char
00169     // stream.set (ios::eofbit|ios::failbit);
00170     return stream;
00171 
00172   str = "";     // Initialize the string
00173 
00174   // if we don't have a quote, append until we see space
00175   if (c != '"')
00176     for (str = c; stream.get (c) && !isspace (c); str += c)
00177       continue;
00178   else
00179     for (; stream.get (c) && c != '"'; str += c)
00180       if (c == '\\')
00181         {
00182           stream.get (c);
00183           if (c != '"')
00184             str += '\\';
00185         }
00186 
00187   return stream;
00188 }
00189 
00190 template <class STREAM> STREAM &
00191 operator<< (STREAM &stream,
00192             ACE_Quoted_String &str)
00193 {
00194   stream.put ('"');
00195 
00196   for (u_int i = 0; i < str.length (); ++i)
00197     {
00198       if (str[i] == '"')
00199         stream.put ('\\');
00200       stream.put (str[i]);
00201     }
00202 
00203   stream.put ('"');
00204 
00205   return stream;
00206 }
00207 
00208 #endif /* ACE_HAS_STRING_CLASS */
00209 #endif /* ACE_LACKS_ACE_IOSTREAM */
00210 #endif /* ACE_IOSTREAM_T_C */

Generated on Mon Jun 16 11:19:54 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002