home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20os2.zip / src / tobjstrm.cpp < prev    next >
C/C++ Source or Header  |  1999-05-19  |  18KB  |  930 lines

  1. /*
  2.  * tobjstrm.cc
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #define Uses_TStreamable
  13. #define Uses_TStreamableClass
  14. #define Uses_TStreamableTypes
  15. #define Uses_TPWrittenObjects
  16. #define Uses_TPReadObjects
  17. #define Uses_pstream
  18. #define Uses_ipstream
  19. #define Uses_opstream
  20. #define Uses_iopstream
  21. #define Uses_fpbase
  22. #define Uses_ifpstream
  23. #define Uses_ofpstream
  24. #define Uses_fpstream
  25. #include <tvision/tv.h>
  26.  
  27. #include <assert.h>
  28. #include <fcntl.h>
  29. #include <fstream.h>
  30. #include <limits.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <sys/stat.h>
  34.  
  35. const uchar nullStringLen = UCHAR_MAX;
  36.  
  37. TStreamableClass::TStreamableClass( const char *n, BUILDER b, int d ) :
  38.     name( n ),
  39.     build( b ),
  40.     delta( d )
  41. {
  42.     pstream::initTypes();
  43.     pstream::registerType( this );
  44. }
  45.  
  46. TStreamableTypes::TStreamableTypes() : TNSSortedCollection( 5, 5 )
  47. {
  48. }
  49.  
  50. void *TStreamableTypes::operator new( size_t, void * arena )
  51. {
  52.     return arena;
  53. }
  54.  
  55. TStreamableTypes::~TStreamableTypes()
  56. {
  57. }
  58.  
  59. void TStreamableTypes::registerType( const TStreamableClass *d )
  60. {
  61.     insert( (void *)d );
  62. }
  63.  
  64. const TStreamableClass *TStreamableTypes::lookup( const char *name )
  65. {
  66.     ccIndex loc;
  67.     if( search( (void *)name, loc ) )
  68.         return (TStreamableClass *)at( loc );
  69.     else
  70.         return 0;
  71. }
  72.  
  73. void *TStreamableTypes::keyOf( void *d )
  74. {
  75.     return (void *)((TStreamableClass *)d)->name;
  76. }
  77.  
  78. int TStreamableTypes::compare( void *d1, void *d2 )
  79. {
  80.     return strcmp( (char *)d1, (char *)d2 );
  81. }
  82.  
  83. TPWrittenObjects::TPWrittenObjects() : TNSSortedCollection( 5, 5 ), curId( 0 )
  84. {
  85. }
  86.  
  87. TPWrittenObjects::~TPWrittenObjects()
  88. {
  89. }
  90.  
  91. void TPWrittenObjects::registerObject( const void *adr )
  92. {
  93.     TPWObj *o = new TPWObj( adr, curId++ );
  94.     insert( o );
  95. }
  96.  
  97. P_id_type TPWrittenObjects::find( const void *d )
  98. {
  99.     ccIndex loc;
  100.     if( search( (void *)d, loc ) )
  101.         return ((TPWObj *)at( loc ))->ident;
  102.     else
  103.         return P_id_notFound;
  104. }
  105.  
  106. void *TPWrittenObjects::keyOf( void *d )
  107. {
  108.     return (void *)((TPWObj *)d)->address;
  109. }
  110.  
  111. int TPWrittenObjects::compare( void *o1, void *o2 )
  112. {
  113.     if( o1 == o2 )
  114.         return 0;
  115.     else if( ((char *)o1)+1 < ((char *)o2)+1 ) // force normalization
  116.         return -1;
  117.     else
  118.         return 1;
  119. }
  120.  
  121. TPWObj::TPWObj( const void *adr, P_id_type id ) : address( adr ), ident( id )
  122. {
  123. }
  124.  
  125. TPReadObjects::TPReadObjects() : TNSCollection( 5, 5 ), curId( 0 )
  126. {
  127. }
  128.  
  129. TPReadObjects::~TPReadObjects()
  130. {
  131. }
  132.  
  133. void TPReadObjects::registerObject( const void *adr )
  134. {
  135.     ccIndex loc = insert( (void *)adr );
  136. #ifndef __UNPATCHED
  137. //    assert( loc == curId );     // to be sure that TNSCollection /* XXX */
  138.     assert( loc == (ccIndex)curId );     // to be sure that TNSCollection /* XXX */
  139. #else
  140.     assert( loc == curId++ );   // to be sure that TNSCollection
  141. #endif
  142.                                 // continues to work the way
  143.                                 // it does now...
  144. #ifndef __UNPATCHED
  145.     curId++;  // Move the increment OUTSIDE the assertion.
  146. #endif
  147. }
  148.  
  149. const void *TPReadObjects::find( P_id_type id )
  150. {
  151.     return at( id );
  152. }
  153.  
  154. pstream::pstream( streambuf *sb )
  155. {
  156.     init( sb );
  157. }
  158.  
  159. pstream::~pstream()
  160. {
  161. }
  162.  
  163. void pstream::initTypes()
  164. {
  165.     if( types == 0 )
  166.         types = new TStreamableTypes;
  167. }
  168.  
  169. int pstream::rdstate() const
  170. {
  171.     return state;
  172. }
  173.  
  174. int pstream::eof() const
  175. {
  176.     return state & ios::eofbit;
  177. }
  178.  
  179. int pstream::fail() const
  180. {
  181.     return state & (ios::failbit | ios::badbit); //| ios::hardfail);
  182. }
  183.  
  184. int pstream::bad() const
  185. {
  186.     return state & (ios::badbit); //| ios::hardfail);
  187. }
  188.  
  189. int pstream::good() const
  190. {
  191.     return state == 0;
  192. }
  193.  
  194. void pstream::clear( int i )
  195. {
  196.     state = (i & 0xFF); //| (state & ios::hardfail);
  197. }
  198.  
  199. void pstream::registerType( TStreamableClass *ts )
  200. {
  201.     types->registerType( ts );
  202. }
  203.  
  204. pstream::operator void *() const
  205. {
  206.     return fail() ? 0 : (void *)this;
  207. }
  208.  
  209. int pstream::operator! () const
  210. {
  211.     return fail();
  212. }
  213.  
  214. streambuf * pstream::rdbuf() const
  215. {
  216.     return bp;
  217. }
  218.  
  219. pstream::pstream()
  220. {
  221. }
  222.  
  223. void pstream::error( StreamableError )
  224. {
  225.     abort();
  226. }
  227.  
  228. void pstream::error( StreamableError, const TStreamable& )
  229. {
  230.     abort();
  231. }
  232.  
  233. void pstream::init( streambuf *sbp )
  234. {
  235.     state = 0;
  236.     bp = sbp;
  237. }
  238.  
  239. void pstream::setstate( int b )
  240. {
  241.     state |= (b&0xFF);
  242. }
  243.  
  244. ipstream::ipstream( streambuf *sb )
  245. {
  246.     pstream::init( sb );
  247. }
  248.  
  249. ipstream::~ipstream()
  250. {
  251.     objs.shouldDelete = False;
  252.     objs.shutDown();
  253. }
  254.  
  255. streampos ipstream::tellg()
  256. {
  257.     return bp->seekoff( 0, ios::cur, ios::in );
  258. }
  259.  
  260. ipstream& ipstream::seekg( streampos pos )
  261. {
  262.     objs.removeAll();
  263.     bp->seekoff( pos, ios::beg );
  264.     return *this;
  265. }
  266.  
  267. ipstream& ipstream::seekg( streamoff off, ios::seek_dir dir )
  268. {
  269.     objs.removeAll();
  270.     bp->seekoff( off, dir );
  271.     return *this;
  272. }
  273.  
  274. uchar ipstream::readByte()
  275. {
  276.     return bp->sbumpc();
  277. }
  278.  
  279. ushort ipstream::readWord()
  280. {
  281.     /*
  282.      * SS: words are stored in little endian format (LSB first).
  283.      */
  284.     return readByte() | (readByte() << 8);
  285. /*    ushort temp;
  286.     bp->sgetn( (char *)&temp, sizeof( ushort ) );
  287.     return temp;*/
  288. }
  289.  
  290. void ipstream::readBytes( void *data, size_t sz )
  291. {
  292.     bp->sgetn( (char *)data, sz );
  293. }
  294.  
  295. char *ipstream::readString()
  296. {
  297.     uchar len = readByte();
  298.     if( len == nullStringLen )
  299.         return 0;
  300.     char *buf = new char[len+1];
  301.     if( buf == 0 )
  302.         return 0;
  303.     readBytes( buf, len );
  304.     buf[len] = EOS;
  305.     return buf;
  306. }
  307.  
  308. char *ipstream::readString( char *buf, unsigned maxLen )
  309. {
  310.     assert( buf != 0 );
  311.  
  312.     uchar len = readByte();
  313.     if( len > maxLen-1 )
  314.         return 0;
  315.     readBytes( buf, len );
  316.     buf[len] = EOS;
  317.     return buf;
  318. }
  319.  
  320. ipstream& operator >> ( ipstream& ps, char &ch )
  321. {
  322.     ch = ps.readByte();
  323.     return ps;
  324. }
  325.  
  326. ipstream& operator >> ( ipstream& ps, signed char &ch )
  327. {
  328.     ch = ps.readByte();
  329.     return ps;
  330. }
  331.  
  332. ipstream& operator >> ( ipstream& ps, unsigned char &ch )
  333. {
  334.     ch = ps.readByte();
  335.     return ps;
  336. }
  337.  
  338. ipstream& operator >> ( ipstream& ps, signed short &sh )
  339. {
  340.     sh = ps.readWord();
  341.     return ps;
  342. }
  343.  
  344. ipstream& operator >> ( ipstream& ps, unsigned short &sh )
  345. {
  346.     sh = ps.readWord();
  347.     return ps;
  348. }
  349.  
  350. ipstream& operator >> ( ipstream& ps, signed int &i )
  351. {
  352.     /*
  353.      * SS: ints are stored in little endian format (LSB first).
  354.      */
  355.     i = ps.readByte() | (ps.readByte() << 8) | (ps.readByte() << 16) |
  356.     (ps.readByte() << 24);
  357. /*    ps.readBytes( &i, sizeof(int) );*/
  358.     return ps;
  359. }
  360.  
  361. ipstream& operator >> ( ipstream& ps, unsigned int &i )
  362. {
  363.     /*
  364.      * SS: ints are stored in little endian format (LSB first).
  365.      */
  366.     i = ps.readByte() | (ps.readByte() << 8) | (ps.readByte() << 16) |
  367.     (ps.readByte() << 24);
  368. /*    ps.readBytes( &i, sizeof(int) );*/
  369.     return ps;
  370. }
  371.  
  372. ipstream& operator >> ( ipstream& ps, signed long &l )
  373. {
  374.     /*
  375.      * SS: longs are stored in little endian format (LSB first).
  376.      */
  377.     l = ps.readByte() | (ps.readByte() << 8) | (ps.readByte() << 16) |
  378.     (ps.readByte() << 24);
  379. /*    ps.readBytes( &l, sizeof(l) );*/
  380.     return ps;
  381. }
  382.  
  383. ipstream& operator >> ( ipstream& ps, unsigned long &l )
  384. {
  385.     /*
  386.      * SS: longs are stored in little endian format (LSB first).
  387.      */
  388.     l = ps.readByte() | (ps.readByte() << 8) | (ps.readByte() << 16) |
  389.     (ps.readByte() << 24);
  390. /*    ps.readBytes( &l, sizeof(l) );*/
  391.     return ps;
  392. }
  393.  
  394. ipstream& operator >> ( ipstream& ps, float &f )
  395. {
  396.     ps.readBytes( &f, sizeof(f) );
  397.     return ps;
  398. }
  399.  
  400. ipstream& operator >> ( ipstream& ps, double &d )
  401. {
  402.     ps.readBytes( &d, sizeof(d) );
  403.     return ps;
  404. }
  405.  
  406. ipstream& operator >> ( ipstream& ps, long double &ld )
  407. {
  408.     ps.readBytes( &ld, sizeof(ld) );
  409.     return ps;
  410. }
  411.  
  412. ipstream& operator >> ( ipstream& ps, TStreamable& t )
  413. {
  414.     const TStreamableClass *pc = ps.readPrefix();
  415.     ps.readData( pc, &t );
  416.     ps.readSuffix();
  417.     return ps;
  418. }
  419.  
  420. ipstream& operator >> ( ipstream& ps, void *&t )
  421. {
  422.     char ch = ps.readByte();
  423.     switch( ch )
  424.         {
  425.         case pstream::ptNull:
  426.             t = 0;
  427.             break;
  428.         case pstream::ptIndexed:
  429.             {
  430.             P_id_type index = ps.readWord();
  431.             t = (void *)ps.find( index );
  432.             assert( t != 0 );
  433.             break;
  434.             }
  435.         case pstream::ptObject:
  436.             {
  437.             const TStreamableClass *pc = ps.readPrefix();
  438.             t = ps.readData( pc, 0 );
  439.             ps.readSuffix();
  440.             break;
  441.             }
  442.         default:
  443.             ps.error( pstream::peInvalidType );
  444.             break;
  445.         }
  446.     return ps;
  447. }
  448.  
  449. ipstream::ipstream()
  450. {
  451. }
  452.  
  453. const TStreamableClass *ipstream::readPrefix()
  454. {
  455.     char ch = readByte();
  456.     assert( ch == '[' );    // don't combine this with the previous line!
  457.                             // We must always do the read, even if we're
  458.                             // not checking assertions
  459.  
  460.     char name[128];
  461.     readString( name, sizeof name );
  462.     return types->lookup( name );
  463. }
  464.  
  465. void *ipstream::readData( const TStreamableClass *c, TStreamable *mem )
  466. {
  467.     if( mem == 0 )
  468.         mem = c->build();
  469.  
  470.     registerObject( (char *)mem - c->delta );   // register the actual address
  471.                                         // of the object, not the address
  472.                                         // of the TStreamable sub-object
  473.     return mem->read( *this );
  474. }
  475.  
  476. void ipstream::readSuffix()
  477. {
  478.     char ch = readByte();
  479.     assert( ch == ']' );    // don't combine this with the previous line!
  480.                             // We must always do the write, even if we're
  481.                             // not checking assertions
  482.  
  483. }
  484.  
  485. const void *ipstream::find( P_id_type id )
  486. {
  487.     return objs.find( id );
  488. }
  489.  
  490. void ipstream::registerObject( const void *adr )
  491. {
  492.     objs.registerObject( adr );
  493. }
  494.  
  495. opstream::opstream()
  496. {
  497.     objs = new TPWrittenObjects;
  498. }
  499.  
  500. opstream::opstream( streambuf * sb )
  501. {
  502.     objs = new TPWrittenObjects;
  503.     pstream::init( sb );
  504. }
  505.  
  506. opstream::~opstream()
  507. {
  508.     objs->shutDown();
  509.     delete objs;
  510. }
  511.  
  512. opstream& opstream::seekp( streampos pos )
  513. {
  514. #ifndef __UNPATCHED
  515.     objs->freeAll();   // CMF 07.11.92 --- delete the TPWObj's
  516. #endif
  517.     objs->removeAll();
  518.     bp->seekoff( pos, ios::beg );
  519.     return *this;
  520. }
  521.  
  522. opstream& opstream::seekp( streamoff pos, ios::seek_dir dir )
  523. {
  524. #ifndef __UNPATCHED
  525.     objs->freeAll();   // CMF 07.11.92 ... s.a.
  526. #endif
  527.     objs->removeAll();
  528.     bp->seekoff( pos, dir );
  529.     return *this;
  530. }
  531.  
  532. streampos opstream::tellp()
  533. {
  534.     return bp->seekoff( 0, ios::cur, ios::out );
  535. }
  536.  
  537. opstream& opstream::flush()
  538. {
  539.     bp->sync();
  540.     return *this;
  541. }
  542.  
  543. void opstream::writeByte( uchar ch )
  544. {
  545.     bp->sputc( ch );
  546. }
  547.  
  548. void opstream::writeBytes( const void *data, size_t sz )
  549. {
  550.     bp->sputn( (char *)data, sz );
  551. }
  552.  
  553. void opstream::writeWord( ushort sh )
  554. {
  555.     /*
  556.      * SS: words are stored in little endian format (LSB first).
  557.      */
  558.     writeByte(sh & 0xff);
  559.     writeByte((sh >> 8) & 0xff);
  560. /*    bp->sputn( (char *)&sh, sizeof( ushort ) );*/
  561. }
  562.  
  563. void opstream::writeString( const char *str )
  564. {
  565.     if( str == 0 )
  566.         {
  567.         writeByte( nullStringLen );
  568.         return;
  569.         }
  570.     int len = strlen( str );
  571.     writeByte( (uchar)len );
  572.     writeBytes( str, len );
  573. }
  574.  
  575. opstream& operator << ( opstream& ps, char ch )
  576. {
  577.     ps.writeByte( ch );
  578.     return ps;
  579. }
  580.  
  581. opstream& operator << ( opstream& ps, signed char ch )
  582. {
  583.     ps.writeByte( ch );
  584.     return ps;
  585. }
  586.  
  587. opstream& operator << ( opstream& ps, unsigned char ch )
  588. {
  589.     ps.writeByte( ch );
  590.     return ps;
  591. }
  592.  
  593. opstream& operator << ( opstream& ps, signed short sh )
  594. {
  595.     ps.writeWord( sh );
  596.     return ps;
  597. }
  598.  
  599. opstream& operator << ( opstream& ps, unsigned short sh )
  600. {
  601.     ps.writeWord( sh );
  602.     return ps;
  603. }
  604.  
  605. opstream& operator << ( opstream& ps, signed int i )
  606. {
  607.     /*
  608.      * SS: ints are stored in little endian format (LSB first).
  609.      */
  610.     ps.writeByte(i & 0xff);
  611.     ps.writeByte((i >> 8) & 0xff);
  612.     ps.writeByte((i >> 16) & 0xff);
  613.     ps.writeByte((i >> 24) & 0xff);
  614. /*    ps.writeBytes( &i, sizeof(int) );*/
  615.     return ps;
  616. }
  617.  
  618. opstream& operator << ( opstream& ps, unsigned int i )
  619. {
  620.     /*
  621.      * SS: ints are stored in little endian format (LSB first).
  622.      */
  623.     ps.writeByte(i & 0xff);
  624.     ps.writeByte((i >> 8) & 0xff);
  625.     ps.writeByte((i >> 16) & 0xff);
  626.     ps.writeByte((i >> 24) & 0xff);
  627. /*    ps.writeBytes( &i, sizeof(int) );*/
  628.     return ps;
  629. }
  630. opstream& operator << ( opstream& ps, signed long l )
  631. {
  632.     /*
  633.      * SS: longs are stored in little endian format (LSB first).
  634.      */
  635.     ps.writeByte(l & 0xff);
  636.     ps.writeByte((l >> 8) & 0xff);
  637.     ps.writeByte((l >> 16) & 0xff);
  638.     ps.writeByte((l >> 24) & 0xff);
  639. /*    ps.writeBytes( &l, sizeof(l) );*/
  640.     return ps;
  641. }
  642.  
  643. opstream& operator << ( opstream& ps, unsigned long l )
  644. {
  645.     /*
  646.      * SS: longs are stored in little endian format (LSB first).
  647.      */
  648.     ps.writeByte(l & 0xff);
  649.     ps.writeByte((l >> 8) & 0xff);
  650.     ps.writeByte((l >> 16) & 0xff);
  651.     ps.writeByte((l >> 24) & 0xff);
  652. /*    ps.writeBytes( &l, sizeof(l) );*/
  653.     return ps;
  654. }
  655.  
  656. opstream& operator << ( opstream& ps, float f )
  657. {
  658.     ps.writeBytes( &f, sizeof(f) );
  659.     return ps;
  660. }
  661.  
  662. opstream& operator << ( opstream& ps, double d )
  663. {
  664.     ps.writeBytes( &d, sizeof(d) );
  665.     return ps;
  666. }
  667.  
  668. opstream& operator << ( opstream& ps, long double ld )
  669. {
  670.     ps.writeBytes( &ld, sizeof(ld) );
  671.     return ps;
  672. }
  673.  
  674. opstream& operator << ( opstream& ps, TStreamable& t )
  675. {
  676.     ps.writePrefix( t );
  677.     ps.writeData( t );
  678.     ps.writeSuffix( t );
  679.     return ps;
  680. }
  681.  
  682. opstream& operator << ( opstream& ps, TStreamable *t )
  683. {
  684.     P_id_type index;
  685.     if( t == 0 )
  686.         ps.writeByte( pstream::ptNull );
  687.     else if( (index = ps.find( t )) != P_id_notFound )
  688.         {
  689.         ps.writeByte( pstream::ptIndexed );
  690.         ps.writeWord( index );
  691.         }
  692.     else
  693.         {
  694.         ps.writeByte( pstream::ptObject );
  695.         ps << *t;
  696.         }
  697.     return ps;
  698. }
  699.  
  700. void opstream::writePrefix( const TStreamable& t )
  701. {
  702.     writeByte( '[' );
  703.     writeString( t.streamableName() );
  704. }
  705.  
  706. void opstream::writeData( TStreamable& t )
  707. {
  708.     if( types->lookup( t.streamableName() ) == 0 )
  709.         error( peNotRegistered, t );
  710.     else
  711.         {
  712.         registerObject( &t );
  713.         t.write( *this );
  714.         }
  715. }
  716.  
  717. void opstream::writeSuffix( const TStreamable& )
  718. {
  719.     writeByte( ']' );
  720. }
  721.  
  722. P_id_type opstream::find( const void *adr )
  723. {
  724.     return objs->find( adr );
  725. }
  726.  
  727. void opstream::registerObject( const void *adr )
  728. {
  729.     objs->registerObject( adr );
  730. }
  731.  
  732. iopstream::iopstream( streambuf * sb )
  733. {
  734.     pstream::init( sb );
  735. }
  736.  
  737. iopstream::~iopstream()
  738. {
  739. }
  740.  
  741. iopstream::iopstream()
  742. {
  743. }
  744.  
  745. fpbase::fpbase()
  746. {
  747.     pstream::init( &buf );
  748. }
  749.  
  750. fpbase::fpbase( const char *name, int omode, int prot )
  751. {
  752.     pstream::init( &buf );
  753.     open( name, omode, prot );
  754. }
  755.  
  756. fpbase::fpbase( int f ) : buf( f )
  757. {
  758.     pstream::init( &buf );
  759. }
  760.  
  761. fpbase::fpbase( int f, char *b, int len ) : buf( f, b, len )
  762. {
  763.     pstream::init( &buf );
  764. }
  765.  
  766. fpbase::~fpbase()
  767. {
  768. }
  769.  
  770. void fpbase::open( const char *b, int m, int prot )
  771. {
  772.     if( buf.is_open() )
  773.         clear(ios::failbit);        // fail - already open
  774.     else if( buf.open(b, m, prot) )
  775.         clear(ios::goodbit);        // successful open
  776.     else
  777.         clear(ios::badbit);     // open failed
  778. }
  779.  
  780. void fpbase::attach( int f )
  781. {
  782.     if( buf.is_open() )
  783.         setstate(ios::failbit);
  784.     else if( buf.attach(f) )
  785.         clear(ios::goodbit);
  786.     else
  787.         clear(ios::badbit);
  788. }
  789.  
  790. void fpbase::close()
  791. {
  792.     if( buf.close() )
  793.         clear(ios::goodbit);
  794.     else
  795.         setstate(ios::failbit);
  796. }
  797.  
  798. void fpbase::setbuf(char* b, int len)
  799. {
  800.     if( buf.setbuf(b, len) )
  801.         clear(ios::goodbit);
  802.     else
  803.         setstate(ios::failbit);
  804. }
  805.  
  806. filebuf *fpbase::rdbuf()
  807. {
  808.     return &buf;
  809. }
  810.  
  811. ifpstream::ifpstream()
  812. {
  813. }
  814.  
  815. #ifdef __OS2__
  816. ifpstream::ifpstream( const char* name, int omode, int prot ) :
  817.         fpbase( name, omode | ios::in | ios::binary, prot )
  818. {
  819. }
  820. #else
  821. ifpstream::ifpstream( const char* name, int omode, int prot ) :
  822.         fpbase( name, omode | ios::in | ios::bin, prot )
  823. {
  824. }
  825. #endif
  826.  
  827. ifpstream::ifpstream( int f ) : fpbase( f )
  828. {
  829. }
  830.  
  831. ifpstream::ifpstream(int f, char* b, int len) : fpbase(f, b, len)
  832. {
  833. }
  834.  
  835. ifpstream::~ifpstream()
  836. {
  837. }
  838.  
  839. filebuf *ifpstream::rdbuf()
  840. {
  841.     return fpbase::rdbuf();
  842. }
  843.  
  844. void ifpstream::open( const char *name, int omode, int prot )
  845. {
  846. #ifdef __OS2__
  847.     fpbase::open( name, omode | ios::in | ios::binary, prot );
  848. #else
  849.     fpbase::open( name, omode | ios::in | ios::bin, prot );
  850. #endif
  851. }
  852.  
  853. ofpstream::ofpstream()
  854. {
  855. }
  856.  
  857. ofpstream::ofpstream( const char* name, int omode, int prot ) :
  858. #ifdef __OS2__
  859.         fpbase( name, omode | ios::out | ios::binary, prot )
  860. #else
  861.         fpbase( name, omode | ios::out | ios::bin, prot )
  862. #endif
  863. {
  864. }
  865.  
  866. ofpstream::ofpstream( int f ) : fpbase( f )
  867. {
  868. }
  869.  
  870. ofpstream::ofpstream(int f, char* b, int len) : fpbase(f, b, len)
  871. {
  872. }
  873.  
  874. ofpstream::~ofpstream()
  875. {
  876. }
  877.  
  878. filebuf *ofpstream::rdbuf()
  879. {
  880.     return fpbase::rdbuf();
  881. }
  882.  
  883. void ofpstream::open( const char *name, int omode, int prot )
  884. {
  885. #ifdef __OS2__
  886.     fpbase::open( name, omode | ios::out | ios::binary, prot );
  887. #else
  888.     fpbase::open( name, omode | ios::out | ios::bin, prot );
  889. #endif
  890. }
  891.  
  892. fpstream::fpstream()
  893. {
  894. }
  895.  
  896. fpstream::fpstream( const char* name, int omode, int prot ) :
  897. #ifdef __OS2__
  898.         fpbase( name, omode | ios::out | ios::binary, prot )
  899. #else
  900.         fpbase( name, omode | ios::out | ios::bin, prot )
  901. #endif
  902. {
  903. }
  904.  
  905. fpstream::fpstream( int f ) : fpbase( f )
  906. {
  907. }
  908.  
  909. fpstream::fpstream(int f, char* b, int len) : fpbase(f, b, len)
  910. {
  911. }
  912.  
  913. fpstream::~fpstream()
  914. {
  915. }
  916.  
  917. filebuf *fpstream::rdbuf()
  918. {
  919.     return fpbase::rdbuf();
  920. }
  921.  
  922. void fpstream::open( const char *name, int omode, int prot )
  923. {
  924. #ifdef __OS2__
  925.     fpbase::open( name, omode | ios::in | ios::out | ios::binary, prot );
  926. #else
  927.     fpbase::open( name, omode | ios::in | ios::out | ios::bin, prot );
  928. #endif
  929. }
  930.