home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18890 < prev    next >
Encoding:
Internet Message Format  |  1993-01-10  |  2.5 KB

  1. Path: sparky!uunet!news.claremont.edu!ucivax!news.service.uci.edu!network.ucsd.edu!sdd.hp.com!think.com!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!ugle.unit.no!nuug!ifi.uio.no!nntp.ifi.uio.no!jar
  2. From: jar@solva.ifi.uio.no (Jo Are Rosland)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: xdr layer above iostream's
  5. Message-ID: <JAR.93Jan10162442@solva.ifi.uio.no>
  6. Date: 10 Jan 93 15:24:42 GMT
  7. References: <1ih5puINN4fj@buzz.bmc.uu.se>
  8. Sender: jar@ifi.uio.no (Jo Are Rosland)
  9. Organization: Dept. of Informatics, University of Oslo, Norway
  10. Lines: 42
  11. Nntp-Posting-Host: solva.ifi.uio.no
  12. In-Reply-To: sundvall@perrier.embnet.se's message of 7 Jan 1993 11:56:46 GMT
  13. X-Md4-Signature: 998719afc70bc82f213d281d10eb0eda
  14. Originator: jar@solva.ifi.uio.no
  15.  
  16. In article <1ih5puINN4fj@buzz.bmc.uu.se> Mats Sundvall writes:
  17.    I have implemented an Xdr class with the help of the xdr_rec. I have
  18.    a constructor Xdr(iostream*) and can then put a XDR layer above a stream.
  19.    All the operator input and output methods are then implemented to read
  20.    from and write to Xdr.
  21.  
  22.    Another way to implement it would be to implement a new iostream subclassing
  23.    from ios and streambuf.
  24.  
  25.    I now wonder what pros and cons there is with these different approches, and
  26.    if there are other ways to do it that I haven't thought about.
  27.  
  28. I think the best solution is to make xdrstream an independent class
  29. with an interface similar to ios, and a constructor (among others)
  30. looking like xdrstream(streambuf*).  Then you implement the << and >>
  31. operators for all the types you need (at least the primitive types.)
  32.  
  33. There are a number of reasons for this:
  34.  
  35. The ios class doesn't seem to offer xdrstream very much, so it's not
  36. much use in having it as a subclass.  All the formatting functionality
  37. (things like field widths etc.) are just superfluous in xdrstream.  It
  38. would just be unnecessary baggage to carry around.
  39.  
  40. Since ios formatting (all the << and >> defined for ios) is mainly
  41. text based, while xdr is binary, you need to implement all the >> and
  42. << whatever solution you choose.
  43.  
  44. With the xdrstream(streambuf *) constructor (and a corresponding
  45. streambuf* member) you can perform xdr IO with all your excisting
  46. streambuf subclasses, including your tcp and tli classes if they are
  47. implemented correctly.  Outputting to standard output would be
  48. possible by creating the xdrstream with xdrstream(cout.rdbuf()), if
  49. you want to output to a file, you could do it like this: xdrstream(new
  50. filebuf("file")). (Or whatever the constructor for filebuf looks
  51. like :-)).
  52.  
  53. Hope this helps,
  54.  
  55. --
  56. Jo Are Rosland
  57. jar@ifi.uio.no
  58.